Example #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);
         }
     }
 }
            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)),
                        SiloName     = TryGetSiloName(record),
                        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]),
                                                                     LogFormatter.ParseDate(split[1])));
                        }));
                    }
                }

                return(Tuple.Create(entry, GetVersion(record)));
            }
Example #3
0
        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);
        }
Example #4
0
        private static MembershipEntry ParseEntity(SiloEntity entity)
        {
            var entry = new MembershipEntry
            {
                HostName = entity.Hostname,
                Status   = entity.Status
            };

            if (entity.ProxyPort.HasValue)
            {
                entry.ProxyPort = entity.ProxyPort.Value;
            }

            entry.SiloAddress = SiloAddress.New(new IPEndPoint(IPAddress.Parse(entity.Address), entity.Port), entity.Generation);

            entry.SiloName = entity.SiloName;

            entry.StartTime = entity.StartTime.UtcDateTime;

            entry.IAmAliveTime = entity.IAmAliveTime.UtcDateTime;

            var suspectingSilos = new List <SiloAddress>();
            var suspectingTimes = new List <DateTime>();

            foreach (var silo in entity.SuspectingSilos)
            {
                suspectingSilos.Add(SiloAddress.FromParsableString(silo));
            }

            foreach (var time in entity.SuspectingTimes)
            {
                suspectingTimes.Add(LogFormatter.ParseDate(time));
            }

            if (suspectingSilos.Count != suspectingTimes.Count)
            {
                throw new OrleansException($"SuspectingSilos.Length of {suspectingSilos.Count} as read from Kubernetes is not equal to SuspectingTimes.Length of {suspectingTimes.Count}");
            }

            for (int i = 0; i < suspectingSilos.Count; i++)
            {
                entry.AddSuspector(suspectingSilos[i], suspectingTimes[i]);
            }

            return(entry);
        }
 public MembershipEntry ToEntry()
 {
     return(new MembershipEntry
     {
         FaultZone = FaultZone,
         HostName = HostName,
         IAmAliveTime = LogFormatter.ParseDate(IAmAliveTime),
         ProxyPort = ProxyPort,
         RoleName = RoleName,
         SiloAddress = SiloAddressClass.FromParsableString(SiloAddress),
         SiloName = SiloName,
         Status = (SiloStatus)Status,
         StartTime = LogFormatter.ParseDate(StartTime),
         SuspectTimes = SuspectTimes.Select(x => x.ToTuple()).ToList(),
         UpdateZone = UpdateZone
     });
 }
Example #6
0
        /// <summary>
        /// Parses the MembershipData to a MembershipEntry
        /// </summary>
        /// <param name="membershipData">
        /// The membership data.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        internal async Task <Tuple <MembershipEntry, string> > Parse(MembershipCollection membershipData)
        {
            // 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 = membershipData.StartTime;
            MembershipEntry entry     = null;

            if (startTime.HasValue)
            {
                entry = new MembershipEntry
                {
                    SiloAddress = ReturnSiloAddress(membershipData),

                    // SiloName = TryGetSiloName(record),
                    HostName     = membershipData.HostName,
                    Status       = (SiloStatus)membershipData.Status,
                    ProxyPort    = membershipData.ProxyPort,
                    StartTime    = startTime.Value,
                    IAmAliveTime = membershipData.IAmAliveTime,
                    SiloName     = membershipData.HostName
                };

                string suspectingSilos = membershipData.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].Trim()),
                                   LogFormatter.ParseDate(split[1].Trim())));
                    }));
                }
            }

            BsonDocument membershipVersionDocument =
                await
                this.FindDocumentAsync(
                    MembershipVersionCollectionName,
                    MembershipVersionKeyName,
                    membershipData.DeploymentId);

            return(Tuple.Create(entry, membershipVersionDocument["Version"].AsInt32.ToString()));
        }
Example #7
0
        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);
            }

            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;
            if (!string.IsNullOrEmpty(tableEntry.SiloName))
            {
                parse.SiloName = tableEntry.SiloName;
            }
            else if (!string.IsNullOrEmpty(tableEntry.InstanceName))
            {
                // this is for backward compatability: in a mixed cluster of old and new version,
                // some entries will have the old InstanceName column.
                parse.SiloName = 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) ?
                              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 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);
        }
 public Tuple <SiloAddress, DateTime> ToTuple()
 {
     return(Tuple.Create(SiloAddress.FromParsableString(Address), LogFormatter.ParseDate(IAmAliveTime)));
 }
        MembershipEntry GetMembershipEntry(Row row, SiloAddress forAddress = null)
        {
            if (row["start_time"] == null)
            {
                return(null);
            }

            var result = new MembershipEntry
            {
                SiloAddress  = forAddress ?? SiloAddress.New(new IPEndPoint(IPAddress.Parse((string)row["address"]), (int)row["port"]), (int)row["generation"]),
                SiloName     = (string)row["silo_name"],
                HostName     = (string)row["host_name"],
                Status       = (SiloStatus)(int)row["status"],
                ProxyPort    = (int)row["proxy_port"],
                StartTime    = ((DateTimeOffset)row["start_time"]).UtcDateTime,
                IAmAliveTime = ((DateTimeOffset)row["i_am_alive_time"]).UtcDateTime
            };

            var suspectingSilos = (string)row["suspect_times"];

            if (!string.IsNullOrWhiteSpace(suspectingSilos))
            {
                result.SuspectTimes = new List <Tuple <SiloAddress, DateTime> >();
                result.SuspectTimes.AddRange(suspectingSilos.Split('|').Select(s =>
                {
                    var split = s.Split(',');
                    return(new Tuple <SiloAddress, DateTime>(SiloAddress.FromParsableString(split[0]), LogFormatter.ParseDate(split[1])));
                }));
            }

            return(result);
        }