/// <summary>
 /// Creates a configuration.
 /// </summary>
 /// <param name="name">name of the replicated collection</param>
 public ReplicaConfiguration(string name, List <string> primaries, List <string> secondaries, List <string> nonreplicas = null, List <string> readonlyReplicas = null, bool isCloudBacked = true, bool isStable = false)
     : this(name)
 {
     // set local configuration
     if (primaries != null)
     {
         PrimaryServers = primaries.ToList();
     }
     if (secondaries != null)
     {
         SecondaryServers = secondaries.ToList();
     }
     if (nonreplicas != null)
     {
         NonReplicaServers = nonreplicas.ToList();
     }
     if (readonlyReplicas != null)
     {
         ReadOnlySecondaryServers = readonlyReplicas.ToList();
     }
     this.isStable = isStable;
     if (isCloudBacked)
     {
         // get configuration from cloud (or write configuration to cloud if it does not exist)
         bool autoRefresh = (!isStable);
         SyncWithCloud(ClientRegistry.GetConfigurationAccount(), autoRefresh);
     }
 }
Exemple #2
0
        /// <summary>
        /// Periodically uploads SLAs and SessionStates.
        /// SLAs and SessionStates are stored in two Azure tables called.
        /// </summary>
        public void StartUploadConfigurationTask(string containerName, List <ConsistencySLAEngine> engines, SessionState sessionState, ServerMonitor monitor)
        {
            activeUploaders[containerName] = true;
            int                  sleepDuration = 0;
            int                  epoch;
            DateTimeOffset       lastModified;
            ReplicaConfiguration configuration = ClientRegistry.GetConfiguration(containerName, false);

            if (configuration == null)
            {
                activeUploaders[containerName] = false;
            }

            while (activeUploaders[containerName])
            {
                try
                {
                    configuration.SyncWithCloud(ClientRegistry.GetConfigurationAccount());

                    while (!configuration.IsInFastMode())
                    {
                        lock (configuration)
                            Monitor.Wait(configuration, 1000);
                    }

                    epoch = configuration.Epoch;
                    Console.WriteLine("Uploading SLA and SessionState with Epoch: " + epoch);
                    lastModified = configuration.EpochModifiedTime;

                    //    |====a====|-conf in progress-|====b====|
                    //Clients upload their configurations between the middle of a configuration period, and before a configuration epoch is finished.
                    //I.e., after for example a, and before the first next bar, or after b, and before the next upcomming bar.
                    if (DateTimeOffset.Now.Subtract(lastModified).TotalMilliseconds > ConstPool.CONFIGURATION_UPLOAD_INTERVAL / 2)
                    {
                        UploadClientData(containerName, epoch, engines, sessionState, monitor);
                        //Console.WriteLine("Uploaded the configuration to the azure storage. ...");
                        sleepDuration = ConstPool.CONFIGURATION_UPLOAD_INTERVAL;
                    }
                    else
                    {
                        //we try to push the upload to some time after the middle of an epoch duration.
                        sleepDuration = (ConstPool.CONFIGURATION_UPLOAD_INTERVAL / 2) - DateTimeOffset.Now.Subtract(lastModified).Milliseconds;
                    }
                    Thread.Sleep(sleepDuration);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                    throw ex;
                }
            }
        }