private bool PutBlockList() { bool flag; bool flag1 = false; try { for (int i = 0; i < this._maxNumberOfRetries; i++) { try { using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew)) { using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext()) { this.GetContainer(dbContext); BlockBlob blob = this.GetBlob(dbContext, true) as BlockBlob; BlobServiceMetaData instance = BlobServiceMetaData.GetInstance(blob.ServiceMetadata); instance.CopyStatus = "success"; instance.CopyProgressOffset = this._contentLength.ToString(); instance.CopyProgressTotal = this._contentLength.ToString(); instance.CopyCompletionTime = new long?(DateTime.UtcNow.ToFileTimeUtc()); blob.HasBlock = new bool?((this._blockIds.Count > 1 ? true : this._contentLength < (long)4194304)); blob.ContentLength = this._contentLength; blob.ServiceMetadata = instance.GetMetadata(); blob.IsCommitted = new bool?(false); blob.UncommittedBlockIdLength = null; dbContext.SubmitChanges(); dbContext.CommitBlockList(this._accountName, this._containerName, this._blobName, DbListBlobObject.SerializeCommitBlockListEntryFromUncommitted(this._blockIds).ToString(), ref this._lastModifiedTime); transactionScope.Complete(); } } IStringDataEventStream info = Logger <IRestProtocolHeadLogger> .Instance.Info; object[] objArray = new object[] { this._accountName, this._containerName, this._blobName, this._contentLength }; info.Log("Commited Blocks for: {0}/{1}/{2}, Length:{3}", objArray); break; } catch (SqlException sqlException) { if (this.ShouldRethrowException(i, sqlException, out flag1)) { throw; } } } return(true); } catch (Exception exception1) { Exception exception = exception1; Logger <IRestProtocolHeadLogger> .Instance.Error.Log("CopyBlob: PutBlockList exception {0}", new object[] { exception }); this.SetCopyFailed(exception, flag1, null); flag = false; } return(flag); }
private void SetCopyStatus(Blob blobObj) { if (this._currentLength < this._contentLength) { BlobServiceMetaData instance = BlobServiceMetaData.GetInstance(blobObj.ServiceMetadata); instance.CopyProgressOffset = this._currentLength.ToString(); blobObj.ServiceMetadata = instance.GetMetadata(); } IStringDataEventStream info = Logger <IRestProtocolHeadLogger> .Instance.Info; object[] objArray = new object[] { this._accountName, this._containerName, this._blobName, this._currentLength, this._contentLength }; info.Log("CopyStatus for {0}/{1}/{2}: {3}B of {4}B", objArray); }
public static void SetCopyStatusToFailedAfterRestart() { while (true) { IEnumerable <Blob> blobs = null; try { using (TransactionScope transactionScope = new TransactionScope()) { using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext()) { IQueryable <Blob> blobs1 = from b in dbContext.Blobs select b; blobs = blobs1.Take <Blob>(100); if (blobs == null || blobs.Count <Blob>() == 0) { break; } else { foreach (Blob blob in blobs) { BlobServiceMetaData instance = BlobServiceMetaData.GetInstance(blob.ServiceMetadata); if (!"pending".Equals(instance.CopyStatus)) { continue; } instance.CopyStatus = "failed"; instance.CopyStatusDescription = "500 InternalError \"Reset to failed during restart.\""; Blob blob1 = DbBlobObject.ClearBlob(blob, instance.GetMetadata()); dbContext.Blobs.DeleteOnSubmit(blob); dbContext.SubmitChanges(); using (DevelopmentStorageDbDataContext developmentStorageDbDataContext = DevelopmentStorageDbDataContext.GetDbContext()) { developmentStorageDbDataContext.Blobs.InsertOnSubmit(blob1); developmentStorageDbDataContext.SubmitChanges(); } } } } transactionScope.Complete(); } } catch (Exception exception1) { Exception exception = exception1; Logger <IRestProtocolHeadLogger> .Instance.Error.Log("SetCopyStatusToFailedAfterRestart: Failed to change copy status! Exception {0}", new object[] { exception }); } } }
public void SetCopyCompleted() { for (int i = 0; i < this._maxNumberOfRetries; i++) { try { using (TransactionScope transactionScope = new TransactionScope()) { using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext()) { this.GetContainer(dbContext); Blob blob = this.GetBlob(dbContext, false); BlobServiceMetaData instance = BlobServiceMetaData.GetInstance(blob.ServiceMetadata); if (!string.Equals(this._copyId, instance.CopyId, StringComparison.OrdinalIgnoreCase)) { Logger <IRestProtocolHeadLogger> .Instance.Info.Log("CopyBlob: SetCopyCompleted not updating status as the copyId has changed."); } else { instance.CopyStatus = "success"; instance.CopyProgressOffset = this._contentLength.ToString(); instance.CopyProgressTotal = this._contentLength.ToString(); instance.CopyCompletionTime = new long?(DateTime.UtcNow.ToFileTimeUtc()); blob.ServiceMetadata = instance.GetMetadata(); dbContext.SubmitChanges(); transactionScope.Complete(); } } } break; } catch (Exception exception1) { Exception exception = exception1; if (i != this._maxNumberOfRetries - 1) { IStringDataEventStream critical = Logger <IRestProtocolHeadLogger> .Instance.Critical; object[] objArray = new object[] { exception, i + 1 }; critical.Log("Could not set copyStatus of blob. Exception {0}!Retrying attempt {1}...", objArray); } } } }
public void SetCopyFailed(Exception exception, bool isRetryFailure, string description) { bool flag; bool flag1 = true; for (int i = 0; i < this._maxNumberOfRetries; i++) { try { using (TransactionScope transactionScope = new TransactionScope()) { Blob blob = null; using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext()) { this.GetContainer(dbContext); Blob metadata = this.GetBlob(dbContext, false); DateTime?lastModificationTime = metadata.LastModificationTime; DateTime?nullable = this._lastModifiedTime; if (lastModificationTime.HasValue != nullable.HasValue) { flag = true; } else { flag = (!lastModificationTime.HasValue ? false : lastModificationTime.GetValueOrDefault() != nullable.GetValueOrDefault()); } if (flag) { flag1 = false; } BlobServiceMetaData instance = BlobServiceMetaData.GetInstance(metadata.ServiceMetadata); if (!string.Equals(this._copyId, instance.CopyId, StringComparison.OrdinalIgnoreCase)) { Logger <IRestProtocolHeadLogger> .Instance.Info.Log("CopyBlob: SetCopyFailed not updating status as the copyId is changed."); break; } else { instance.CopyStatus = "failed"; instance.CopyStatusDescription = (description == null ? string.Format("Internal Error. HasRetriedOnFailure={0}", isRetryFailure) : description); instance.CopyCompletionTime = new long?(DateTime.UtcNow.ToFileTimeUtc()); if (!flag1) { metadata.ServiceMetadata = instance.GetMetadata(); metadata.ContentLength = (long)0; } else { blob = DbBlobObject.ClearBlob(metadata, instance.GetMetadata()); dbContext.Blobs.DeleteOnSubmit(metadata); } dbContext.SubmitChanges(); } } if (flag1) { using (DevelopmentStorageDbDataContext developmentStorageDbDataContext = DevelopmentStorageDbDataContext.GetDbContext()) { developmentStorageDbDataContext.Blobs.InsertOnSubmit(blob); developmentStorageDbDataContext.SubmitChanges(); } } transactionScope.Complete(); } break; } catch (Exception exception2) { Exception exception1 = exception2; if (i != this._maxNumberOfRetries - 1) { IStringDataEventStream critical = Logger <IRestProtocolHeadLogger> .Instance.Critical; object[] objArray = new object[] { exception1, i + 1 }; critical.Log("Could not set copyStatus of blob. Exception {0}!Retrying attempt {1}...", objArray); } } } }