Esempio n. 1
0
 private ReminderEntry ConvertFromTableEntry(ReminderTableEntry tableEntry, string eTag)
 {
     try
     {
         return(new ReminderEntry
         {
             GrainRef = this.grainReferenceConverter.GetGrainFromKeyString(tableEntry.GrainReference),
             ReminderName = tableEntry.ReminderName,
             StartAt = LogFormatter.ParseDate(tableEntry.StartAt),
             Period = TimeSpan.Parse(tableEntry.Period),
             ETag = eTag,
         });
     }
     catch (Exception exc)
     {
         var error =
             $"Failed to parse ReminderTableEntry: {tableEntry}. This entry is corrupt, going to ignore it.";
         logger.Error((int)AzureUtils.Utilities.ErrorCode.AzureTable_49, error, exc);
         throw;
     }
     finally
     {
         string serviceIdStr = ReminderTableEntry.ConstructServiceIdStr(remTableManager.ServiceId);
         if (!tableEntry.ServiceId.Equals(serviceIdStr))
         {
             var error =
                 $"Read a reminder entry for wrong Service id. Read {tableEntry}, but my service id is {serviceIdStr}. Going to discard it.";
             logger.Warn((int)AzureUtils.Utilities.ErrorCode.AzureTable_ReadWrongReminder, error);
             throw new OrleansException(error);
         }
     }
 }
Esempio n. 2
0
        private static ReminderTableEntry ConvertToTableEntry(ReminderEntry remEntry, Guid serviceId, string deploymentId)
        {
            string partitionKey = ReminderTableEntry.ConstructPartitionKey(serviceId, remEntry.GrainRef);
            string rowKey       = ReminderTableEntry.ConstructRowKey(remEntry.GrainRef, remEntry.ReminderName);
            string serviceIdStr = ReminderTableEntry.ConstructServiceIdStr(serviceId);

            var consistentHash = remEntry.GrainRef.GetUniformHashCode();

            return(new ReminderTableEntry
            {
                PartitionKey = partitionKey,
                RowKey = rowKey,

                ServiceId = serviceIdStr,
                DeploymentId = deploymentId,
                GrainReference = remEntry.GrainRef.ToKeyString(),
                ReminderName = remEntry.ReminderName,

                StartAt = LogFormatter.PrintDate(remEntry.StartAt),
                Period = remEntry.Period.ToString(),

                GrainRefConsistentHash = String.Format("{0:X8}", consistentHash),
                ETag = remEntry.ETag,
            });
        }
Esempio n. 3
0
        public async Task <bool> RemoveRow(GrainReference grainRef, string reminderName, string eTag)
        {
            var entry = new ReminderTableEntry
            {
                PartitionKey = ReminderTableEntry.ConstructPartitionKey(remTableManager.ServiceId, grainRef),
                RowKey       = ReminderTableEntry.ConstructRowKey(grainRef, reminderName),
                ETag         = eTag,
            };

            try
            {
                if (logger.IsEnabled(LogLevel.Trace))
                {
                    logger.Trace("RemoveRow entry = {0}", entry.ToString());
                }

                bool result = await remTableManager.DeleteReminderEntryConditionally(entry, eTag);

                if (result == false)
                {
                    logger.Warn((int)AzureUtils.Utilities.ErrorCode.AzureTable_43,
                                $"Delete failed on the reminder table. Will retry. Entry = {entry}");
                }
                return(result);
            }
            catch (Exception exc)
            {
                logger.Warn((int)AzureUtils.Utilities.ErrorCode.AzureTable_44,
                            $"Intermediate error when deleting reminder entry {entry} to the table {remTableManager.TableName}.", exc);
                throw;
            }
        }
Esempio n. 4
0
        public async Task <string> UpsertRow(ReminderEntry entry)
        {
            try
            {
                if (logger.IsEnabled(LogLevel.Debug))
                {
                    logger.Debug("UpsertRow entry = {0}", entry.ToString());
                }
                ReminderTableEntry remTableEntry = ConvertToTableEntry(entry, remTableManager.ServiceId, remTableManager.DeploymentId);

                string result = await remTableManager.UpsertRow(remTableEntry);

                if (result == null)
                {
                    logger.Warn((int)AzureUtils.Utilities.ErrorCode.AzureTable_45,
                                $"Upsert failed on the reminder table. Will retry. Entry = {entry.ToString()}");
                }
                return(result);
            }
            catch (Exception exc)
            {
                logger.Warn((int)AzureUtils.Utilities.ErrorCode.AzureTable_42,
                            $"Intermediate error upserting reminder entry {entry.ToString()} to the table {remTableManager.TableName}.", exc);
                throw;
            }
        }
Esempio n. 5
0
        public async Task <bool> RemoveRow(GrainReference grainRef, string reminderName, string eTag)
        {
            var entry = new ReminderTableEntry
            {
                PartitionKey = ReminderTableEntry.ConstructPartitionKey(remTableManager.ServiceId, grainRef),
                RowKey       = ReminderTableEntry.ConstructRowKey(grainRef, reminderName),
                ETag         = eTag,
            };

            try
            {
                if (logger.IsVerbose2)
                {
                    logger.Verbose2("RemoveRow entry = {0}", entry.ToString());
                }

                bool result = await remTableManager.DeleteReminderEntryConditionally(entry, eTag);

                if (result == false)
                {
                    logger.Warn(ErrorCode.AzureTable_43, String.Format("Delete failed on the reminder table. Will retry. Entry = {0}", entry));
                }
                return(result);
            }
            catch (Exception exc)
            {
                logger.Warn(ErrorCode.AzureTable_44, String.Format("Intermediate error when deleting reminder entry {0} to the table {1}.",
                                                                   entry, remTableManager.TableName), exc);
                throw;
            }
        }
Esempio n. 6
0
        public async Task <string> UpsertRow(ReminderEntry entry)
        {
            try
            {
                if (logger.IsVerbose)
                {
                    logger.Verbose("UpsertRow entry = {0}", entry.ToString());
                }
                ReminderTableEntry remTableEntry = ConvertToTableEntry(entry, remTableManager.ServiceId, remTableManager.DeploymentId);

                string result = await remTableManager.UpsertRow(remTableEntry);

                if (result == null)
                {
                    logger.Warn(ErrorCode.AzureTable_45, String.Format("Upsert failed on the reminder table. Will retry. Entry = {0}", entry.ToString()));
                }
                return(result);
            }
            catch (Exception exc)
            {
                logger.Warn(ErrorCode.AzureTable_42, String.Format("Intermediate error upserting reminder entry {0} to the table {1}.",
                                                                   entry.ToString(), remTableManager.TableName), exc);
                throw;
            }
        }
Esempio n. 7
0
 private ReminderEntry ConvertFromTableEntry(ReminderTableEntry tableEntry, string eTag)
 {
     try
     {
         return(new ReminderEntry
         {
             GrainRef = GrainReference.FromKeyString(tableEntry.GrainReference),
             ReminderName = tableEntry.ReminderName,
             StartAt = TraceLogger.ParseDate(tableEntry.StartAt),
             Period = TimeSpan.Parse(tableEntry.Period),
             ETag = eTag,
         });
     }
     catch (Exception exc)
     {
         var error = String.Format("Failed to parse ReminderTableEntry: {0}. This entry is corrupt, going to ignore it.",
                                   tableEntry);
         logger.Error(ErrorCode.AzureTable_49, error, exc);
         throw;
     }
     finally
     {
         string serviceIdStr = ReminderTableEntry.ConstructServiceIdStr(remTableManager.ServiceId);
         if (!tableEntry.ServiceId.Equals(serviceIdStr))
         {
             var error = String.Format("Read a reminder entry for wrong Service id. Read {0}, but my service id is {1}. Going to discard it.",
                                       tableEntry, serviceIdStr);
             logger.Warn(ErrorCode.AzureTable_ReadWrongReminder, error);
             throw new ApplicationException(error);
         }
     }
 }