private bool TryCreateTableVersionRecord(int version, string etag, out SiloInstanceRecord entry) { int etagInt; if (etag is null) { etagInt = 0; } else { if (!int.TryParse(etag, out etagInt)) { entry = default; return(false); } } entry = new SiloInstanceRecord { DeploymentId = clusterId, SiloIdentity = SiloInstanceRecord.TABLE_VERSION_ROW, MembershipVersion = version, ETag = etagInt }; return(true); }
private SiloInstanceRecord ConvertPartial(MembershipEntry memEntry) { return(new SiloInstanceRecord { DeploymentId = this.clusterId, IAmAliveTime = LogFormatter.PrintDate(memEntry.IAmAliveTime), SiloIdentity = SiloInstanceRecord.ConstructSiloIdentity(memEntry.SiloAddress) }); }
private MembershipEntry Parse(SiloInstanceRecord tableEntry) { var parse = new MembershipEntry { HostName = tableEntry.HostName, Status = (SiloStatus)tableEntry.Status }; parse.ProxyPort = tableEntry.ProxyPort; parse.SiloAddress = SiloAddress.New(new IPEndPoint(IPAddress.Parse(tableEntry.Address), tableEntry.Port), tableEntry.Generation); if (!string.IsNullOrEmpty(tableEntry.SiloName)) { parse.SiloName = tableEntry.SiloName; } parse.StartTime = !string.IsNullOrEmpty(tableEntry.StartTime) ? LogFormatter.ParseDate(tableEntry.StartTime) : default(DateTime); parse.IAmAliveTime = !string.IsNullOrEmpty(tableEntry.IAmAliveTime) ? LogFormatter.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(LogFormatter.ParseDate(time)); } } if (suspectingSilos.Count != suspectingTimes.Count) { throw new OrleansException(String.Format("SuspectingSilos.Length of {0} as read from Azure table is not equal 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); }
public void GetKeysTest() { SiloAddress address = SiloAddress.New(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 12345), 67890); var instanceRecord = new SiloInstanceRecord { DeploymentId = "deploymentID", SiloIdentity = SiloInstanceRecord.ConstructSiloIdentity(address) }; Dictionary <string, AttributeValue> keys = instanceRecord.GetKeys(); Assert.Equal(2, keys.Count); Assert.Equal(instanceRecord.DeploymentId, keys[SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME].S); Assert.Equal(instanceRecord.SiloIdentity, keys[SiloInstanceRecord.SILO_IDENTITY_PROPERTY_NAME].S); }
private SiloInstanceRecord Convert(MembershipEntry memEntry, TableVersion tableVersion) { var tableEntry = new SiloInstanceRecord { DeploymentId = this.clusterId, Address = memEntry.SiloAddress.Endpoint.Address.ToString(), Port = memEntry.SiloAddress.Endpoint.Port, Generation = memEntry.SiloAddress.Generation, HostName = memEntry.HostName, Status = (int)memEntry.Status, ProxyPort = memEntry.ProxyPort, SiloName = memEntry.SiloName, StartTime = LogFormatter.PrintDate(memEntry.StartTime), IAmAliveTime = LogFormatter.PrintDate(memEntry.IAmAliveTime), SiloIdentity = SiloInstanceRecord.ConstructSiloIdentity(memEntry.SiloAddress), MembershipVersion = tableVersion.Version }; if (memEntry.SuspectTimes != null) { var siloList = new StringBuilder(); var timeList = new StringBuilder(); bool first = true; foreach (var tuple in memEntry.SuspectTimes) { if (!first) { siloList.Append('|'); timeList.Append('|'); } siloList.Append(tuple.Item1.ToParsableString()); timeList.Append(LogFormatter.PrintDate(tuple.Item2)); first = false; } tableEntry.SuspectingSilos = siloList.ToString(); tableEntry.SuspectingTimes = timeList.ToString(); } else { tableEntry.SuspectingSilos = string.Empty; tableEntry.SuspectingTimes = string.Empty; } return(tableEntry); }
public async Task <MembershipTableData> ReadRow(SiloAddress siloAddress) { try { var keys = new Dictionary <string, AttributeValue> { { $"{SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME}", new AttributeValue(this.clusterId) }, { $"{SiloInstanceRecord.SILO_IDENTITY_PROPERTY_NAME}", new AttributeValue(SiloInstanceRecord.ConstructSiloIdentity(siloAddress)) } }; var entry = await storage.ReadSingleEntryAsync(this.options.TableName, keys, fields => new SiloInstanceRecord(fields)); MembershipTableData data = entry != null?Convert(new List <SiloInstanceRecord> { entry }) : new MembershipTableData(this.tableVersion); if (this.logger.IsEnabled(LogLevel.Trace)) { this.logger.Trace("Read my entry {0} Table=" + Environment.NewLine + "{1}", siloAddress.ToLongString(), data.ToString()); } return(data); } catch (Exception exc) { this.logger.Warn(ErrorCode.MembershipBase, $"Intermediate error reading silo entry for key {siloAddress.ToLongString()} from the table {this.options.TableName}.", exc); throw; } }
private static bool SiloIsDefunct(SiloInstanceRecord silo, DateTimeOffset beforeDate) { return(DateTimeOffset.TryParse(silo.IAmAliveTime, out var iAmAliveTime) && iAmAliveTime < beforeDate && silo.Status != (int)SiloStatus.Active); }
public async Task <MembershipTableData> ReadRow(SiloAddress siloAddress) { try { var siloEntryKeys = new Dictionary <string, AttributeValue> { { $"{SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME}", new AttributeValue(this.clusterId) }, { $"{SiloInstanceRecord.SILO_IDENTITY_PROPERTY_NAME}", new AttributeValue(SiloInstanceRecord.ConstructSiloIdentity(siloAddress)) } }; var versionEntryKeys = new Dictionary <string, AttributeValue> { { $"{SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME}", new AttributeValue(this.clusterId) }, { $"{SiloInstanceRecord.SILO_IDENTITY_PROPERTY_NAME}", new AttributeValue(SiloInstanceRecord.TABLE_VERSION_ROW) } }; var entries = await storage.GetEntriesTxAsync(this.options.TableName, new[] { siloEntryKeys, versionEntryKeys }, fields => new SiloInstanceRecord(fields)); MembershipTableData data = Convert(entries.ToList()); if (this.logger.IsEnabled(LogLevel.Trace)) { this.logger.LogTrace("Read my entry {SiloAddress} Table: {TableData}", siloAddress.ToLongString(), data.ToString()); } return(data); } catch (Exception exc) { this.logger.LogWarning( (int)ErrorCode.MembershipBase, exc, "Intermediate error reading silo entry for key {SiloAddress} from the table {TableName}", siloAddress.ToLongString(), this.options.TableName); throw; } }