internal async Task <bool> DeleteReminderEntryConditionally(ReminderTableEntry reminderEntry, string eTag) { try { await DeleteTableEntryAsync(reminderEntry, eTag); return(true); }catch (Exception exc) { HttpStatusCode httpStatusCode; string restStatus; if (AzureTableUtils.EvaluateException(exc, out httpStatusCode, out restStatus)) { if (Logger.IsEnabled(LogLevel.Trace)) { Logger.Trace("DeleteReminderEntryConditionally failed with httpStatusCode={0}, restStatus={1}", httpStatusCode, restStatus); } if (AzureTableUtils.IsContentionError(httpStatusCode)) { return(false); } } throw; } }
/// <summary> /// Conditionally update the row for this entry, but only if the eTag matches with the current record in data store /// </summary> /// <param name="siloEntry">Silo Entry to be written</param> /// <param name="entryEtag">ETag value for the entry being updated</param> /// <param name="tableVersionEntry">Version row to update</param> /// <param name="versionEtag">ETag value for the version row</param> /// <returns></returns> internal async Task <bool> UpdateSiloEntryConditionally(SiloInstanceTableEntry siloEntry, string entryEtag, SiloInstanceTableEntry tableVersionEntry, string versionEtag) { try { await storage.UpdateTwoTableEntriesConditionallyAsync(siloEntry, entryEtag, tableVersionEntry, versionEtag); return(true); } catch (Exception exc) { HttpStatusCode httpStatusCode; string restStatus; if (!AzureTableUtils.EvaluateException(exc, out httpStatusCode, out restStatus)) { throw; } if (logger.IsEnabled(LogLevel.Trace)) { logger.Trace("UpdateSiloEntryConditionally failed with httpStatusCode={0}, restStatus={1}", httpStatusCode, restStatus); } if (AzureTableUtils.IsContentionError(httpStatusCode)) { return(false); } throw; } }
private async Task <bool> TryOperation(Func <Task> func, string operation = null) { try { await func().ConfigureAwait(false); return(true); } catch (Exception exc) { HttpStatusCode httpStatusCode; string restStatus; if (!AzureTableUtils.EvaluateException(exc, out httpStatusCode, out restStatus)) { throw; } if (logger.IsEnabled(LogLevel.Trace)) { logger.Trace("{0} failed with httpStatusCode={1}, restStatus={2}", operation, httpStatusCode, restStatus); } if (AzureTableUtils.IsContentionError(httpStatusCode)) { return(false); } throw; } }
public void AzureTableErrorCode_IsContentionError() { Assert.True(AzureTableUtils.IsContentionError(HttpStatusCode.PreconditionFailed)); Assert.True(AzureTableUtils.IsContentionError(HttpStatusCode.Conflict)); Assert.True(AzureTableUtils.IsContentionError(HttpStatusCode.NotFound)); Assert.True(AzureTableUtils.IsContentionError(HttpStatusCode.NotImplemented)); Assert.False(AzureTableUtils.IsContentionError((HttpStatusCode)503)); Assert.False(AzureTableUtils.IsContentionError((HttpStatusCode)504)); Assert.False(AzureTableUtils.IsContentionError((HttpStatusCode)408)); Assert.False(AzureTableUtils.IsContentionError((HttpStatusCode)500)); Assert.False(AzureTableUtils.IsContentionError((HttpStatusCode)500)); Assert.False(AzureTableUtils.IsContentionError((HttpStatusCode)500)); Assert.False(AzureTableUtils.IsContentionError((HttpStatusCode)200)); }
private void CheckAlertWriteError(string operation, object data1, string data2, Exception exc) { HttpStatusCode httpStatusCode; if (AzureTableUtils.EvaluateException(exc, out httpStatusCode, out _) && AzureTableUtils.IsContentionError(httpStatusCode)) { // log at Verbose, since failure on conditional is not not an error. Will analyze and warn later, if required. if (Logger.IsEnabled(LogLevel.Debug)) { Logger.Debug((int)Utilities.ErrorCode.AzureTable_13, $"Intermediate Azure table write error {operation} to table {TableName} data1 {(data1 ?? "null")} data2 {(data2 ?? "null")}", exc); } } else { Logger.Error((int)Utilities.ErrorCode.AzureTable_14, $"Azure table access write error {operation} to table {TableName} entry {data1}", exc); } }
/// <summary> /// Insert (create new) row entry /// </summary> internal async Task <bool> TryCreateTableVersionEntryAsync() { try { var versionRow = await storage.ReadSingleTableEntryAsync(DeploymentId, SiloInstanceTableEntry.TABLE_VERSION_ROW); if (versionRow != null && versionRow.Item1 != null) { return(false); } SiloInstanceTableEntry entry = CreateTableVersionEntry(0); await storage.CreateTableEntryAsync(entry); return(true); } catch (Exception exc) { HttpStatusCode httpStatusCode; string restStatus; if (!AzureTableUtils.EvaluateException(exc, out httpStatusCode, out restStatus)) { throw; } if (logger.IsEnabled(LogLevel.Trace)) { logger.Trace("InsertSiloEntryConditionally failed with httpStatusCode={0}, restStatus={1}", httpStatusCode, restStatus); } if (AzureTableUtils.IsContentionError(httpStatusCode)) { return(false); } throw; } }
internal async Task <string> UpsertRow(ReminderTableEntry reminderEntry) { try { return(await UpsertTableEntryAsync(reminderEntry)); } catch (Exception exc) { HttpStatusCode httpStatusCode; string restStatus; if (AzureTableUtils.EvaluateException(exc, out httpStatusCode, out restStatus)) { if (Logger.IsEnabled(LogLevel.Trace)) { Logger.Trace("UpsertRow failed with httpStatusCode={0}, restStatus={1}", httpStatusCode, restStatus); } if (AzureTableUtils.IsContentionError(httpStatusCode)) { return(null); // false; } } throw; } }