Exemplo n.º 1
0
        /// <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="eTag">ETag value for the entry being updated</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 (!AzureStorageUtils.EvaluateException(exc, out httpStatusCode, out restStatus))
                {
                    throw;
                }

                if (logger.IsVerbose2)
                {
                    logger.Verbose2("UpdateSiloEntryConditionally failed with httpStatusCode={0}, restStatus={1}", httpStatusCode, restStatus);
                }
                if (AzureStorageUtils.IsContentionError(httpStatusCode))
                {
                    return(false);
                }

                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Insert (create new) row entry
        /// </summary>
        /// <param name="siloEntry">Silo Entry to be written</param>
        /// <param name="tableVersionEntry">Version row to update</param>
        /// <param name="tableVersionEtag">Version row eTag</param>
        internal async Task <bool> InsertSiloEntryConditionally(SiloInstanceTableEntry siloEntry, SiloInstanceTableEntry tableVersionEntry, string tableVersionEtag)
        {
            try
            {
                await storage.InsertTwoTableEntriesConditionallyAsync(siloEntry, tableVersionEntry, tableVersionEtag);

                return(true);
            }
            catch (Exception exc)
            {
                HttpStatusCode httpStatusCode;
                string         restStatus;
                if (!AzureStorageUtils.EvaluateException(exc, out httpStatusCode, out restStatus))
                {
                    throw;
                }

                if (logger.IsEnabled(LogLevel.Trace))
                {
                    logger.Trace("InsertSiloEntryConditionally failed with httpStatusCode={0}, restStatus={1}", httpStatusCode, restStatus);
                }
                if (AzureStorageUtils.IsContentionError(httpStatusCode))
                {
                    return(false);
                }

                throw;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Insert (create new) row entry
        /// </summary>
        /// <param name="siloEntry">Silo Entry to be written</param>
        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 (!AzureStorageUtils.EvaluateException(exc, out httpStatusCode, out restStatus))
                {
                    throw;
                }

                if (logger.IsVerbose2)
                {
                    logger.Verbose2("InsertSiloEntryConditionally failed with httpStatusCode={0}, restStatus={1}", httpStatusCode, restStatus);
                }
                if (AzureStorageUtils.IsContentionError(httpStatusCode))
                {
                    return(false);
                }

                throw;
            }
        }
        private void CheckAlertWriteError(string operation, object data1, string data2, Exception exc)
        {
            HttpStatusCode httpStatusCode;
            string         restStatus;

            if (AzureStorageUtils.EvaluateException(exc, out httpStatusCode, out restStatus) && AzureStorageUtils.IsContentionError(httpStatusCode))
            {
                // log at Verbose, since failure on conditional is not not an error. Will analyze and warn later, if required.
                if (Logger.IsVerbose)
                {
                    Logger.Verbose(ErrorCode.AzureTable_13,
                                   $"Intermediate Azure table write error {operation} to table {TableName} data1 {(data1 ?? "null")} data2 {(data2 ?? "null")}", exc);
                }
            }
            else
            {
                Logger.Error(ErrorCode.AzureTable_14,
                             $"Azure table access write error {operation} to table {TableName} entry {data1}", exc);
            }
        }
Exemplo n.º 5
0
        private void CheckAlertWriteError(string operation, object data, string tableVersionData, Exception exc)
        {
            HttpStatusCode httpStatusCode;
            string         restStatus;

            if (AzureStorageUtils.EvaluateException(exc, out httpStatusCode, out restStatus) && AzureStorageUtils.IsContentionError(httpStatusCode))
            {
                // log at Verbose, since failure on conditional is not not an error. Will analyze and warn later, if required.
                if (Logger.IsVerbose)
                {
                    Logger.Verbose(ErrorCode.AzureTable_13,
                                   String.Format("Intermediate Azure table write error {0} to table {1} version {2} entry {3}",
                                                 operation, TableName, (tableVersionData ?? "null"), (data ?? "null")), exc);
                }
            }
            else
            {
                Logger.Error(ErrorCode.AzureTable_14,
                             string.Format("Azure table access write error {0} to table {1} entry {2}", operation, TableName, data), exc);
            }
        }