/// <summary> /// Aborts a transaction and releases it. /// </summary> /// <param name="trans">Transaction to be aborted.</param> public void AbortTransaction(IDbTransaction trans) { if (trans == null) { return; } bool isRequestTransaction; TransactionInfo transInfo = GetTransactionInfo(trans, out isRequestTransaction); if (transInfo != null) { #if DEBUG_DBCONNECTIONPOOLING OSTrace.Info("DBConnectionPooling[TID=" + transInfo.Transaction.GetHashCode() + "] - returned to pool"); OSTrace.Error(new StackTrace().ToString()); #endif transInfo.Release(); if (isRequestTransaction) { RequestTransactionInfo = null; } else { TransactionPool.Remove(transInfo.Transaction); } transInfo.ReturnConnectionToPool(); } }
protected TransactionInfo AddToPoolAndReserve() { lock (this) { TransactionInfo transInfo = null; while (transInfo == null) { transInfo = BuildTransactionInfo(); transInfo.Reserve(); //drivers doesn't ensure connection is good so make sure if (transInfo.Transaction.Connection == null || transInfo.Transaction.Connection.State == ConnectionState.Closed) { if (transInfo.Transaction.Connection != null) { transInfo.ReturnConnectionToPool(); } LogException(new InvalidTransactionException("Connection in transaction is null."), new StackTrace(), "Releasing connection pools and retrying"); transInfo = null; // retry; TransactionService.ReleasePooledConnections("Connection in transaction is null."); Thread.Sleep(TransactionServiceConstants.RETRY_CONNECTION_TIME); } } #if DEBUG_DBCONNECTIONPOOLING OSTrace.Info("DBConnectionPooling[TID=" + transInfo.Transaction.GetHashCode() + "] - reserved from pool"); OSTrace.Error(new StackTrace().ToString()); #endif TransactionPool.Add(transInfo.Transaction, transInfo); return(transInfo); } }
static IEnumerable <IPlatformTableSourceColumnInfo> TryGetColumnsFromExpression(string indexName, string columnExpression, IEnumerable <IPlatformTableSourceColumnInfo> columns) { var setOfColumns = new HashSet <IPlatformTableSourceColumnInfo>(); try { var matches = ColumnNameRegex.Matches(columnExpression); foreach (Match match in matches) { // Second group matches the capturing group in the regex above (first group matches the whole regex). var column = columns.SingleOrDefault(c => c.Name.EqualsIgnoreCase(match.Groups[1].Value)); if (column != null) { // Workaround for yield return inside try-catch block. setOfColumns.Add(column); } else { OSTrace.Info("Unable to find a column in index {0} with expression {1}".F(indexName, columnExpression)); } } } catch (Exception e) { // No need to propagete the exception. Just tolerate the error and proceed. // The result is a possible inconsistency warning while publishing. OSTrace.Error("Error while parsing index {0} with expression {1}".F(indexName, columnExpression), e); } return(setOfColumns.AsEnumerable()); }
public DatabasePluginProvider(IEnumerable <DirectoryInfo> plugins) { pluginDirectories = plugins; LoadPlugins((e, s) => { OSTrace.Info(s, e); }); }
/// <summary> /// Releases a transaction to the pool. /// If the transaction is poolable, it is released and put back into the pool, otherwise it is removed. /// Throws an <see cref="InvalidTransactionReleaseException"/> if the transaction is not releasable. /// </summary> /// <exception cref="InvalidTransactionReleaseException">Occurs if the transaction is not releasable.</exception> /// <param name="trans">Transaction to be released.</param> public virtual void ReleaseTransaction(IDbTransaction trans) { if (trans == null) { return; } TransactionInfo transInfo = (TransactionInfo)TransactionPool[trans]; if (transInfo != null) { if (!transInfo.IsReleasable) { throw (new InvalidTransactionReleaseException("Cannot release a transaction that was created with \"GetCommitableTransaction\". Use commit or rollback")); } #if DEBUG_DBCONNECTIONPOOLING OSTrace.Info("DBConnectionPooling[TID=" + transInfo.Transaction.GetHashCode() + "] - returned to pool"); OSTrace.Error(new StackTrace().ToString()); #endif if (transInfo.IsPoolable) { transInfo.Release(); } else { TransactionPool.Remove(trans); } } else { try { if (RequestTransactionInfo != null && trans == RequestTransactionInfo.Transaction) { //when releasing the request transaction make sure the connection is ok if (trans.Connection != null && trans.Connection.State != ConnectionState.Open) { LogException(new InvalidTransactionException("Request transaction not open on release."), new StackTrace(), "Request Transaction discarded due to connection not being in a correct state."); //clear and try to dispose connection lock (this) { RequestTransactionInfo = null; } trans.Connection.Dispose(); } else { RequestTransactionInfo.MarkChange(); } } } catch { //this is a best effort } } }
private void SafeEndTransaction(TransactionInfo transInfo, bool commit, bool toFreeResources) { try { #if DEBUG_DBCONNECTIONPOOLING OSTrace.Info("DBConnectionPooling[TID=" + transInfo.Transaction.GetHashCode() + "] - returned to pool"); OSTrace.Error(new StackTrace().ToString()); #endif EndTransaction(transInfo, commit, toFreeResources); } catch (Exception e) { #if DEBUG_DBCONNECTIONPOOLING OSTrace.Error("DBConnectionPooling[TID=" + transInfo.Transaction.GetHashCode() + "]"); OSTrace.Error(new StackTrace().ToString()); #endif EventLogger.WriteError(String.Format("Error closing the transaction to the database: {0}\n{1}\n{2}", e.Message, e.StackTrace, new StackTrace(true))); } }
public LoggingPluginProvider() { LoadPlugins((e, s) => { OSTrace.Info(s, e); }); }
protected TransactionInfo GetAndReserveFromPoolUnchecked() { TransactionInfo[] transactions; lock (TransactionPool.SyncRoot) { transactions = TransactionPool.Values.Cast <TransactionInfo>().ToArray(); } foreach (TransactionInfo transInfo in transactions) { if (transInfo.Free) { lock (transInfo) { if (transInfo.Free) { DateTime lastChange = transInfo.LastChange; transInfo.Reserve(); //#52135, we already have nice checks for the pooled connections if (transInfo.Transaction.Connection == null || transInfo.Connection.State == ConnectionState.Closed) { // build exception report IDbConnection shadowConnection = transInfo.Connection; string exceptTxt = "Connection in transaction is null or closed (TransactionInfo Status: "; try { if (shadowConnection == null) { exceptTxt += "Connection=null, "; } else { exceptTxt += String.Format("Connection.State=='{0}', ", shadowConnection.State.ToString()); } exceptTxt += String.Format("Free='{0}', CreationTime='{1}', LastChange='{2}', ReaderCount='{3}')", transInfo.Free, transInfo.CreationTime, lastChange, transInfo.ReaderCount); int numTransactions = transactions.Length; int numFree = CountFreeTransactionsInPool(transactions); exceptTxt += String.Format(". (Pool Status: Total={0}, Free={1})", numTransactions, numFree); } catch { } finally { // remove and cleanup everything TransactionPool.Remove(transInfo.Transaction); transInfo.Transaction.Dispose(); if (transInfo.Connection != null) { transInfo.Connection.Dispose(); } } throw new InvalidTransactionException(exceptTxt); } else { #if DEBUG_DBCONNECTIONPOOLING OSTrace.Info("DBConnectionPooling[TID=" + transInfo.Transaction.GetHashCode() + "] - reserved from pool"); OSTrace.Error(new StackTrace().ToString()); #endif return(transInfo); } } } } } // No free transaction found. Add a new one and return it. return(AddToPoolAndReserve()); }
public CachePluginProvider() { LoadPlugins((e, s) => { OSTrace.Info(s, e); }); }