2
我正在開發一個應用程序,我不時有一個錯誤,我不得不同步幾個工人角色與blob租約。CloubBlockBlob AcquireLease提供兩個租賃給兩個工作者角色
下面是輔助角色我的初始化代碼
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageAccount"));
string blobContainerName = RoleEnvironment.GetConfigurationSettingValue("BlobContainer");
CloudBlobContainer blobContainer = storageAccount.CreateCloudBlobClient().GetContainerReference(blobContainerName);
blobContainer.CreateIfNotExists();
string blobName = RoleEnvironment.GetConfigurationSettingValue("BlobToBeLeased");
_blob = blobContainer.GetBlockBlobReference(blobName);
if (!_blob.Exists())
{
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("This is dummy data")))
{
try
{
_blob.UploadFromStream(ms);
}
catch (StorageException storageException)
{
if (storageException.RequestInformation.HttpStatusCode != 412)
throw;
}
}
}
這裏是我的AcquireLease方法:
private void AcquireLease()
{
try
{
var leaseId = _blob.AcquireLease(null, null);
Trace.WriteLine("==========> Lease acquired! <========== ID => " + leaseId);
_accessCondition = new AccessCondition {LeaseId = leaseId};
}
catch (Exception)
{
Trace.WriteLine("==========> Lease rejected! <==========");
}
}
問題的截圖:
的問題是什麼時候調用AcquireLease方法,它有時會給我兩個租約...任何人都有一個想法如何解決這個...
CloudBlockBlob操作是否爲原子?
這是不對的... – 2016-03-06 04:25:19