コード例 #1
0
ファイル: KeyValueDB.cs プロジェクト: quyenbc/BTDB
 internal void UpgradeTransactionToWriteOne(KeyValueDBTransaction transaction, ReadTrLink link)
 {
     lock (_readLinkLock)
     {
         if (link == null && _writeTrInCreation)
         {
             _writeTrInCreation = false;
         }
         else
         {
             if (_writeTr != null || _writeTrInCreation) throw new BTDBTransactionRetryException("Write transaction already running");
             if (link.TransactionNumber != _currentState.TransactionCounter)
                 throw new BTDBTransactionRetryException("Newer write transaction already finished");
         }
         _writeTr = transaction;
         _currentTrCommited = false;
         _commitNeeded = false;
         _newState.TransactionCounter++;
         _unallocatedCounter = 0;
         Debug.Assert(_unallocatedSectorHeadLink == null);
         Debug.Assert(_unallocatedSectorTailLink == null);
         Debug.Assert(_dirtySectorHeadLink == null);
         Debug.Assert(_dirtySectorTailLink == null);
         Debug.Assert(_inTransactionSectorHeadLink == null);
         Debug.Assert(_inTransactionSectorTailLink == null);
         Debug.Assert(_spaceAllocatedInTransaction.Empty);
         Debug.Assert(_spaceDeallocatedInTransaction.Empty);
     }
 }
コード例 #2
0
ファイル: KeyValueDB.cs プロジェクト: quyenbc/BTDB
 internal void DisposeWriteTransaction()
 {
     try
     {
         if (_commitNeeded)
         {
             // rollback
             _freeSpaceAllocatorOptimizer.RollbackWriteTransaction();
             SwapCurrentAndNewState();
             TransferNewStateToCurrentState();
             _commitNeeded = false;
             _spaceUsedByReadOnlyTransactions.UnmergeInPlace(_spaceDeallocatedInTransaction);
             _spaceAllocatedInTransaction.Clear();
             _spaceDeallocatedInTransaction.Clear();
             while (_unallocatedSectorHeadLink != null)
             {
                 LowLevelRemoveFromSectorCache(_unallocatedSectorHeadLink);
                 UnlinkFromUnallocatedSectors(_unallocatedSectorHeadLink);
             }
             while (_dirtySectorHeadLink != null)
             {
                 LowLevelRemoveFromSectorCache(_dirtySectorHeadLink);
                 UnlinkFromDirtySectors(_dirtySectorHeadLink);
             }
             while (_inTransactionSectorHeadLink != null)
             {
                 LowLevelRemoveFromSectorCache(_inTransactionSectorHeadLink);
                 DetransactionalizeSector(_inTransactionSectorHeadLink);
             }
         }
         //Debug.Assert(_sectorCache.Keys.ToList().Exists(l => l < 0) == false);
     }
     finally
     {
         DereferenceReadLink(_readTrLinkHead);
         lock (_readLinkLock)
         {
             _writeTr = null;
         }
     }
     if (!_writtingQueue.IsEmpty) TryToRunNextWrittingTransaction();
 }