예제 #1
0
        private void OnTakeSnapshot(long termPosition)
        {
            long   recordingId;
            string channel  = ctx.SnapshotChannel();
            int    streamId = ctx.SnapshotStreamId();

            using (AeronArchive archive = AeronArchive.Connect(archiveCtx))
                using (Publication publication = archive.AddRecordedExclusivePublication(channel, streamId))
                {
                    try
                    {
                        CountersReader counters  = aeron.CountersReader();
                        int            counterId = AwaitRecordingCounter(publication, counters);

                        recordingId = RecordingPos.GetRecordingId(counters, counterId);
                        SnapshotState(publication, termBaseLogPosition + termPosition);
                        service.OnTakeSnapshot(publication);

                        AwaitRecordingComplete(recordingId, publication.Position, counters, counterId, archive);
                    }
                    finally
                    {
                        archive.StopRecording(publication);
                    }
                }

            recordingLog.AppendSnapshot(recordingId, leadershipTermId, termBaseLogPosition, termPosition, timestampMs);
        }
예제 #2
0
        private long OnTakeSnapshot(long logPosition, long leadershipTermId)
        {
            long recordingId;

            using (AeronArchive archive = AeronArchive.Connect(archiveCtx))
                using (Publication publication = aeron.AddExclusivePublication(ctx.SnapshotChannel(), ctx.SnapshotStreamId()))
                {
                    var  channel        = ChannelUri.AddSessionId(ctx.SnapshotChannel(), publication.SessionId);
                    long subscriptionId = archive.StartRecording(channel, ctx.SnapshotStreamId(), SourceLocation.LOCAL);

                    try
                    {
                        CountersReader counters  = aeron.CountersReader();
                        int            counterId = AwaitRecordingCounter(publication.SessionId, counters);

                        recordingId = RecordingPos.GetRecordingId(counters, counterId);
                        SnapshotState(publication, logPosition, leadershipTermId);
                        service.OnTakeSnapshot(publication);

                        AwaitRecordingComplete(recordingId, publication.Position, counters, counterId, archive);
                    }
                    finally
                    {
                        archive.StopRecording(subscriptionId);
                    }
                }

            return(recordingId);
        }
예제 #3
0
        private void LoadSnapshot(long recordingId)
        {
            using (AeronArchive archive = AeronArchive.Connect(archiveCtx))
            {
                RecordingExtent recordingExtent = new RecordingExtent();
                if (0 == archive.ListRecording(recordingId, recordingExtent))
                {
                    throw new System.InvalidOperationException("Could not find recordingId: " + recordingId);
                }

                string channel  = ctx.ReplayChannel();
                int    streamId = ctx.ReplayStreamId();

                long length    = recordingExtent.stopPosition - recordingExtent.startPosition;
                int  sessionId = (int)archive.StartReplay(recordingId, 0, length, channel, streamId);

                string replaySessionChannel = ChannelUri.AddSessionId(channel, sessionId);
                using (Subscription subscription = aeron.AddSubscription(replaySessionChannel, streamId))
                {
                    Image image = AwaitImage(sessionId, subscription);
                    LoadState(image);
                    service.OnLoadSnapshot(image);
                }
            }
        }
예제 #4
0
        private void LoadSnapshot(long recordingId)
        {
            using (AeronArchive archive = AeronArchive.Connect(archiveCtx))
            {
                string channel   = ctx.ReplayChannel();
                int    streamId  = ctx.ReplayStreamId();
                int    sessionId = (int)archive.StartReplay(recordingId, 0, AeronArchive.NULL_LENGTH, channel, streamId);

                string replaySessionChannel = ChannelUri.AddSessionId(channel, sessionId);
                using (Subscription subscription = aeron.AddSubscription(replaySessionChannel, streamId))
                {
                    Image image = AwaitImage(sessionId, subscription);
                    LoadState(image);
                    service.OnLoadSnapshot(image);
                }
            }
        }