/// <summary> /// Release current thread transaction /// </summary> public void ReleaseTransaction(TransactionService transaction) { // dispose current transaction transaction.Dispose(); bool keepLocked; lock (_transactions) { // remove from "open transaction" list _transactions.Remove(transaction.TransactionID); // return freePages used area _freePages += transaction.MaxTransactionSize; // check if current thread contains more query transactions keepLocked = _transactions.Values.Any(x => x.ThreadID == Environment.CurrentManagedThreadId); } // unlock thread-transaction only if there is no more transactions if (keepLocked == false) { _locker.ExitTransaction(); } // remove transaction from thread if are no queryOnly transaction if (transaction.QueryOnly == false) { ENSURE(_slot.Value == transaction, "current thread must contains transaction parameter"); // clear thread slot for new transaction _slot.Value = null; } }
public TransactionService GetTransaction(bool create, bool queryOnly, out bool isNew) { var transaction = _slot.Value; if (create && transaction == null) { isNew = true; bool alreadyLock; // must lock _transaction before work with _transactions (GetInitialSize use _transactions) lock (_transactions) { if (_transactions.Count >= MAX_OPEN_TRANSACTIONS) { throw new LiteException(0, "Maximum number of transactions reached"); } var initialSize = this.GetInitialSize(); // check if current thread contains any transaction alreadyLock = _transactions.Values.Any(x => x.ThreadID == Environment.CurrentManagedThreadId); transaction = new TransactionService(_header, _locker, _disk, _walIndex, initialSize, this, queryOnly); // add transaction to execution transaction dict _transactions[transaction.TransactionID] = transaction; } // enter in lock transaction after release _transaction lock if (alreadyLock == false) { try { _locker.EnterTransaction(); } catch { transaction.Dispose(); lock (_transactions) { // return pages _freePages += transaction.MaxTransactionSize; _transactions.Remove(transaction.TransactionID); } throw; } } // do not store in thread query-only transaction if (queryOnly == false) { _slot.Value = transaction; } } else { isNew = false; } return(transaction); }
/// <summary> /// Dispose transaction and remove from global variable /// </summary> internal void ClearTransaction() { _locker.Release(); _transaction.Dispose(); _transaction = null; }