예제 #1
0
 public void CanCreateRecoveryManager()
 {
     Assert.DoesNotThrow(() =>
     {
         _recoveryManager = new RecoveryManager(_bufferManager, _logManager, 5);
     });
 }
예제 #2
0
        public void CanRecover()
        {
            _recoveryManager = new RecoveryManager(_bufferManager, _logManager, 6);
            var block = new Block(RandomFilename, 0);

            var buffer = _bufferManager.Pin(block);

            _recoveryManager.Recover();

            _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 checkpointRecord = new CheckpointRecord(_logManager, _bufferManager, record);

            Assert.AreEqual(LogRecordType.Checkpoint, checkpointRecord.Type);
            Assert.AreEqual(1, checkpointRecord.Transactions.Length);
            Assert.AreEqual(6, checkpointRecord.Transactions[0]);
        }
예제 #3
0
        public void CanSetString()
        {
            var page = _fileManager.ResolvePage();

            var block = new Block(RandomFilename, 0);

            page.Read(block);
            page.SetString(0, "default string");
            page.Write(block);

            _recoveryManager = new RecoveryManager(_bufferManager, _logManager, 6);
            var buffer = _bufferManager.Pin(block);

            var lsn = _recoveryManager.SetString(buffer, 0, "not default string");

            _logManager.Flush(lsn);

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

            var enumerator = _logManager.GetEnumerator();

            var record        = enumerator.Current;
            var setBoolRecord = new SetStringRecord(_logManager, _bufferManager, record);

            Assert.AreEqual(LogRecordType.SetString, setBoolRecord.Type);
            Assert.AreEqual(0, setBoolRecord.Block.Id);
            Assert.AreEqual(0, setBoolRecord.Offset);
            Assert.AreEqual("default string", setBoolRecord.Value);
            Assert.AreEqual(6, setBoolRecord.TransactionNumber);
        }
예제 #4
0
        public Transaction(
            ITransactionNumberDispatcher numberDispatcher,
            IBufferManager bufferManager,
            IConcurrencyManager concurrencyManager,
            IFileManager fileManager,
            ILogManager logManager)
        {
            _numberDispatcher   = numberDispatcher;
            _concurrencyManager = concurrencyManager;
            _fileManager        = fileManager;
            _bufferList         = new TransactionBuffersList(bufferManager);

            _transactionNumber = _numberDispatcher.GetNextTransactionNumber();
            _recoveryManager   = new RecoveryManager(bufferManager, logManager, _transactionNumber);
        }
예제 #5
0
        public void CanCreateAndDisposeLogEnumerator()
        {
            _recoveryManager = new RecoveryManager(_bufferManager, _logManager, 5);
            var block  = new Block(RandomFilename, 0);
            var buffer = _bufferManager.Pin(block);

            _recoveryManager.SetInt(buffer, 12, 12);
            _recoveryManager.Commit();

            Assert.DoesNotThrow(() =>
            {
                _enumerator = new LogRecordEnumerator(_logManager, _bufferManager);
                _enumerator.Dispose();
            });
        }
예제 #6
0
        public void CanSetTempString()
        {
            var page = _fileManager.ResolvePage();

            var block = new Block("temp" + RandomFilename, 0);

            page.Read(block);
            page.SetString(0, "default string");
            page.Write(block);

            _recoveryManager = new RecoveryManager(_bufferManager, _logManager, 6);
            var buffer = _bufferManager.Pin(block);

            var lsn = _recoveryManager.SetString(buffer, 0, "string default");

            Assert.AreEqual(-1, lsn);
        }
예제 #7
0
        public void CanSetTempBlob()
        {
            var page = _fileManager.ResolvePage();

            var block = new Block("temp" + RandomFilename, 0);

            page.Read(block);
            page.SetBlob(0, new byte[] { 1, 2, 3 });
            page.Write(block);

            _recoveryManager = new RecoveryManager(_bufferManager, _logManager, 6);
            var buffer = _bufferManager.Pin(block);

            var lsn = _recoveryManager.SetBlob(buffer, 0, new byte[] { 3, 2, 1 });

            Assert.AreEqual(-1, lsn);
        }
예제 #8
0
        public void CanSetTempDate()
        {
            var page = _fileManager.ResolvePage();

            var block = new Block("temp" + RandomFilename, 0);

            page.Read(block);
            page.SetDate(0, new DateTime(2020, 1, 1));
            page.Write(block);

            _recoveryManager = new RecoveryManager(_bufferManager, _logManager, 6);
            var buffer = _bufferManager.Pin(block);

            var lsn = _recoveryManager.SetDate(buffer, 0, new DateTime(2000, 1, 1));

            Assert.AreEqual(-1, lsn);
        }
예제 #9
0
        public void CanSetTempBool()
        {
            var page = _fileManager.ResolvePage();

            var block = new Block("temp" + RandomFilename, 0);

            page.Read(block);
            page.SetBool(0, true);
            page.Write(block);

            _recoveryManager = new RecoveryManager(_bufferManager, _logManager, 6);
            var buffer = _bufferManager.Pin(block);

            var lsn = _recoveryManager.SetBool(buffer, 0, false);

            Assert.AreEqual(-1, lsn);
        }
예제 #10
0
        public void CanRecoverFromUncommitedAndCommitedTransactions()
        {
            var page  = _fileManager.ResolvePage();
            var block = new Block(RandomFilename, 0);

            page.Read(block);
            page.SetInt(0, 222);
            page.Write(block);


            var startRecord = new StartRecord(_logManager, _bufferManager, 1);

            var lsn = startRecord.WriteToLog();

            _logManager.Flush(lsn);

            var startRecord2 = new StartRecord(_logManager, _bufferManager, 2);
            var lsn2         = startRecord2.WriteToLog();

            _logManager.Flush(lsn2);

            _recoveryManager = new RecoveryManager(_bufferManager, _logManager, 1);

            var buffer = _bufferManager.Pin(block);

            _recoveryManager.SetInt(buffer, 0, 123);
            _recoveryManager.SetByte(buffer, 0, 1);
            _recoveryManager.Commit();

            var recoveryManager2 = new RecoveryManager(_bufferManager, _logManager, 2);

            recoveryManager2.SetByte(buffer, 1, 0);

            Assert.DoesNotThrow(() =>
            {
                recoveryManager2.Recover();
                _bufferManager.Unpin(buffer);
            });

            page.Read(block);

            _ = page.GetInt(0, out var resultValue);
            Assert.AreEqual(222, resultValue);
        }
예제 #11
0
        public void CanRecoverSimpleTransaction()
        {
            var startRecord = new StartRecord(_logManager, _bufferManager, 6);

            var lsn = startRecord.WriteToLog();

            _logManager.Flush(lsn);

            _recoveryManager = new RecoveryManager(_bufferManager, _logManager, 6);

            var block  = new Block(RandomFilename, 0);
            var buffer = _bufferManager.Pin(block);

            _recoveryManager.SetInt(buffer, 0, 123);

            Assert.DoesNotThrow(() =>
            {
                _recoveryManager.Recover();
                _bufferManager.Unpin(buffer);
            });
        }
예제 #12
0
        public void CanRollback()
        {
            _recoveryManager = new RecoveryManager(_bufferManager, _logManager, 6);
            var block = new Block(RandomFilename, 0);

            var buffer = _bufferManager.Pin(block);

            _recoveryManager.Rollback();

            _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 RollbackRecord(_logManager, _bufferManager, record);

            Assert.AreEqual(LogRecordType.Rollback, commitRecord.Type);
            Assert.AreEqual(6, commitRecord.TransactionNumber);
        }