//Judge whether system are doing checkpoint.
//ilockerId = lockManager.id();
//lock = lockManager.get(ilockerId, lockManager.LOCK_WAITING, lockManager.OBJECT_OBJECT, checkpointOjb, lockManager.LOCK_READ);
//lockManager.put(lock);
if (DbEnvironment.READ_ONLY) throw new ChaiDBException(ErrorCode.DATABASE_IS_READONLY);
//I don't know whether the logic is right ? Check it when release.
if (flagCheck(flags, DB_TXN_NOWAIT | DB_TXN_NOSYNC | DB_TXN_SYNC))
throw new ChaiDBException(ErrorCode.ILLEGAL_FLAG_BEGIN_TXN);
if (flagCombinationCheck(flags, DB_TXN_NOSYNC, DB_TXN_SYNC) == false)
throw new ChaiDBException(ErrorCode.ILLEGAL_COMBINATION_FLAG_BEGIN_TXN);
//if ( txnChain.size() >= maxTxns)
// throw new ChaiDBException(ErrorCode.MAXIMUM_ACTIVE_TXNS, "The number of transaction is reach maximum.");
if (freePool.isEmpty()) { //Free transaction pool is empty.
txn = new TransactionImpl(this); //Allocate memory from heap.
} else {
txn = (TransactionImpl) freePool.remove(); //Removes an element from the pool.
}
/* Sets the flags of transaction. */
if ((flags & Transaction.TXN_DIRTY_READ) != 0) txn.setFlags(Transaction.TXN_DIRTY_READ);
if ((flags & Transaction.TXN_NOSYNC) != 0) txn.setFlags(Transaction.TXN_NOSYNC);
if ((flags & Transaction.TXN_SYNC) != 0) txn.setFlags(Transaction.TXN_SYNC);
if ((flags & Transaction.TXN_NOWAIT) != 0) txn.setFlags(Transaction.TXN_NOWAIT);
/*
* We do not have to write begin records (and if we do not, then we
* need never write records for read-only transactions). However,
* we do need to find the current LSN so that we can store it in the
* transaction structure, so we can know where to take checkpoints.
* Note: Here Zhu Liang will put the value into the beginLsn field of the begun transaction instance.
*/
/* Environment is being recovered by recover routine. Note: <this.flags> */
if ((TransactionManagerImpl.flags & TXN_IN_RECOVERY) != 0) {
throw new ChaiDBException(ErrorCode.IN_RECOVER_PROCESS);
}
/* Make sure that we aren't still recovering prepared transactions. Using only during XA recovery.*/
//if (nRestoredTxns != 0){
// throw new ChaiDBException("txn_begin: recovery of prepared but not yet committed transactions is incomplete.");