private void FastWrite(WriteOp op, List <SessionState> sessions = null, ServerMonitor monitor = null) { // there should only be one primary server since we are in fast mode string server = configuration.PrimaryServers.First(); ICloudBlob blob = ClientRegistry.GetCloudBlob(server, configuration.Name, blobName, false); watch.Start(); op(blob); watch.Stop(); // update server and session state ServerState ss = (monitor == null) ? slaEngine.Monitor.GetServerState(server) : monitor.GetServerState(server); ss.AddRtt(watch.ElapsedMilliseconds); if (sessions == null) { slaEngine.Session.RecordObjectWritten(blobName, Timestamp(blob), ss); } else { foreach (SessionState session in sessions) { session.RecordObjectWritten(blobName, Timestamp(blob), ss); } } }
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; } } } }
public void FetchAttributes(Microsoft.WindowsAzure.Storage.AccessCondition accessCondition = null, Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions options = null, Microsoft.WindowsAzure.Storage.OperationContext operationContext = null) { // TODO: use protocol ServerState ss = slaEngine.FindServerToRead(Name); ICloudBlob blob = ClientRegistry.GetCloudBlob(ss.Name, configuration.Name, Name); watch.Start(); blob.FetchAttributes(accessCondition, options, operationContext); ss.AddRtt(watch.ElapsedMilliseconds); // slaEngine.SessionState.RecordObjectRead(blob.Name, Timestamp(blob), ss); slaEngine.Session.RecordObjectRead(blob.Name, Timestamp(blob), ss, ""); }
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; } }
private void MultiWrite(WriteOp op, AccessCondition access, List <SessionState> sessions = null, ServerMonitor monitor = null) { // This protocol uses three phases and ETags // It assumes that the client is in fast mode and remains so throughout the protocol // i.e. it assumes that the set of primaries does not change. // TODO: recover from failed clients that may leave a write partially completed ICloudBlob blob; Dictionary <string, string> eTags; // Phase 1. Mark intention to write with write-in-progress flags eTags = SetWiPFlags(); if (eTags == null) { // flags were not successfully set, so abort the protocol return; } // Phase 2. Perform write at all primaries bool didAtLeastOne = false; foreach (string server in configuration.PrimaryServers) { blob = ClientRegistry.GetCloudBlob(server, configuration.Name, blobName, false); access.IfMatchETag = eTags[server]; watch.Start(); try { op(blob); } catch (StorageException) { // If writing fails at some primary, then abort the protocol // It could be that a concurrent writer is in progress // Note that some writes may have already been performed // If so, then we leave the WiP flags set so the recovery process will kick in // or so a concurrent writer can complete its protocol and overwrite our writes // If not, then we can clear the WiP flags if (!didAtLeastOne) { ClearWiPFlags(eTags); } return; } watch.Stop(); eTags[server] = blob.Properties.ETag; didAtLeastOne = true; // update session and server state ServerState ss = (monitor == null) ? slaEngine.Monitor.GetServerState(server) : monitor.GetServerState(server); ss.AddRtt(watch.ElapsedMilliseconds); if (sessions == null) { slaEngine.Session.RecordObjectWritten(blobName, Timestamp(blob), ss); } else { foreach (SessionState session in sessions) { session.RecordObjectWritten(blobName, Timestamp(blob), ss); } } } // Phase 3. Clear write-in-progress flags to indicate that write has completed ClearWiPFlags(eTags); }
public void RecordObjectRead(string name, DateTimeOffset timestamp, ServerState server, long duration) { server.AddRtt(duration); Session.RecordObjectRead(name, timestamp, server, Sla.Id); DetermineHitSubSLA(name, timestamp, server, duration); }