コード例 #1
0
ファイル: EpochRecord.cs プロジェクト: danieldeb/EventStore
            public EpochRecordDto(EpochRecord rec)
            {
                EpochPosition = rec.EpochPosition;
                EpochNumber = rec.EpochNumber;
                EpochId = rec.EpochId;

                PrevEpochPosition = rec.PrevEpochPosition;
                TimeStamp = rec.TimeStamp;
            }
コード例 #2
0
            public SubscribeReplica(long logPosition, Guid chunkId, EpochRecord[] lastEpochs, IPEndPoint replicaEndPoint, 
                                    Guid masterId, Guid subscriptionId, bool isPromotable)
            {
                Ensure.Nonnegative(logPosition, "logPosition");
                Ensure.NotNull(lastEpochs, "lastEpochs");
                Ensure.NotEmptyGuid(masterId, "masterId");
                Ensure.NotEmptyGuid(subscriptionId, "subscriptionId");
                Ensure.NotNull(replicaEndPoint, "replicaEndPoint");

                LogPosition = logPosition;
                ChunkId = chunkId;
                LastEpochs = lastEpochs;
                ReplicaEndPoint = replicaEndPoint;
                MasterId = masterId;
                SubscriptionId = subscriptionId;
                IsPromotable = isPromotable;
            }
コード例 #3
0
ファイル: EpochManager.cs プロジェクト: danieldeb/EventStore
        private void UpdateLastEpoch(EpochRecord epoch, bool flushWriter)
        {
            lock (_locker)
            {
                _epochs[epoch.EpochNumber] = epoch;
                _lastEpochNumber = epoch.EpochNumber;
                _lastEpochPosition = epoch.EpochPosition;
                _minCachedEpochNumber = Math.Max(_minCachedEpochNumber, epoch.EpochNumber - CachedEpochCount + 1);
                _epochs.Remove(_minCachedEpochNumber - 1);

                if (flushWriter)
                    _writer.Flush();
                // Now update epoch checkpoint, so on restart we don't scan sequentially TF.
                _checkpoint.Write(epoch.EpochPosition);
                _checkpoint.Flush();

                Log.Debug("=== Update Last Epoch E{0}@{1}:{2:B} (previous epoch at {3}).", 
                          epoch.EpochNumber, epoch.EpochPosition, epoch.EpochId, epoch.PrevEpochPosition);
            }
        }
コード例 #4
0
ファイル: EpochManager.cs プロジェクト: danieldeb/EventStore
        public void SetLastEpoch(EpochRecord epoch)
        {
            Ensure.NotNull(epoch, "epoch");

            lock (_locker)
            {
                if (epoch.EpochPosition > _lastEpochPosition)
                {
                    UpdateLastEpoch(epoch, flushWriter: false);
                    return;
                }
            }

            // Epoch record must have been already written, so we need to make sure it is where we expect it to be.
            // If this check fails, then there is something very wrong with epochs, data corruption is possible.
            if (!IsCorrectEpochAt(epoch.EpochPosition, epoch.EpochNumber, epoch.EpochId))
            {
                throw new Exception(string.Format("Not found epoch at {0} with epoch number: {1} and epoch ID: {2}. "
                                                  + "SetLastEpoch FAILED! Data corruption risk!",
                                                  epoch.EpochPosition,
                                                  epoch.EpochNumber,
                                                  epoch.EpochId));
            }
        }
コード例 #5
0
ファイル: EpochManager.cs プロジェクト: danieldeb/EventStore
        private EpochRecord WriteEpochRecordWithRetry(int epochNumber, Guid epochId, long lastEpochPosition)
        {
            long pos = _writer.Checkpoint.ReadNonFlushed();
            var epoch = new EpochRecord(pos, epochNumber, epochId, lastEpochPosition, DateTime.UtcNow);
            var rec = new SystemLogRecord(epoch.EpochPosition, epoch.TimeStamp, SystemRecordType.Epoch, SystemRecordSerialization.Json, epoch.AsSerialized());

            if (!_writer.Write(rec, out pos))
            {
                epoch = new EpochRecord(pos, epochNumber, epochId, lastEpochPosition, DateTime.UtcNow);
                rec = new SystemLogRecord(epoch.EpochPosition, epoch.TimeStamp, SystemRecordType.Epoch, SystemRecordSerialization.Json, epoch.AsSerialized());
                if (!_writer.Write(rec, out pos))
                    throw new Exception(string.Format("Second write try failed at {0}.", epoch.EpochPosition));
            }
            Log.Debug("=== Writing E{0}@{1}:{2:B} (previous epoch at {3}).", epochNumber, epoch.EpochPosition, epochId, lastEpochPosition);
            return epoch;
        }
コード例 #6
0
 public void SetLastEpoch(EpochRecord epoch)
 {
     throw new NotImplementedException();
 }