public async Task <IReadTransaction> BeginReadTransactionAsync(RetriableOperation retriableOperation = NevermoreDefaults.RetriableOperations, string name = null) { var txn = CreateReadTransaction(retriableOperation, name); await txn.OpenAsync(); return(txn); }
/// <summary> /// Helper method that retry the specified operation on certain exceptions /// </summary> /// <typeparam name="T">operation return type</typeparam> /// <param name="operation">retriable operation</param> /// <returns>operation return value</returns> private T RetryHelper <T>(RetriableOperation <T> operation) { int retryCount = 0; while (true) { try { return(operation()); } catch (ActionNotSupportedException) { throw; } catch (FaultException <DataFault> ) { throw; } catch (CommunicationException ex) { TraceHelper.TraceSource.TraceEvent(TraceEventType.Error, 0, "[DataProxyAgent] . RetryHelper received exception: retryCount={0}, exception={1}", retryCount, ex); // retry on communication exception if (retryCount++ > MaxRetryCount) { throw; } this.RecreateInternalAgent(); } } }
public IReadTransaction BeginReadTransaction(RetriableOperation retriableOperation = NevermoreDefaults.RetriableOperations, string name = null) { var txn = CreateReadTransaction(retriableOperation, name); txn.Open(); return(txn); }
public PreparedCommand(string statement, CommandParameterValues parameterValues, RetriableOperation operation = RetriableOperation.None, DocumentMap mapping = null, TimeSpan?commandTimeout = null, CommandBehavior commandBehavior = CommandBehavior.Default) { Mapping = mapping; Statement = statement; ParameterValues = parameterValues; Operation = operation; CommandTimeout = commandTimeout; CommandBehavior = commandBehavior; }
RetryPolicy GetRetryPolicy(RetriableOperation operation) { if (retriableOperation == RetriableOperation.None) { return(RetryPolicy.NoRetry); } return((retriableOperation & operation) != 0 ? RetryManager.Instance.GetDefaultSqlCommandRetryPolicy() : RetryPolicy.NoRetry); }
public WriteTransaction( RelationalTransactionRegistry registry, RetriableOperation operationsToRetry, IRelationalStoreConfiguration configuration, IKeyAllocator keyAllocator, string name = null ) : base(registry, operationsToRetry, configuration, name) { this.configuration = configuration; this.keyAllocator = keyAllocator; builder = new DataModificationQueryBuilder(configuration, AllocateId); }
public ReadTransaction(RelationalTransactionRegistry registry, RetriableOperation operationsToRetry, IRelationalStoreConfiguration configuration, string name = null) { State = new Dictionary <string, object>(); this.registry = registry; this.operationsToRetry = operationsToRetry; this.configuration = configuration; this.name = name ?? Thread.CurrentThread.Name; if (string.IsNullOrEmpty(name)) { this.name = "<unknown>"; } registry.Add(this); }
/// <summary> /// the helper function to perform the retriable operations. /// </summary> /// <param name="retriableOperation">the delegation method.</param> /// <param name="format">the error format string when exception raised.</param> /// <param name="objParams">the params for the format string.</param> public static void PerformRetriableOperation(RetriableOperation retriableOperation, string format, params object[] objParams) { int retryNumber = 0; do { try { retriableOperation(retryNumber); return; } catch (MessageQueueException e) { // the msmq queue cannot access, then retry 3 times. if (MessageQueueHelper.CanRetry(e)) { retryNumber++; if (retryNumber < MessageQueueHelper.RetryCount) { string errorMessage = string.Empty; if (!string.IsNullOrEmpty(format)) { errorMessage = string.Format(CultureInfo.InvariantCulture, format, objParams) + ", and"; } errorMessage += "Will perform retry[" + retryNumber.ToString(CultureInfo.InvariantCulture) + "], the exception:" + e.ToString(); BrokerTracing.TraceWarning(errorMessage); } else { throw MessageQueueHelper.ConvertMessageQueueException(e); } } else { throw MessageQueueHelper.ConvertMessageQueueException(e); } } catch (Exception) { throw; } System.Threading.Thread.Sleep(100); }while (retryNumber > 0); }
public RelationalTransaction( RelationalTransactionRegistry registry, RetriableOperation retriableOperation, IsolationLevel isolationLevel, ISqlCommandFactory sqlCommandFactory, JsonSerializerSettings jsonSerializerSettings, RelationalMappings mappings, IKeyAllocator keyAllocator, IRelatedDocumentStore relatedDocumentStore, string name = null, ObjectInitialisationOptions objectInitialisationOptions = ObjectInitialisationOptions.None ) { this.registry = registry; this.retriableOperation = retriableOperation; this.sqlCommandFactory = sqlCommandFactory; this.jsonSerializerSettings = jsonSerializerSettings; this.mappings = mappings; this.keyAllocator = keyAllocator; this.relatedDocumentStore = relatedDocumentStore; this.name = name ?? Thread.CurrentThread.Name; this.objectInitialisationOptions = objectInitialisationOptions; if (string.IsNullOrEmpty(name)) { this.name = "<unknown>"; } dataModificationQueryBuilder = new DataModificationQueryBuilder(mappings, jsonSerializerSettings); try { registry.Add(this); connection = new SqlConnection(registry.ConnectionString); connection.OpenWithRetry(); transaction = connection.BeginTransaction(isolationLevel); } catch { Dispose(); throw; } }
public IWriteTransaction BeginWriteTransaction(IsolationLevel isolationLevel = NevermoreDefaults.IsolationLevel, RetriableOperation retriableOperation = NevermoreDefaults.RetriableOperations, string name = null) { var txn = CreateWriteTransaction(retriableOperation, name); txn.Open(isolationLevel); return(txn); }
ReadTransaction CreateReadTransaction(RetriableOperation retriableOperation, string name) { return(new ReadTransaction(registry.Value, retriableOperation, Configuration, name)); }
public async Task <IReadTransaction> BeginReadTransactionAsync(IsolationLevel isolationLevel = NevermoreDefaults.IsolationLevel, RetriableOperation retriableOperation = NevermoreDefaults.RetriableOperations, string name = null) { var txn = CreateReadTransaction(retriableOperation, name); try { await txn.OpenAsync(isolationLevel); return(txn); } catch { txn.Dispose(); throw; } }
public IRelationalTransaction BeginTransaction( RetriableOperation retriableOperation = RetriableOperation.Delete | RetriableOperation.Select, string name = null) { return(BeginTransaction(IsolationLevel.ReadCommitted, retriableOperation, name)); }
public IRelationalTransaction BeginTransaction(IsolationLevel isolationLevel, RetriableOperation retriableOperation = RetriableOperation.Delete | RetriableOperation.Select, string name = null) { return(new RelationalTransaction(registry.Value, retriableOperation, isolationLevel, sqlCommandFactory, jsonSettings, mappings, keyAllocator, relatedDocumentStore, name, objectInitialisationOptions)); }
public async Task <IWriteTransaction> BeginWriteTransactionAsync(IsolationLevel isolationLevel = NevermoreDefaults.IsolationLevel, RetriableOperation retriableOperation = NevermoreDefaults.RetriableOperations, string name = null) { var txn = CreateWriteTransaction(retriableOperation, name); await txn.OpenAsync(isolationLevel); return(txn); }
public IRelationalTransaction BeginTransaction(IsolationLevel isolationLevel = NevermoreDefaults.IsolationLevel, RetriableOperation retriableOperation = NevermoreDefaults.RetriableOperations, string name = null) { return((IRelationalTransaction)BeginWriteTransaction(isolationLevel, retriableOperation, name)); }
public TResult ExecuteScalar <TResult>(string query, CommandParameterValues args, RetriableOperation operation, TimeSpan?commandTimeout = null) { return(ExecuteScalar <TResult>(new PreparedCommand(query, args, operation, commandTimeout: commandTimeout))); }
WriteTransaction CreateWriteTransaction(RetriableOperation retriableOperation, string name) { return(new WriteTransaction(registry.Value, retriableOperation, Configuration, keyAllocator.Value, name)); }
public Task <TResult> ExecuteScalarAsync <TResult>(string query, CommandParameterValues args = null, RetriableOperation retriableOperation = RetriableOperation.Select, TimeSpan?commandTimeout = null, CancellationToken cancellationToken = default) { return(ExecuteScalarAsync <TResult>(new PreparedCommand(query, args, retriableOperation, null, commandTimeout), cancellationToken)); }