Example #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);
        }
Example #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);
        }