Exemplo n.º 1
0
        void NewWrittingTransactionUnsafe(TaskCompletionSource <IKeyValueDBTransaction> tcs)
        {
            var newTransactionRoot = LastCommited.NewTransactionRoot();

            _writingTransaction = new KeyValueDBTransaction(this, newTransactionRoot, true, false);
            tcs.SetResult(_writingTransaction);
        }
Exemplo n.º 2
0
 internal IBTreeRootNode MakeWrittableTransaction(KeyValueDBTransaction keyValueDBTransaction, IBTreeRootNode btreeRoot)
 {
     lock (_writeLock)
     {
         if (_writingTransaction != null)
         {
             throw new BTDBTransactionRetryException("Another writting transaction already running");
         }
         if (LastCommited != btreeRoot)
         {
             throw new BTDBTransactionRetryException("Another writting transaction already finished");
         }
         _writingTransaction = keyValueDBTransaction;
         return(btreeRoot.NewTransactionRoot());
     }
 }
Exemplo n.º 3
0
        internal void CommitWrittingTransaction(IBTreeRootNode btreeRoot, bool temporaryCloseTransactionLog)
        {
            var deltaUlong = unchecked (btreeRoot.CommitUlong - _lastCommited.CommitUlong);

            if (deltaUlong != 0)
            {
                _writerWithTransactionLog.WriteUInt8((byte)KVCommandType.CommitWithDeltaUlong);
                _writerWithTransactionLog.WriteVUInt64(deltaUlong);
            }
            else
            {
                _writerWithTransactionLog.WriteUInt8((byte)KVCommandType.Commit);
            }
            if (DurableTransactions || !temporaryCloseTransactionLog)
            {
                _writerWithTransactionLog.FlushBuffer();
            }
            UpdateTransactionLogInBTreeRoot(btreeRoot);
            if (DurableTransactions)
            {
                _fileWithTransactionLog.HardFlush();
            }
            if (temporaryCloseTransactionLog)
            {
                _writerWithTransactionLog.WriteUInt8((byte)KVCommandType.TemporaryEndOfFile);
                _writerWithTransactionLog.FlushBuffer();
                if (DurableTransactions)
                {
                    _fileWithTransactionLog.HardFlush();
                }
                _fileWithTransactionLog.Truncate();
            }
            lock (_writeLock)
            {
                _writingTransaction = null;
                _lastCommited       = btreeRoot;
                TryDequeWaiterForWrittingTransaction();
            }
        }
Exemplo n.º 4
0
 internal void RevertWrittingTransaction(bool nothingWrittenToTransactionLog)
 {
     if (!nothingWrittenToTransactionLog)
     {
         _writerWithTransactionLog.WriteUInt8((byte)KVCommandType.Rollback);
         var newRoot = _lastCommited.CloneRoot();
         UpdateTransactionLogInBTreeRoot(newRoot);
         lock (_writeLock)
         {
             _writingTransaction = null;
             _lastCommited       = newRoot;
             TryDequeWaiterForWrittingTransaction();
         }
     }
     else
     {
         lock (_writeLock)
         {
             _writingTransaction = null;
             TryDequeWaiterForWrittingTransaction();
         }
     }
 }