/// <summary>
        /// Pings all servers to obtain their round-trips times and their high timestamps.
        /// </summary>
        public void PingTimestampsNow()
        {
            Stopwatch watch = new Stopwatch();

            foreach (string server in configuration.SecondaryServers)
            {
                // if the server is not reached yet, we perform a dummy operation for it.
                if (!replicas[server].IsContacted())
                {
                    try
                    {
                        //we perform a dummy operation to get the rtt latency!
                        DateTimeOffset?serverTime = null;
                        long           rtt;
                        if (server.EndsWith("-secondary") && configuration.PrimaryServers.Contains(server.Replace("-secondary", "")))
                        {
                            // get the server's last sync time from Azure
                            // this call only works on Azure secondaries
                            CloudBlobClient blobClient = ClientRegistry.GetCloudBlobClient(server);
                            watch.Restart();
                            ServiceStats stats = blobClient.GetServiceStats();
                            rtt = watch.ElapsedMilliseconds;
                            replicas[server].AddRtt(rtt);
                            if (stats.GeoReplication.LastSyncTime.HasValue)
                            {
                                serverTime = stats.GeoReplication.LastSyncTime.Value;
                            }
                        }
                        else
                        {
                            // get the server's last sync time from the container's metadata
                            CloudBlobContainer blobContainer = ClientRegistry.GetCloudBlobContainer(server, configuration.Name);
                            watch.Restart();
                            blobContainer.FetchAttributes();
                            rtt = watch.ElapsedMilliseconds;
                            if (blobContainer.Metadata.ContainsKey("lastsync"))
                            {
                                //if no lastmodified time is provided in the constructor, we still try to be fast.
                                //So, we check to see if by any chance the container previously has synchronized.
                                serverTime = DateTimeOffset.Parse(blobContainer.Metadata["lastsync"]);
                            }
                        }
                        if (serverTime.HasValue && serverTime > replicas[server].HighTime)
                        {
                            replicas[server].HighTime = serverTime.Value;
                        }
                    }
                    catch (StorageException)
                    {
                        // do nothing
                    }
                }
            }
        }
        /// <summary>
        /// Pings all servers to obtain their round-trips times and their high timestamps.
        /// </summary>
        public void PingNow()
        {
            Stopwatch watch = new Stopwatch();

            foreach (string server in replicas.Keys)
            {
                // if the server is not reached yet, we perform a dummy operation for it.
                if (!replicas[server].IsContacted())
                {
                    //we perform a dummy operation to get the rtt latency!
                    CloudBlobClient blobClient = ClientRegistry.GetCloudBlobClient(server);
                    long            rtt;
                    watch.Restart();
                    blobClient.GetServiceProperties();
                    rtt = watch.ElapsedMilliseconds;
                    replicas[server].AddRtt(rtt);
                }
            }
        }
Example #3
0
        public static void PingAllServers()
        {
            List <string> allServers = config.GetServers();
            Stopwatch     watch      = new Stopwatch();

            for (int pingCount = 0; pingCount < 5; pingCount++)
            {
                foreach (string server in allServers)
                {
                    CloudBlobClient blobClient = ClientRegistry.GetCloudBlobClient(server);
                    if (blobClient != null)
                    {
                        CloudBlobContainer blobContainer = blobClient.GetContainerReference(containerName);
                        //Log("Pinging " + SiteName(server) + " aka " + server + "...");
                        watch.Restart();
                        //we perform a dummy operation to get the rtt latency!
                        try
                        {
                            bool ok = blobContainer.Exists();
                        }
                        catch (StorageException se)
                        {
                            Log("Storage exception when pinging " + SiteName(server) + ": " + se.Message);
                        }
                        long        el = watch.ElapsedMilliseconds;
                        ServerState ss = container.Monitor.GetServerState(server);
                        ss.AddRtt(el);
                        //Log("Pinged " + SiteName(server) + " in " + el + " milliseconds");
                    }
                    else
                    {
                        Log("Failed to ping " + SiteName(server));
                    }
                }
            }
        }