in mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java [648:784]
public void commit()
{
// We *must* own the transactionLock
if ( !transactionLock.isHeldByCurrentThread() )
{
String name = Thread.currentThread().getName();
String err = "This thread, '" + name + "' does not hold the transactionLock ";
TXN_LOG.error( err );
throw new RecordManagerException( err );
}
if ( TXN_LOG.isDebugEnabled() )
{
TXN_LOG.debug( "Committing a transaction on thread {}, TxnLevel {}",
Thread.currentThread().getName(), getTxnLevel() );
}
if ( !fileChannel.isOpen() )
{
// Still we have to decrement the TransactionLevel
int txnLevel = decrementTxnLevel();
if ( txnLevel == 0 )
{
// We can safely release the lock
// The file has been closed, nothing remains to commit, let's get out
transactionLock.unlock();
}
return;
}
int nbTxnStarted = CONTEXT.get();
switch ( nbTxnStarted )
{
case ROLLBACKED_TXN:
// The transaction was rollbacked, quit immediatelly
transactionLock.unlock();
return;
case 1:
// We are done with the transaction, we can update the RMHeader and swap the BTreeHeaders
// First update the RMHeader to be sure that we have a way to restore from a crash
updateRecordManagerHeader();
// Swap the BtreeHeaders maps
swapCurrentBtreeHeaders();
// We can now free pages
for ( PageIO pageIo : freedPages )
{
try
{
free( pageIo );
}
catch ( IOException ioe )
{
throw new RecordManagerException( ioe.getMessage() );
}
}
// Release the allocated and freed pages list
freedPages.clear();
allocatedPages.clear();
// And update the RMHeader again, removing the old references to BOB and CPB b-tree headers
// here, we have to erase the old references to keep only the new ones.
updateRecordManagerHeader();
commitCount++;
if ( commitCount >= pageReclaimerThreshold )
{
runReclaimer();
}
// Finally, decrement the number of started transactions
// and release the global lock if possible
int txnLevel = decrementTxnLevel();
if ( txnLevel == 0 )
{
transactionLock.unlock();
}
return;
default:
// We are inner an existing transaction. Just update the necessary elements
// Update the RMHeader to be sure that we have a way to restore from a crash
updateRecordManagerHeader();
// Swap the BtreeHeaders maps
//swapCurrentBtreeHeaders();
// We can now free pages
for ( PageIO pageIo : freedPages )
{
try
{
free( pageIo );
}
catch ( IOException ioe )
{
throw new RecordManagerException( ioe.getMessage() );
}
}
// Release the allocated and freed pages list
freedPages.clear();
allocatedPages.clear();
// And update the RMHeader again, removing the old references to BOB and CPB b-tree headers
// here, we have to erase the old references to keep only the new ones.
updateRecordManagerHeader();
commitCount++;
if ( commitCount >= pageReclaimerThreshold )
{
runReclaimer();
}
// Finally, decrement the number of started transactions
// and release the global lock
txnLevel = decrementTxnLevel();
if ( txnLevel == 0 )
{
transactionLock.unlock();
}
return;
}
}