Beispiel #1
0
        public void CanWriteMultipleCommitRecordsToLog()
        {
            _logRecord = new CommitRecord(_logManager, _bufferManager, 1);
            var lsn  = _logRecord.WriteToLog();
            var lsn2 = new CommitRecord(_logManager, _bufferManager, 2).WriteToLog();

            _logManager.Flush(lsn2);
            var page = _fileManager.ResolvePage();

            _ = page.Read(new Block(_logFileName, 0));

            _ = page.GetInt(0, out var nextResPosition);
            _ = page.GetInt(sizeof(int), out var recordType1);
            _ = page.GetInt(sizeof(int) * 2, out var transactionId1);


            _ = page.GetInt(12 + 0, out var recordLength2);
            _ = page.GetInt(12 + sizeof(int), out var recordType2);
            _ = page.GetInt(12 + sizeof(int) * 2, out var transactionId2);

            Assert.AreEqual(0, lsn);
            Assert.AreEqual(1, lsn2);

            Assert.AreEqual((sizeof(int) + sizeof(LogRecordType) + sizeof(int)) * 2, nextResPosition);
            Assert.AreEqual((int)LogRecordType.Commit, recordType1);
            Assert.AreEqual(1, transactionId1);

            Assert.AreEqual(0, recordLength2);
            Assert.AreEqual((int)LogRecordType.Commit, recordType2);
            Assert.AreEqual(2, transactionId2);
        }
Beispiel #2
0
        public void Commit()
        {
            _bufferManager.FlushAll(_transactionNumber);

            var lsn = new CommitRecord(_logManager, _bufferManager, _transactionNumber)
                      .WriteToLog();

            _logManager.Flush(lsn);
        }
Beispiel #3
0
        public void CanReadCommitRecord()
        {
            var rec = new CommitRecord(_logManager, _bufferManager, 5);
            var lsn = rec.WriteToLog();

            _logManager.Flush(lsn);


            _enumerator = new LogRecordEnumerator(_logManager, _bufferManager);
            var record = _enumerator.Current as CommitRecord;

            Assert.AreEqual(LogRecordType.Commit, record.Type);
            Assert.AreEqual(5, record.TransactionNumber);
        }
Beispiel #4
0
        public void CanReadBackwardsFromLog()
        {
            _logRecord = new CommitRecord(_logManager, _bufferManager, 1);
            var lsn = _logRecord.WriteToLog();

            _logManager.Flush(lsn);

            var enumerator     = _logManager.GetEnumerator();
            var basicLogRecord = enumerator.Current;

            var logRecord = new CommitRecord(_logManager, _bufferManager, basicLogRecord);

            Assert.AreEqual(LogRecordType.Commit, logRecord.Type);
            Assert.AreEqual(1, logRecord.TransactionNumber);
        }
        private Dictionary <Guid, CommitRecord> MakeCommitRecords(int count, int size)
        {
            var result = new Dictionary <Guid, CommitRecord>();

            for (int j = 0; j < size; j++)
            {
                var r = new CommitRecord()
                {
                    Timestamp         = DateTime.UtcNow,
                    WriteParticipants = new List <ParticipantId>(),
                };
                for (int i = 0; i < size; i++)
                {
                    r.WriteParticipants.Add(MakeParticipantId());
                }
                result.Add(Guid.NewGuid(), r);
            }
            return(result);
        }
Beispiel #6
0
        public void CanCommit()
        {
            _recoveryManager = new RecoveryManager(_bufferManager, _logManager, 6);
            var block = new Block(RandomFilename, 0);

            var buffer = _bufferManager.Pin(block);

            _recoveryManager.Commit();

            _bufferManager.Unpin(buffer);
            _bufferManager.FlushAll(6);

            var page = _fileManager.ResolvePage();

            _ = page.Read(new Block(_name, 0));

            var enumerator = _logManager.GetEnumerator();

            var record       = enumerator.Current;
            var commitRecord = new CommitRecord(_logManager, _bufferManager, record);

            Assert.AreEqual(LogRecordType.Commit, commitRecord.Type);
            Assert.AreEqual(6, commitRecord.TransactionNumber);
        }
Beispiel #7
0
            public override Record Clone()
            {
                CommitRecord rec = (CommitRecord)MemberwiseClone();

                return(rec);
            }
Beispiel #8
0
 protected override void AssignRecord(Record rec)
 {
     record = (CommitRecord)rec;
 }