private void DoDelete(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 done = false;

            while (!done)
            {
                using (PrimaryCloudBlobLease lease = new PrimaryCloudBlobLease(this.Name, configuration, true))
                {
                    if (lease.HasLease)
                    {
                        Dictionary <ICloudBlob, IAsyncResult> results = new Dictionary <ICloudBlob, IAsyncResult>();
                        foreach (string serverName in configuration.PrimaryServers)
                        {
                            watch.Start();
                            ICloudBlob blob = ClientRegistry.GetCloudBlob(serverName, configuration.Name, Name);
                            results[blob] = blob.BeginDelete(deleteSnapshotsOption, lease.getAccessConditionWithLeaseId(accessCondition), options, operationContext, null, null);
                            ServerState ss = slaEngine.Monitor.GetServerState(serverName);
                            ss.AddRtt(watch.ElapsedMilliseconds);
                            slaEngine.Session.RecordObjectWritten(Name, Timestamp(blob), ss);
                        }

                        foreach (ICloudBlob blob in results.Keys)
                        {
                            blob.EndDelete(results[blob]);
                        }
                        done = true;
                    }
                }
            }
        }
Exemple #2
0
        private void MultiWriteUsingBlobLease(WriteOp op)
        {
            // TODO: recover from failed clients that may leave a write partially completed
            // TODO: remove use of leases and replace with ETags
            // throw new Exception("Write to multiple primaries not yet implemented.");
            try
            {
                bool done = false;
                while (!done)
                {
                    // grab lease on blob to guard against concurrent writers
                    using (PrimaryCloudBlobLease lease = new PrimaryCloudBlobLease(blobName, configuration, true))
                    {
                        if (lease.HasLease)
                        {
                            // TODO: fix code for writing to multiple primaries (and remove it from here)
                            foreach (string server in configuration.PrimaryServers)
                            {
                                watch.Start();
                                ICloudBlob blob = ClientRegistry.GetCloudBlob(server, configuration.Name, blobName, false);
                                op(blob);
                                watch.Stop();

                                ServerState ss = slaEngine.Monitor.GetServerState(server);
                                ss.AddRtt(watch.ElapsedMilliseconds);
                                slaEngine.Session.RecordObjectWritten(blobName, Timestamp(blob), ss);
                            }
                            done = true;
                        }
                    }
                }
            }
            catch (StorageException se)
            {
                throw se;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void DoUploadFromStream(System.IO.Stream source, Microsoft.WindowsAzure.Storage.AccessCondition accessCondition = null, Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions options = null, Microsoft.WindowsAzure.Storage.OperationContext operationContext = null)
        {
            try
            {
                bool done = false;
                while (!done)
                {
                    using (PrimaryCloudBlobLease lease = new PrimaryCloudBlobLease(Name, configuration, true))
                    {
                        if (lease.HasLease)
                        {
                            foreach (string server in configuration.PrimaryServers)
                            {
                                watch.Start();

                                ICloudBlob blob = ClientRegistry.GetCloudBlob(server, configuration.Name, Name, false);

                                source.Position = 0;
                                blob.UploadFromStream(source, lease.getAccessConditionWithLeaseId(accessCondition), options, operationContext);

                                watch.Stop();

                                ServerState ss = slaEngine.Monitor.GetServerState(server);
                                ss.AddRtt(watch.ElapsedMilliseconds);
                                slaEngine.Session.RecordObjectWritten(Name, Timestamp(blob), ss);
                            }

                            done = true;
                        }
                    }
                }
            }
            catch (StorageException se)
            {
                throw se;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }