public IOperationDataStream GetCopyState(long upToSequenceNumber, IOperationDataStream copyContext)
        {
            LogMessage(nameof(GetCopyState));

            var startData = copyContext.GetNextAsync(CancellationToken.None).GetAwaiter().GetResult();

            var startLsn = BitConverter.ToInt64(startData[0].Array, 0);

            return(new CopyStateOperationStream(log, startLsn, upToSequenceNumber));
        }
Example #2
0
        /// <summary>
        /// Gets operation data from state providers.
        /// </summary>
        public async Task <OperationData> GetNextAsync(CancellationToken cancellationToken)
        {
            try
            {
                while (this.currentIndex < this.operationDataStreamCollection.Count)
                {
                    StateProviderIdentifier stateProviderIdentifier = this.operationDataStreamCollection[this.currentIndex].Item1;
                    IOperationDataStream    operationDataStream     = this.operationDataStreamCollection[this.currentIndex].Item2;

                    OperationData operationData = await operationDataStream.GetNextAsync(cancellationToken).ConfigureAwait(false);

                    if (operationData == null)
                    {
                        ++this.currentIndex;
                        continue;
                    }

                    // Reserve the List space with expected size: Version, ID, OperationData
                    List <ArraySegment <byte> > namedBytes = new List <ArraySegment <byte> >(2 + operationData.Count);
                    byte[] versionAsBytes = BitConverter.GetBytes(this.version);
                    namedBytes.Add(new ArraySegment <byte>(versionAsBytes));

                    long   stateProviderId = stateProviderIdentifier.StateProviderId;
                    byte[] idAsBytes       = BitConverter.GetBytes(stateProviderId);
                    namedBytes.Add(new ArraySegment <byte>(idAsBytes));

                    foreach (ArraySegment <byte> roll in operationData)
                    {
                        namedBytes.Add(roll);
                    }

                    return(new OperationData(namedBytes));
                }

                FabricEvents.Events.NamedOperationDataCollectionGetNext(this.traceType);

                return(null);
            }
            catch (Exception e)
            {
                string msg = string.Format(
                    CultureInfo.InvariantCulture,
                    "OperationDataStreamCollection Count: {0}, CurrentIndex: {1}.",
                    this.operationDataStreamCollection.Count,
                    this.currentIndex);
                StateManagerStructuredEvents.TraceException(
                    this.traceType,
                    "NamedOperationDataCollection.GetNextAsync.",
                    msg,
                    e);
                throw;
            }
        }