예제 #1
0
        /// <summary>
        /// Gets the snapshot for the given stream/bucket
        /// </summary>
        /// <param name="bucketId"></param>
        /// <param name="streamId"></param>
        /// <param name="maxRevision"></param>
        /// <returns></returns>
        public ISnapshot GetSnapshot(string bucketId, string streamId, int maxRevision)
        {
            ISnapshot snapshot         = null;
            var       snapshotPageBlob = WrappedPageBlob.GetAssumingExists(_primaryContainer, bucketId + "/ss/" + streamId);

            if (snapshotPageBlob != null)
            {
                var snapshotSize     = Convert.ToInt32(snapshotPageBlob.Metadata["ss_data_size_bytes"]);
                var snapshotRevision = Convert.ToInt32(snapshotPageBlob.Metadata["ss_stream_revision"]);

                if (snapshotRevision <= maxRevision && snapshotSize != 0)
                {
                    var snapshotBytes  = snapshotPageBlob.DownloadBytes(0, snapshotSize);
                    var snapshotObject = _serializer.Deserialize <object>(snapshotBytes);
                    snapshot = new Snapshot(bucketId, streamId, snapshotRevision, snapshotObject);
                }
                else
                {
                    Logger.Info("Snapshot exists for stream [{0}] at revision [{1}] but not being returned because max revision desired was [{2}]",
                                streamId, snapshotRevision, maxRevision);
                }
            }

            return(snapshot);
        }
예제 #2
0
        /// <summary>
        /// Marks a stream Id's commit as dispatched.
        /// </summary>
        /// <param name="commit">The commit object to mark as dispatched.</param>
        public void MarkCommitAsDispatched(ICommit commit)
        {
            AddCheckpointTableEntry(commit);

            var pageBlob = WrappedPageBlob.GetAssumingExists(_primaryContainer, commit.BucketId + "/" + commit.StreamId);
            HeaderDefinitionMetadata headerDefinition = null;
            var header = GetHeaderWithRetry(pageBlob, out headerDefinition);

            // we must commit at a page offset, we will just track how many pages in we must start writing at
            foreach (var commitDefinition in header.PageBlobCommitDefinitions)
            {
                if (commit.CommitId == commitDefinition.CommitId)
                {
                    commitDefinition.IsDispatched = true;
                    --header.UndispatchedCommitCount;
                }
            }

            CommitNewMessage(pageBlob, null, header, headerDefinition,
                             headerDefinition.HeaderStartLocationOffsetBytes);
        }