Ejemplo n.º 1
0
        public void Fail(
            BatchAsyncBatcher completer,
            Exception exception)
        {
            if (this.AssertBatcher(completer, exception))
            {
                this.taskCompletionSource.SetException(exception);
            }

            this.Dispose();
        }
Ejemplo n.º 2
0
        public void Complete(
            BatchAsyncBatcher completer,
            TransactionalBatchOperationResult result)
        {
            if (this.AssertBatcher(completer))
            {
                this.taskCompletionSource.SetResult(result);
            }

            this.Dispose();
        }
        private BatchAsyncBatcher GetBatchToDispatchAndCreate()
        {
            if (this.currentBatcher.IsEmpty)
            {
                return(null);
            }

            BatchAsyncBatcher previousBatcher = this.currentBatcher;

            this.currentBatcher = this.CreateBatchAsyncBatcher();
            return(previousBatcher);
        }
Ejemplo n.º 4
0
        private bool AssertBatcher(
            BatchAsyncBatcher completer,
            Exception innerException = null)
        {
            if (!object.ReferenceEquals(completer, this.CurrentBatcher))
            {
                DefaultTrace.TraceCritical($"Operation was completed by incorrect batcher.");
                this.taskCompletionSource.SetException(new Exception($"Operation was completed by incorrect batcher.", innerException));
                return(false);
            }

            return(true);
        }
Ejemplo n.º 5
0
        public void Complete(
            BatchAsyncBatcher completer,
            BatchOperationResult result)
        {
            if (this.AssertBatcher(completer))
            {
                this.Diagnostics.Complete();
                result.Diagnostics = this.Diagnostics;
                this.taskCompletionSource.SetResult(result);
            }

            this.Dispose();
        }
Ejemplo n.º 6
0
        public void Complete(
            BatchAsyncBatcher completer,
            TransactionalBatchOperationResult result)
        {
            if (this.AssertBatcher(completer))
            {
                this.initialTrace.AddChild(result.Trace);
                result.Trace = this.initialTrace;
                this.taskCompletionSource.SetResult(result);
            }

            this.Dispose();
        }
        public BatchAsyncStreamer(
            int maxBatchOperationCount,
            int maxBatchByteSize,
            int dispatchTimerInSeconds,
            TimerPool timerPool,
            CosmosSerializer cosmosSerializer,
            BatchAsyncBatcherExecuteDelegate executor,
            BatchAsyncBatcherRetryDelegate retrier)
        {
            if (maxBatchOperationCount < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(maxBatchOperationCount));
            }

            if (maxBatchByteSize < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(maxBatchByteSize));
            }

            if (dispatchTimerInSeconds < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(dispatchTimerInSeconds));
            }

            if (executor == null)
            {
                throw new ArgumentNullException(nameof(executor));
            }

            if (retrier == null)
            {
                throw new ArgumentNullException(nameof(retrier));
            }

            if (cosmosSerializer == null)
            {
                throw new ArgumentNullException(nameof(cosmosSerializer));
            }

            this.maxBatchOperationCount = maxBatchOperationCount;
            this.maxBatchByteSize       = maxBatchByteSize;
            this.executor = executor;
            this.retrier  = retrier;
            this.dispatchTimerInSeconds = dispatchTimerInSeconds;
            this.timerPool        = timerPool;
            this.cosmosSerializer = cosmosSerializer;
            this.currentBatcher   = this.CreateBatchAsyncBatcher();

            this.ResetTimer();
        }
        public void Add(ItemBatchOperation operation)
        {
            BatchAsyncBatcher toDispatch = null;

            lock (this.dispatchLimiter)
            {
                while (!this.currentBatcher.TryAdd(operation))
                {
                    // Batcher is full
                    toDispatch = this.GetBatchToDispatchAndCreate();
                }
            }

            if (toDispatch != null)
            {
                // Discarded for Fire & Forget
                _ = toDispatch.DispatchAsync(this.partitionMetric, this.cancellationTokenSource.Token);
            }
        }
        public BatchAsyncStreamer(
            int maxBatchOperationCount,
            int maxBatchByteSize,
            TimerWheel timerWheel,
            SemaphoreSlim limiter,
            int maxDegreeOfConcurrency,
            CosmosSerializerCore serializerCore,
            BatchAsyncBatcherExecuteDelegate executor,
            BatchAsyncBatcherRetryDelegate retrier)
        {
            if (maxBatchOperationCount < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(maxBatchOperationCount));
            }

            if (maxBatchByteSize < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(maxBatchByteSize));
            }

            if (executor == null)
            {
                throw new ArgumentNullException(nameof(executor));
            }

            if (retrier == null)
            {
                throw new ArgumentNullException(nameof(retrier));
            }

            if (serializerCore == null)
            {
                throw new ArgumentNullException(nameof(serializerCore));
            }

            if (limiter == null)
            {
                throw new ArgumentNullException(nameof(limiter));
            }

            if (maxDegreeOfConcurrency < 1)
            {
                throw new ArgumentNullException(nameof(maxDegreeOfConcurrency));
            }

            this.maxBatchOperationCount = maxBatchOperationCount;
            this.maxBatchByteSize       = maxBatchByteSize;
            this.executor       = executor;
            this.retrier        = retrier;
            this.timerWheel     = timerWheel;
            this.serializerCore = serializerCore;
            this.currentBatcher = this.CreateBatchAsyncBatcher();
            this.ResetTimer();

            this.limiter                = limiter;
            this.oldPartitionMetric     = new BatchPartitionMetric();
            this.partitionMetric        = new BatchPartitionMetric();
            this.maxDegreeOfConcurrency = maxDegreeOfConcurrency;

            this.StartCongestionControlTimer();
        }
Ejemplo n.º 10
0
 public void Dispose()
 {
     this.CurrentBatcher = null;
 }