Ejemplo n.º 1
0
        //public Microsoft.WindowsAzure.Storage.ICancellableAsyncResult BeginUploadFromStream(System.IO.Stream source, AsyncCallback callback, object state)
        //{
        //    return strongBlob.BeginUploadFromStream(source, callback, state);
        //}

        //public Microsoft.WindowsAzure.Storage.ICancellableAsyncResult BeginUploadFromStream(System.IO.Stream source, Microsoft.WindowsAzure.Storage.AccessCondition accessCondition, Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions options, Microsoft.WindowsAzure.Storage.OperationContext operationContext, AsyncCallback callback, object state)
        //{
        //    return strongBlob.BeginUploadFromStream(source, accessCondition, options, operationContext, callback, state);
        //}

        //public void EndUploadFromStream(IAsyncResult asyncResult)
        //{
        //    strongBlob.EndUploadFromStream(asyncResult);
        //    slaEngine.SessionState.RecordObjectWritten(strongBlob.Name, Timestamp(strongBlob), primaryServer);
        //}

        //public Microsoft.WindowsAzure.Storage.ICancellableAsyncResult BeginDownloadToStream(System.IO.Stream target, AsyncCallback callback, object state)
        //{
        //    // TODO: Use SLA to decide from which server to download.
        //    return strongBlob.BeginDownloadToStream(target, callback, state);
        //}

        //public Microsoft.WindowsAzure.Storage.ICancellableAsyncResult BeginDownloadToStream(System.IO.Stream target, Microsoft.WindowsAzure.Storage.AccessCondition accessCondition, Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions options, Microsoft.WindowsAzure.Storage.OperationContext operationContext, AsyncCallback callback, object state)
        //{
        //    return strongBlob.BeginDownloadToStream(target, accessCondition, options, operationContext, callback, state);
        //}

        //public void EndDownloadToStream(IAsyncResult asyncResult)
        //{
        //    strongBlob.EndDownloadToStream(asyncResult);
        //    slaEngine.SessionState.RecordObjectRead(strongBlob.Name, Timestamp(strongBlob), primaryServer);
        //}

        //public Microsoft.WindowsAzure.Storage.ICancellableAsyncResult BeginDownloadRangeToStream(System.IO.Stream target, long? offset, long? length, AsyncCallback callback, object state)
        //{
        //    return strongBlob.BeginDownloadRangeToStream(target, offset, length, callback, state);
        //}

        //public Microsoft.WindowsAzure.Storage.ICancellableAsyncResult BeginDownloadRangeToStream(System.IO.Stream target, long? offset, long? length, Microsoft.WindowsAzure.Storage.AccessCondition accessCondition, Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions options, Microsoft.WindowsAzure.Storage.OperationContext operationContext, AsyncCallback callback, object state)
        //{
        //    return strongBlob.BeginDownloadRangeToStream(target, offset, length, accessCondition, options, operationContext, callback, state);
        //}

        //public void EndDownloadRangeToStream(IAsyncResult asyncResult)
        //{
        //    strongBlob.EndDownloadRangeToStream(asyncResult);
        //    slaEngine.SessionState.RecordObjectRead(strongBlob.Name, Timestamp(strongBlob), primaryServer);
        //}

        //public Microsoft.WindowsAzure.Storage.ICancellableAsyncResult BeginExists(AsyncCallback callback, object state)
        //{
        //    return strongBlob.BeginExists(callback, state);
        //}

        //public Microsoft.WindowsAzure.Storage.ICancellableAsyncResult BeginExists(Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions options, Microsoft.WindowsAzure.Storage.OperationContext operationContext, AsyncCallback callback, object state)
        //{
        //    return strongBlob.BeginExists(options, operationContext, callback, state);
        //}

        //public bool EndExists(IAsyncResult asyncResult)
        //{
        //    bool result = strongBlob.EndExists(asyncResult);
        //    slaEngine.SessionState.RecordObjectRead(strongBlob.Name, Timestamp(strongBlob), primaryServer);
        //    return result;
        //}

        //public Microsoft.WindowsAzure.Storage.ICancellableAsyncResult BeginFetchAttributes(AsyncCallback callback, object state)
        //{
        //    return strongBlob.BeginFetchAttributes(callback, state);
        //}

        //public Microsoft.WindowsAzure.Storage.ICancellableAsyncResult BeginFetchAttributes(Microsoft.WindowsAzure.Storage.AccessCondition accessCondition, Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions options, Microsoft.WindowsAzure.Storage.OperationContext operationContext, AsyncCallback callback, object state)
        //{
        //    return strongBlob.BeginFetchAttributes(accessCondition, options, operationContext, callback, state);
        //}

        //public void EndFetchAttributes(IAsyncResult asyncResult)
        //{
        //    strongBlob.EndFetchAttributes(asyncResult);
        //    slaEngine.SessionState.RecordObjectRead(strongBlob.Name, Timestamp(strongBlob), primaryServer);
        //}

        //public void SetMetadata(Microsoft.WindowsAzure.Storage.AccessCondition accessCondition = null, Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions options = null, Microsoft.WindowsAzure.Storage.OperationContext operationContext = null)
        //{
        //    watch.Start();
        //    strongBlob.SetMetadata(accessCondition, options, operationContext);
        //    primaryServer.AddRtt(watch.ElapsedMilliseconds);
        //    slaEngine.SessionState.RecordObjectWritten(strongBlob.Name, Timestamp(strongBlob), primaryServer);
        //}

        //public Microsoft.WindowsAzure.Storage.ICancellableAsyncResult BeginSetMetadata(AsyncCallback callback, object state)
        //{
        //    return strongBlob.BeginSetMetadata(callback, state);
        //}

        //public Microsoft.WindowsAzure.Storage.ICancellableAsyncResult BeginSetMetadata(Microsoft.WindowsAzure.Storage.AccessCondition accessCondition, Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions options, Microsoft.WindowsAzure.Storage.OperationContext operationContext, AsyncCallback callback, object state)
        //{
        //    return strongBlob.BeginSetMetadata(accessCondition, options, operationContext, callback, state);
        //}

        //public void EndSetMetadata(IAsyncResult asyncResult)
        //{
        //    strongBlob.EndSetMetadata(asyncResult);
        //    slaEngine.SessionState.RecordObjectWritten(strongBlob.Name, Timestamp(strongBlob), primaryServer);
        //}

        //public void SetProperties(Microsoft.WindowsAzure.Storage.AccessCondition accessCondition = null, Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions options = null, Microsoft.WindowsAzure.Storage.OperationContext operationContext = null)
        //{
        //    watch.Start();
        //    strongBlob.SetProperties(accessCondition, options, operationContext);
        //    primaryServer.AddRtt(watch.ElapsedMilliseconds);
        //    slaEngine.SessionState.RecordObjectWritten(strongBlob.Name, Timestamp(strongBlob), primaryServer);
        //}

        //public Microsoft.WindowsAzure.Storage.ICancellableAsyncResult BeginSetProperties(AsyncCallback callback, object state)
        //{
        //    return strongBlob.BeginSetProperties(callback, state);
        //}

        //public Microsoft.WindowsAzure.Storage.ICancellableAsyncResult BeginSetProperties(Microsoft.WindowsAzure.Storage.AccessCondition accessCondition, Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions options, Microsoft.WindowsAzure.Storage.OperationContext operationContext, AsyncCallback callback, object state)
        //{
        //    return strongBlob.BeginSetProperties(accessCondition, options, operationContext, callback, state);
        //}

        //public void EndSetProperties(IAsyncResult asyncResult)
        //{
        //    strongBlob.EndSetProperties(asyncResult);
        //    slaEngine.SessionState.RecordObjectWritten(strongBlob.Name, Timestamp(strongBlob), primaryServer);
        //}

        public void Delete(Microsoft.WindowsAzure.Storage.Blob.DeleteSnapshotsOption deleteSnapshotsOption = DeleteSnapshotsOption.None, Microsoft.WindowsAzure.Storage.AccessCondition accessCondition = null, Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions options = null, Microsoft.WindowsAzure.Storage.OperationContext operationContext = null)
        {
            bool isDone = false;

            do
            {
                try
                {
                    if (configuration.IsInFastMode())
                    {
                        DoDelete(deleteSnapshotsOption, accessCondition, options, operationContext);
                        isDone = true;
                    }
                    else
                    {
                        //We are not sure if reconfiguration is happening or not. We execute put in slow mode.
                        using (CloudBlobLease lease = new CloudBlobLease(configuration.Name, LeaseTakingPolicy.TryOnce))
                        {
                            if (lease.HasLease)
                            {
                                configuration.SyncWithCloud(ClientRegistry.GetConfigurationAccount());
                                DoDelete(deleteSnapshotsOption, accessCondition, options, operationContext);
                                isDone = true;
                            }
                        }
                    }
                }
                catch (StorageException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            } while (!isDone);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Perform read optimistically and then verify configuration.
        /// </summary>
        /// <param name="op">The read operation</param>
        /// <param name="blob">The blob being read</param>
        /// <param name="ss">The chosen server</param>
        /// <returns>whether the read succeeded; if not, then it should be tried again.</returns>
        private void SlowRead(ReadOp op)
        {
            // TODO: Deal with the case that we try to read from a replica that is no longer a replica and the read fails
            // In this case, the read should be retried after refreshing the configuration.
            ServerState ss = null;

            try
            {
                bool isDone = false;
                do  // until we enter fast mode or succeed at reading in slow mode with the correct configuration
                {
                    ss          = slaEngine.FindServerToRead(blobName);
                    blobForRead = ClientRegistry.GetCloudBlob(ss.Name, containerName, blobName);

                    // TODO: this should really check if the reader wants strong consistency
                    // It could be that eventual consistency is fine but the SLA Engine just happened to choose a primary server
                    // In this case, we can do a fast mode read since we don't care if the chosen server is no longer a primary
                    if (configuration.IsInFastMode() || !configuration.PrimaryServers.Contains(ss.Name))
                    {
                        // it is fine to read from the selected secondary replica
                        // or from a primary replica if we have now entered fast mode
                        FastRead(op);
                        isDone = true;
                    }
                    else
                    {
                        // read from the selected replica that we believe to be a primary replica
                        watch.Start();
                        op(blobForRead);
                        watch.Stop();

                        // then see if the configuration has changed and the selected replica is no longer primary
                        configuration.SyncWithCloud(ClientRegistry.GetConfigurationAccount());

                        // TODO: check the epoch number on the configuration to make sure that we have not missed a configuration.
                        // i.e. we need to make sure that the server from which we read did not become a secondary during our read,
                        // and then back to primary when we checked.
                        // TODO: maybe we should check that the read delivered a non-zero utility.
                        // It is possible that the configuration was so stale that a much better server could have been chosen.
                        if (configuration.PrimaryServers.Contains(ss.Name))
                        {
                            //We have contacted the primary replica, hence we are good to go.
                            slaEngine.RecordObjectRead(blobForRead.Name, Timestamp(blobForRead), ss, watch.ElapsedMilliseconds);
                            isDone = true;
                        }
                        isDone = false;  // not done
                    }
                } while (!isDone);
            }
            // TODO: decide if we need to catch any exceptions here or just let then propagate through
            catch (StorageException se)
            {
                if (StorageExceptionCode.NotFound(se))
                {
                    //blob is not found.
                    //this is fine because the replica might have removed.
                    //it simply returns, so client need to re-execute if this happens.
                    //We can also re-execute the read here, but for debugging purposes, it's simpler for the client to re-execute.
                    //Of course in real system, we need to re-execute at this level.
                    return;
                }
                // storage exceptions are passed through to the caller
                throw;
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Object reference not set to an instance of an object"))
                {
                    return;
                }
                throw ex;
            }
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            Console.CancelKeyPress += new ConsoleCancelEventHandler(Cancelled);

            if (args.Length == 0)
            {
                args = new string[7];

                //storage account locating configuration of given container
                args[0] = "dbtsouthstorage"; // "devstoreaccount1";

                // container name
                args[1] = "testcontainer";

                // the result folder name
                args[2] = "folder1";

                //sleep time between ticks in milliseconds.
                args[3] = "90000";

                //interval between configuration
                args[4] = "2";

                //duration of experiment in ticks
                args[5] = "24";

                //start tick for configuration
                args[6] = "1";
            }

            configurationSite    = args[0];
            containerName        = args[1];
            resultFileFolderName = args[2];

            sleepTimeBetweenTicks      = Int32.Parse(args[3]);
            ticksBetweenConfigurations = Int32.Parse(args[4]);
            experimentDurationInTicks  = Int32.Parse(args[5]);
            startTickOfConfiguration   = Int32.Parse(args[6]);

            Dictionary <string, CloudStorageAccount> acounts = Account.GetStorageAccounts(true);

            acounts.Remove("devstoreaccount1");
            ClientRegistry.Init(acounts, Account.GetStorageAccounts(true)[configurationSite]);
            ReplicaConfiguration configuration = ClientRegistry.GetConfiguration(containerName, false);

            Configurator conf = new Configurator(containerName);


            #region replicator
            Replicator replicator = new Replicator(containerName);
            replicator.Start();
            #endregion

            #region configurator

            List <ConfigurationConstraint> constraints = new List <ConfigurationConstraint>();
            //constraints.Add(new LocationConstraint(containerName, "dbteastasiastorage", LocationConstraintType.Replicate));
            constraints.Add(new ReplicationFactorConstraint(containerName, configuration, 1, 2));

            DateTime startTime = DateTime.Now;
            Thread.Sleep(startTickOfConfiguration * sleepTimeBetweenTicks);
            while (DateTime.Now.Subtract(startTime).TotalMilliseconds < (experimentDurationInTicks * sleepTimeBetweenTicks))
            {
                try
                {
                    configuration = ClientRegistry.GetConfiguration(containerName, false);
                    Console.WriteLine("Starting to reconfigure. Current Epoch: " + configuration.Epoch);
                    conf.Configure(ClientRegistry.GetConfigurationAccount(), configuration.Epoch, configuration, constraints);
                    Console.WriteLine(Configurator.Logs);
                    Console.WriteLine(">>>>>>>>>>> Finished. Current Epoch: " + configuration.Epoch + "<<<<<<<<<<<<<<<<");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                Thread.Sleep(ticksBetweenConfigurations * sleepTimeBetweenTicks);
            }

            #endregion

            return;
        }