internal virtual async Task AddAsync(TKey key, TValue value, TimeSpan timeout, CancellationToken cancellationToken, ITransaction transaction = null) { BackupRestoreTrace.TraceSource.WriteInfo(TraceType, "AddAsync Key: {0} , Value {1}", key, value); try { if (transaction == null) { using (transaction = this.StatefulService.StateManager.CreateTransaction()) { await this.StoreReliableDictionary.AddAsync(transaction, key, value, timeout, cancellationToken); await transaction.CommitAsync(); } } else { await this.StoreReliableDictionary.AddAsync(transaction, key, value, timeout, cancellationToken); } } catch (Exception exception) { if (exception is ArgumentException) { BackupRestoreTrace.TraceSource.WriteInfo(TraceType, "Key Already exist in Store {0}", key); throw new FabricBackupRestoreKeyAlreadyExisingException(); } else { BackupRestoreTrace.TraceSource.WriteInfo(TraceType, "Exception in addition to store"); UtilityHelper.LogException(TraceType, exception); this.HandleException(exception); } } }
internal virtual async Task AddOrUpdateAsync(TKey key, TValue value, Func <TKey, TValue, TValue> updateValueFunc, TimeSpan timeout, CancellationToken cancellationToken, ITransaction transaction = null) { BackupRestoreTrace.TraceSource.WriteInfo(TraceType, "AddOrUpdateAsync Key: {0} , Value {1}", key, value); try { if (transaction == null) { using (transaction = this.StatefulService.StateManager.CreateTransaction()) { await this.StoreReliableDictionary.AddOrUpdateAsync(transaction, key, value, updateValueFunc, timeout, cancellationToken); await transaction.CommitAsync(); } } else { await this.StoreReliableDictionary.AddOrUpdateAsync(transaction, key, value, updateValueFunc, timeout, cancellationToken);; } } catch (Exception exception) { if (exception is TransactionFaultedException) { BackupRestoreTrace.TraceSource.WriteInfo(TraceType, "TransactionFaultedException {0}", key); throw new FabricBackupRestoreLocalRetryException(); } else { BackupRestoreTrace.TraceSource.WriteInfo(TraceType, "Exception in addition to store"); UtilityHelper.LogException(TraceType, exception); this.HandleException(exception); } } }
internal virtual async Task DeleteValueAsync(TKey key, TimeSpan timeout, CancellationToken cancellationToken, ITransaction transaction = null) { BackupRestoreTrace.TraceSource.WriteInfo(TraceType, "DeleteValueAsync Key: {0}", key); try { if (transaction == null) { using (transaction = this.StatefulService.StateManager.CreateTransaction()) { ConditionalValue <TValue> conditionalValue = await this.StoreReliableDictionary.TryRemoveAsync(transaction, key, timeout, cancellationToken); if (conditionalValue.HasValue) { await transaction.CommitAsync(); } else { transaction.Abort(); throw new FabricBackupKeyNotExisingException(); } } } else { ConditionalValue <TValue> conditionalValue = await this.StoreReliableDictionary.TryRemoveAsync(transaction, key, timeout, cancellationToken); if (!conditionalValue.HasValue) { throw new FabricBackupKeyNotExisingException(); } } } catch (Exception exception) { BackupRestoreTrace.TraceSource.WriteInfo(TraceType, "DeleteValueAsync Key : {0} Failed ", key); UtilityHelper.LogException(TraceType, exception); this.HandleException(exception); } }