Example #1
0
        private EpochRecord WriteEpochRecordWithRetry(int epochNumber, Guid epochId, long lastEpochPosition,
                                                      Guid instanceId)
        {
            long pos   = _writer.Checkpoint.ReadNonFlushed();
            var  epoch = new EpochRecord(pos, epochNumber, epochId, lastEpochPosition, DateTime.UtcNow, instanceId);
            var  rec   = new SystemLogRecord(epoch.EpochPosition, epoch.TimeStamp, SystemRecordType.Epoch,
                                             SystemRecordSerialization.Json, epoch.AsSerialized());

            Log.Debug(
                "=== Writing E{epochNumber}@{epochPosition}:{epochId:B} (previous epoch at {lastEpochPosition}). L={leaderId:B}.",
                epochNumber, epoch.EpochPosition, epochId, lastEpochPosition, epoch.LeaderInstanceId);
            if (!_writer.Write(rec, out pos))
            {
                epoch = new EpochRecord(pos, epochNumber, epochId, lastEpochPosition, DateTime.UtcNow, instanceId);
                rec   = new SystemLogRecord(epoch.EpochPosition, epoch.TimeStamp, SystemRecordType.Epoch,
                                            SystemRecordSerialization.Json, epoch.AsSerialized());
                if (!_writer.Write(rec, out pos))
                {
                    throw new Exception($"Second write try failed at {epoch.EpochPosition}.");
                }
            }
            _writer.Flush();
            _bus.Publish(new SystemMessage.EpochWritten(epoch));
            return(epoch);
        }
Example #2
0
        public ISystemLogRecord CreateEpoch(EpochRecord epoch)
        {
            var result = new SystemLogRecord(
                logPosition: epoch.EpochPosition,
                timeStamp: epoch.TimeStamp,
                systemRecordType: SystemRecordType.Epoch,
                systemRecordSerialization: SystemRecordSerialization.Json,
                data: epoch.AsSerialized());

            return(result);
        }
Example #3
0
        private EpochRecord WriteEpoch(int epochNumber, long lastPos, Guid instanceId)
        {
            long pos   = _writer.Checkpoint.ReadNonFlushed();
            var  epoch = new EpochRecord(pos, epochNumber, Guid.NewGuid(), lastPos, DateTime.UtcNow, instanceId);
            var  rec   = new SystemLogRecord(epoch.EpochPosition, epoch.TimeStamp, SystemRecordType.Epoch,
                                             SystemRecordSerialization.Json, epoch.AsSerialized());

            _writer.Write(rec, out _);
            _writer.Flush();
            return(epoch);
        }
Example #4
0
        public override void When()
        {
            _epochId     = Guid.NewGuid();
            _epochNumber = 7;
            var epoch = new EpochRecord(0, _epochNumber, _epochId, -1, DateTime.UtcNow, Guid.Empty);
            var rec   = new SystemLogRecord(epoch.EpochPosition, epoch.TimeStamp, SystemRecordType.Epoch,
                                            SystemRecordSerialization.Json, epoch.AsSerialized());

            Assert.True(Writer.Write(rec, out _));
            Writer.Flush();
        }
Example #5
0
        private void ProcessSystemRecord(SystemLogRecord record)
        {
            CommitPendingTransaction(_transaction, isTfEof: true);

            if (record.SystemRecordType == SystemRecordType.Epoch)
            {
                // Epoch record is written to TF, but possibly is not added to EpochManager
                // as we could be in Slave\Clone mode. We try to add epoch to EpochManager
                // every time we encounter EpochRecord while chasing. SetLastEpoch call is idempotent,
                // but does integrity checks.
                var epoch = record.GetEpochRecord();
                _epochManager.SetLastEpoch(epoch);
            }
        }
Example #6
0
        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);
        }
        public List <SystemLogRecord> GetSystemLog(DateTime _startDate, DateTime _endDate, string _logtype, string _context)
        {
            List <SystemLogRecord> _ret = new List <SystemLogRecord>();
            string _sql = " select ID,CZSJ,LOGTYPE,LOGTEXT ";

            _sql += " from xt_systemlog t ";
            _sql += " where (CZSJ between :KSRQ and :JSRQ ) ";

            if (_logtype.Trim().Length > 0)
            {
                _sql += string.Format(" and LOGTYPE='{0}' ", _logtype);
            }

            if (_context.Trim().Length > 0)
            {
                _sql += " and (LOGTEXT like '%" + _context + "%' ) ";
            }

            _sql += " order by CZSJ DESC ";
            OracleParameter[] _param =
            {
                new OracleParameter(":KSRQ", OracleDbType.Date),
                new OracleParameter(":JSRQ", OracleDbType.Date)
            };
            _param[0].Value = _startDate;
            _param[1].Value = _endDate;

            OracleDataReader dr = OracleHelper.ExecuteReader(OracleHelper.ConnectionStringProfile, CommandType.Text,
                                                             _sql, _param);

            while (dr.Read())
            {
                SystemLogRecord _mitem = new SystemLogRecord(
                    dr.IsDBNull(0) ? "" : dr.GetString(0),
                    dr.IsDBNull(1) ? DateTime.MinValue : dr.GetDateTime(1),
                    dr.IsDBNull(2) ? "" : dr.GetString(2),
                    dr.IsDBNull(3) ? "" : dr.GetString(3)
                    );
                _ret.Add(_mitem);
            }
            dr.Close();
            return(_ret);
        }
Example #8
0
        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;
        }