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 OrleansException(error); } } }
internal static Tuple <MembershipEntry, int> GetMembershipEntry(IDataRecord record) { //TODO: This is a bit of hack way to check in the current version if there's membership data or not, but if there's a start time, there's member. DateTime? startTime = record.GetValueOrDefault <DateTime?>(nameof(Columns.StartTime)); MembershipEntry entry = null; if (startTime.HasValue) { entry = new MembershipEntry { SiloAddress = GetSiloAddress(record, nameof(Columns.Port)), HostName = record.GetValue <string>(nameof(Columns.HostName)), Status = record.GetValue <SiloStatus>(nameof(Columns.Status)), ProxyPort = record.GetValue <int>(nameof(Columns.ProxyPort)), StartTime = startTime.Value, IAmAliveTime = record.GetValue <DateTime>(nameof(Columns.IAmAliveTime)) }; string suspectingSilos = record.GetValueOrDefault <string>(nameof(Columns.SuspectTimes)); if (!string.IsNullOrWhiteSpace(suspectingSilos)) { entry.SuspectTimes = new List <Tuple <SiloAddress, DateTime> >(); entry.SuspectTimes.AddRange(suspectingSilos.Split('|').Select(s => { var split = s.Split(','); return(new Tuple <SiloAddress, DateTime>(SiloAddress.FromParsableString(split[0]), TraceLogger.ParseDate(split[1]))); })); } } return(Tuple.Create(entry, GetVersion(record))); }
private static MembershipEntry Parse(SiloInstanceTableEntry tableEntry) { var parse = new MembershipEntry { HostName = tableEntry.HostName, Status = (SiloStatus)Enum.Parse(typeof(SiloStatus), tableEntry.Status) }; if (!string.IsNullOrEmpty(tableEntry.ProxyPort)) { parse.ProxyPort = int.Parse(tableEntry.ProxyPort); } parse.IsPrimary = false; // there are no primaries with in Azure table. int port = 0; if (!string.IsNullOrEmpty(tableEntry.Port)) { int.TryParse(tableEntry.Port, out port); } int gen = 0; if (!string.IsNullOrEmpty(tableEntry.Generation)) { int.TryParse(tableEntry.Generation, out gen); } parse.SiloAddress = SiloAddress.New(new IPEndPoint(IPAddress.Parse(tableEntry.Address), port), gen); parse.RoleName = tableEntry.RoleName; parse.InstanceName = tableEntry.InstanceName; if (!string.IsNullOrEmpty(tableEntry.UpdateZone)) { parse.UpdateZone = int.Parse(tableEntry.UpdateZone); } if (!string.IsNullOrEmpty(tableEntry.FaultZone)) { parse.FaultZone = int.Parse(tableEntry.FaultZone); } parse.StartTime = !string.IsNullOrEmpty(tableEntry.StartTime) ? TraceLogger.ParseDate(tableEntry.StartTime) : default(DateTime); parse.IAmAliveTime = !string.IsNullOrEmpty(tableEntry.IAmAliveTime) ? TraceLogger.ParseDate(tableEntry.IAmAliveTime) : default(DateTime); var suspectingSilos = new List <SiloAddress>(); var suspectingTimes = new List <DateTime>(); if (!string.IsNullOrEmpty(tableEntry.SuspectingSilos)) { string[] silos = tableEntry.SuspectingSilos.Split('|'); foreach (string silo in silos) { suspectingSilos.Add(SiloAddress.FromParsableString(silo)); } } if (!string.IsNullOrEmpty(tableEntry.SuspectingTimes)) { string[] times = tableEntry.SuspectingTimes.Split('|'); foreach (string time in times) { suspectingTimes.Add(TraceLogger.ParseDate(time)); } } if (suspectingSilos.Count != suspectingTimes.Count) { throw new OrleansException(String.Format("SuspectingSilos.Length of {0} as read from Azure table is not eqaul to SuspectingTimes.Length of {1}", suspectingSilos.Count, suspectingTimes.Count)); } for (int i = 0; i < suspectingSilos.Count; i++) { parse.AddSuspector(suspectingSilos[i], suspectingTimes[i]); } return(parse); }
private static MembershipEntry ConvertFromRow(SqlDataReader results, out string eTag, out int tableVersion, out string versionETag) { var entry = new MembershipEntry(); int port = results.GetInt32(PortIdx); int gen = results.GetInt32(GenerationIdx); entry.SiloAddress = SiloAddress.New(new IPEndPoint(IPAddress.Parse(results.GetString(AddressIdx)), port), gen); entry.HostName = results.GetString(HostNameIdx); entry.Status = (SiloStatus)results.GetInt32(StatusIdx); if (!results.GetSqlInt32(ProxyPortIdx).IsNull) { entry.ProxyPort = results.GetInt32(ProxyPortIdx); } if (!results.GetSqlBoolean(PrimaryIdx).IsNull) { entry.IsPrimary = results.GetBoolean(PrimaryIdx); } entry.RoleName = results.GetString(RoleNameIdx); entry.InstanceName = results.GetString(InstanceNameIdx); if (!results.GetSqlInt32(UpdateZoneIdx).IsNull) { entry.UpdateZone = results.GetInt32(UpdateZoneIdx); } if (!results.GetSqlInt32(FaultZoneIdx).IsNull) { entry.FaultZone = results.GetInt32(FaultZoneIdx); } if (!results.GetSqlDateTime(StartTimeIdx).IsNull) { entry.StartTime = results.GetDateTime(StartTimeIdx); } if (!results.GetSqlDateTime(IAmAliveTimeIdx).IsNull) { entry.IAmAliveTime = results.GetDateTime(IAmAliveTimeIdx); } eTag = results.GetString(ETagIdx); tableVersion = (int)results.GetInt64(VersionIdx); versionETag = results.GetString(VersionETagIdx); var suspectingSilosString = results.GetSqlString(SuspectingSilosIdx); var suspectingTimesString = results.GetSqlString(SuspectingTimesIdx); List <SiloAddress> suspectingSilos = new List <SiloAddress>(); List <DateTime> suspectingTimes = new List <DateTime>(); if (!suspectingSilosString.IsNull && !string.IsNullOrEmpty(suspectingSilosString.Value)) { string[] silos = suspectingSilosString.Value.Split('|'); foreach (string silo in silos) { suspectingSilos.Add(SiloAddress.FromParsableString(silo)); } } if (!suspectingTimesString.IsNull && !string.IsNullOrEmpty(suspectingTimesString.Value)) { string[] times = suspectingTimesString.Value.Split('|'); foreach (string time in times) { suspectingTimes.Add(TraceLogger.ParseDate(time)); } } if (suspectingSilos.Count != suspectingTimes.Count) { throw new OrleansException(String.Format("SuspectingSilos.Length of {0} as read from SQL table is not eqaul to SuspectingTimes.Length of {1}", suspectingSilos.Count, suspectingTimes.Count)); } for (int i = 0; i < suspectingSilos.Count; i++) { entry.AddSuspector(suspectingSilos[i], suspectingTimes[i]); } return(entry); }