Skip to content

Commit

Permalink
Fix lease-lost decision logic (#179)
Browse files Browse the repository at this point in the history
* Provide inner exception's message as LeaseLostException's message.

* Fix the lease-lost decision logic.
  • Loading branch information
serkantkaraca committed Aug 18, 2017
1 parent ba15eda commit 438fd4c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,7 @@ async Task<bool> AcquireLeaseCoreAsync(AzureBlobLease lease)
}
catch (StorageException se)
{
if (WasLeaseLost(partitionId, se))
{
retval = false;
}
else
{
throw;
}
throw HandleStorageException(partitionId, se);
}

return retval;
Expand All @@ -362,12 +355,7 @@ async Task<bool> RenewLeaseCoreAsync(AzureBlobLease lease)
}
catch (StorageException se)
{
if (WasLeaseLost(partitionId, se))
{
throw new LeaseLostException(partitionId, se);
}

throw;
throw HandleStorageException(partitionId, se);
}

return true;
Expand Down Expand Up @@ -398,12 +386,7 @@ async Task<bool> ReleaseLeaseCoreAsync(AzureBlobLease lease)
}
catch (StorageException se)
{
if (WasLeaseLost(partitionId, se))
{
throw new LeaseLostException(partitionId, se);
}

throw;
throw HandleStorageException(partitionId, se);
}

return true;
Expand Down Expand Up @@ -442,12 +425,7 @@ async Task<bool> UpdateLeaseCoreAsync(AzureBlobLease lease)
}
catch (StorageException se)
{
if (WasLeaseLost(partitionId, se))
{
throw new LeaseLostException(partitionId, se);
}

throw;
throw HandleStorageException(partitionId, se);
}

return true;
Expand All @@ -462,31 +440,32 @@ async Task<AzureBlobLease> DownloadLeaseAsync(string partitionId, CloudBlockBlob
AzureBlobLease blobLease = new AzureBlobLease(rehydrated, blob);
return blobLease;
}
bool WasLeaseLost(string partitionId, StorageException se)

Exception HandleStorageException(string partitionId, StorageException se)
{
bool retval = false;
ProcessorEventSource.Log.AzureStorageManagerInfo(this.host.Id, partitionId, "WAS LEASE LOST?");
ProcessorEventSource.Log.AzureStorageManagerInfo(this.host.Id, partitionId, "HttpStatusCode " + se.RequestInformation.HttpStatusCode);
ProcessorEventSource.Log.AzureStorageManagerInfo(this.host.Id, partitionId, "HandleStorageException - HttpStatusCode " + se.RequestInformation.HttpStatusCode);
if (se.RequestInformation.HttpStatusCode == 409 || // conflict
se.RequestInformation.HttpStatusCode == 412) // precondition failed
{
StorageExtendedErrorInformation extendedErrorInfo = se.RequestInformation.ExtendedErrorInformation;

if (extendedErrorInfo != null)
{
string errorCode = extendedErrorInfo.ErrorCode;
ProcessorEventSource.Log.AzureStorageManagerInfo(this.host.Id, partitionId, "Error code: " + errorCode);
ProcessorEventSource.Log.AzureStorageManagerInfo(this.host.Id, partitionId, "Error message: " + extendedErrorInfo.ErrorMessage);
if (errorCode == BlobErrorCodeStrings.LeaseLost ||
errorCode == BlobErrorCodeStrings.LeaseIdMismatchWithLeaseOperation ||
errorCode == BlobErrorCodeStrings.LeaseIdMismatchWithBlobOperation)
{
retval = true;
}
ProcessorEventSource.Log.AzureStorageManagerInfo(this.host.Id, partitionId, "HandleStorageException - Error code: " + errorCode);
ProcessorEventSource.Log.AzureStorageManagerInfo(this.host.Id, partitionId, "HandleStorageException - Error message: " + extendedErrorInfo.ErrorMessage);
}

if (extendedErrorInfo == null ||
extendedErrorInfo.ErrorCode == BlobErrorCodeStrings.LeaseLost ||
extendedErrorInfo.ErrorCode == BlobErrorCodeStrings.LeaseIdMismatchWithLeaseOperation ||
extendedErrorInfo.ErrorCode == BlobErrorCodeStrings.LeaseIdMismatchWithBlobOperation)
{
return new LeaseLostException(partitionId, se);
}
}

return retval;
return se;
}

CloudBlockBlob GetBlockBlobReference(string partitionId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class LeaseLostException : Exception
readonly string partitionId;

internal LeaseLostException(string partitionId, Exception innerException)
: base(string.Empty, innerException)
: base(innerException.Message, innerException)
{
if (partitionId == null)
{
Expand Down

0 comments on commit 438fd4c

Please sign in to comment.