2011-02-04 13 views
6

tôi có mã này:Lỗi lưu trữ Azure: "Các đốm màu đã chỉ định đã tồn tại", nhưng không!

 CloudBlob blob = _container.GetBlobReference(relativefilePath); 
     blob.Properties.ContentType = contentType; 
     blob.UploadFromStream(fileContent); 

Khi tôi tải lên một tập tin lớn (150MB) để lưu trữ phát triển và tôi đã nhận ngoại lệ này:

Microsoft.WindowsAzure.StorageClient.StorageClientException was unhandled by user code
Message=The specified blob already exists.
Source=Microsoft.WindowsAzure.StorageClient

Nhưng đó là không đúng sự thật, các tập tin không hiện hữu. Trên thực tế, tôi không biết tại sao đó phải là một vấn đề, mỗi khi tôi đã cố gắng, tôi có thể ghi đè lên một blob hiện có w/o bất kỳ vấn đề. Điều tuyệt vời nhất là khi ngoại lệ xuất hiện trong VS, tôi chọn "Bật chỉnh sửa", tôi di chuyển con trỏ thực hiện (mũi tên màu vàng) sang dòng mã thứ 2 cho thấy, thực thi ... và sau đó là HOẠT ĐỘNG NÓ !!

Tôi chỉ nhận ngoại lệ với các tệp lớn và tôi không hiểu tại sao.

Đây là chi tiết ngoại lệ:

Microsoft.WindowsAzure.StorageClient.StorageClientException was unhandled by user code 
    Message=The specified blob already exists. 
    Source=Microsoft.WindowsAzure.StorageClient 
    StackTrace: 
     at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.get_Result() 
     at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.ExecuteAndWait() 
     at Microsoft.WindowsAzure.StorageClient.TaskImplHelper.ExecuteImpl(Func`1 impl) 
     at Microsoft.WindowsAzure.StorageClient.CloudBlob.UploadFromStream(Stream source, BlobRequestOptions options) 
     at Microsoft.WindowsAzure.StorageClient.CloudBlob.UploadFromStream(Stream source) 
     at AzureBlobOperations.AzureFileContainerOperations.PutFile(String relativefilePath, Stream fileContent, String contentType, Boolean createIfNotExists) in C:\Users\valeriano.tortola\Documents\Visual Studio 2010\Projects\TestWithBlobs\AzureBlobOperations\AzureFileOperations.cs:line 61 
     at TestWithBlobs.Web.Controllers.HomeController.PostFile(HttpPostedFileBase fileUpload) in C:\Users\valeriano.tortola\Documents\Visual Studio 2010\Projects\TestWithBlobs\TestWithBlobs.Web\Controllers\HomeController.cs:line 31 
     at lambda_method(Closure , ControllerBase , Object[]) 
     at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) 
     at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) 
     at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() 
     at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) 
    InnerException: System.Net.WebException 
     Message=The remote server returned an error: (409) Conflict. 
     Source=System 
     StackTrace: 
      at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 
      at Microsoft.WindowsAzure.StorageClient.EventHelper.ProcessWebResponse(WebRequest req, IAsyncResult asyncResult, EventHandler`1 handler, Object sender) 
     InnerException: 

Trả lời

10

Đây là một vấn đề được biết đến với lưu trữ phát triển. Điều này xảy ra khi có nhiều luồng được khởi chạy để tải lên các khối (tạo thành blob). Về cơ bản những gì đang xảy ra là lưu trữ phát triển sử dụng SQL Server làm kho dữ liệu. Bây giờ điều đầu tiên nó làm là làm cho một mục nhập vào bảng lưu trữ thông tin blob. Nếu có nhiều luồng làm việc thì tất cả các luồng này sẽ cố gắng thực hiện cùng một thao tác. Sau khi chuỗi đầu tiên thành công, các chuỗi tiếp theo sẽ dẫn đến ngoại lệ này được nâng lên.

+0

cảm ơn, vì vậy nó không sẽ xảy ra trong những điều thực sự, không phải là nó? – vtortola

+0

Đó là sự thật. Nó sẽ không xảy ra trong đám mây bởi vì một blob không được cam kết cho đến khi bạn gọi "Commit Block List" hoạt động một cách rõ ràng. –