Exemple #1
0
        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);
        }
Exemple #2
0
 /// <summary>
 /// Check if transaction size reach limit AND check if is possible extend this limit
 /// </summary>
 public bool CheckSafepoint(TransactionService trans)
 {
     return
         (trans.Pages.TransactionSize >= trans.MaxTransactionSize &&
          this.TryExtend(trans) == false);
 }
Exemple #3
0
 public QueryPipe(TransactionService transaction, IDocumentLookup loader, SortDisk tempDisk, bool utcDate)
     : base(transaction, loader, tempDisk, utcDate)
 {
 }
Exemple #4
0
 public GroupByPipe(TransactionService transaction, IDocumentLookup loader, SortDisk tempDisk, EnginePragmas pragmas)
     : base(transaction, loader, tempDisk, pragmas)
 {
 }
Exemple #5
0
 public QueryPipe(TransactionService transaction, IDocumentLookup loader, EnginePragmas pragmas)
     : base(transaction, loader, pragmas)
 {
 }
Exemple #6
0
 /// <summary>
 /// Dispose transaction and remove from global variable
 /// </summary>
 internal void ClearTransaction()
 {
     _locker.Release();
     _transaction.Dispose();
     _transaction = null;
 }