/** * Free the lease and stop the keep-alive thread. * @throws StorageException Thrown when fail to free the lease. */ public void free() throws StorageException { AccessCondition accessCondition = AccessCondition.generateEmptyCondition(); accessCondition.setLeaseID(leaseID); try { blobWrapper.getBlob().releaseLease(accessCondition); } catch (StorageException e) { if ("BlobNotFound".equals(e.getErrorCode())) { // Don't do anything -- it's okay to free a lease // on a deleted file. The delete freed the lease // implicitly. } else { // This error is not anticipated, so re-throw it. LOG.warn("Unanticipated exception when trying to free lease " + leaseID + " on " + blobWrapper.getStorageUri()); throw(e); } } finally { // Even if releasing the lease fails (e.g. because the file was deleted), // make sure to record that we freed the lease, to terminate the // keep-alive thread. leaseFreed = true; LOG.debug("Freed lease " + leaseID + " on " + blobWrapper.getUri() + " managed by thread " + renewer.getName()); } }
AccessCondition accessCondition = AccessCondition.generateEmptyCondition(); accessCondition.setLeaseID(leaseID);
/** * Releases the lease on the container. * * @param leaseID * The lease ID. */ public void releaseLease(String leaseID, String blobKey) throws Exception { AccessCondition accessCondition = new AccessCondition(); accessCondition.setLeaseID(leaseID); getBlobReference(blobKey).releaseLease(accessCondition); }
/** * Releases the lease on the container. * * @param leaseID * The lease ID. */ public void releaseLease(String leaseID, String blobKey) throws Exception { AccessCondition accessCondition = new AccessCondition(); accessCondition.setLeaseID(leaseID); getBlobReference(blobKey).releaseLease(accessCondition); }
@Test @Category(SlowTests.class) public void testContainerBreakLease() throws StorageException, InterruptedException { String proposedLeaseId = UUID.randomUUID().toString(); try { // 5 sec this.container.acquireLease(15, proposedLeaseId); AccessCondition condition = new AccessCondition(); condition.setLeaseID(proposedLeaseId); OperationContext operationContext1 = new OperationContext(); this.container.breakLease(0, condition, null/* BlobRequestOptions */, operationContext1); assertTrue(operationContext1.getLastResult().getStatusCode() == HttpURLConnection.HTTP_ACCEPTED); Thread.sleep(15 * 1000); // infinite proposedLeaseId = this.container.acquireLease(); condition = new AccessCondition(); condition.setLeaseID(proposedLeaseId); OperationContext operationContext2 = new OperationContext(); this.container.breakLease(0, condition, null/* BlobRequestOptions */, operationContext2); assertTrue(operationContext2.getLastResult().getStatusCode() == HttpURLConnection.HTTP_ACCEPTED); } finally { // cleanup AccessCondition condition = new AccessCondition(); condition.setLeaseID(proposedLeaseId); this.container.releaseLease(condition); } }
@Test public void testContainerReleaseLease() throws StorageException { // 15 sec String proposedLeaseId = UUID.randomUUID().toString(); String leaseId = this.container.acquireLease(15, proposedLeaseId); AccessCondition condition = new AccessCondition(); condition.setLeaseID(leaseId); OperationContext operationContext1 = new OperationContext(); this.container.releaseLease(condition, null/* BlobRequestOptions */, operationContext1); assertTrue(operationContext1.getLastResult().getStatusCode() == HttpURLConnection.HTTP_OK); // infinite leaseId = this.container.acquireLease(); condition = new AccessCondition(); condition.setLeaseID(leaseId); OperationContext operationContext2 = new OperationContext(); this.container.releaseLease(condition, null/* BlobRequestOptions */, operationContext2); assertTrue(operationContext2.getLastResult().getStatusCode() == HttpURLConnection.HTTP_OK); }
this.accessCondition.setLeaseID(previousLeaseId);
@Test public void testContainerRenewLeaseTest() throws StorageException{ String proposedLeaseId = UUID.randomUUID().toString(); try { // 5 sec this.container.acquireLease(15, proposedLeaseId); AccessCondition condition = new AccessCondition(); condition.setLeaseID(proposedLeaseId); OperationContext operationContext1 = new OperationContext(); this.container.renewLease(condition, null/* BlobRequestOptions */, operationContext1); assertTrue(operationContext1.getLastResult().getStatusCode() == HttpURLConnection.HTTP_OK); this.container.releaseLease(condition); // infinite proposedLeaseId = this.container.acquireLease(); condition = new AccessCondition(); condition.setLeaseID(proposedLeaseId); OperationContext operationContext2 = new OperationContext(); this.container.renewLease(condition, null/* BlobRequestOptions */, operationContext2); assertTrue(operationContext2.getLastResult().getStatusCode() == HttpURLConnection.HTTP_OK); } finally { // cleanup AccessCondition condition = new AccessCondition(); condition.setLeaseID(proposedLeaseId); this.container.releaseLease(condition); } }
@Override public void recoveryAction(OperationContext context) throws IOException { if (this.getETagLockCondition() == null && (!Utility.isNullOrEmpty(this.getLockedETag()))) { AccessCondition etagLockCondition = new AccessCondition(); etagLockCondition.setIfMatch(this.getLockedETag()); if (accessCondition != null) { etagLockCondition.setLeaseID(accessCondition.getLeaseID()); } this.setETagLockCondition(etagLockCondition); } if (this.getCurrentRequestByteCount() > 0) { this.setOffset(startingOffset + this.getCurrentRequestByteCount()); if (length != null) { this.setLength(length - this.getCurrentRequestByteCount()); } } } };
this.accessCondition.setLeaseID(previousLeaseId);
@Override public void recoveryAction(OperationContext context) throws IOException { if (this.getETagLockCondition() == null && (!Utility.isNullOrEmpty(this.getLockedETag()))) { AccessCondition etagLockCondition = new AccessCondition(); etagLockCondition.setIfMatch(this.getLockedETag()); if (accessCondition != null) { etagLockCondition.setLeaseID(accessCondition.getLeaseID()); } this.setETagLockCondition(etagLockCondition); } if (this.getCurrentRequestByteCount() > 0) { this.setOffset(startingOffset + this.getCurrentRequestByteCount()); if (lengthFinal != null) { this.setLength(lengthFinal - this.getCurrentRequestByteCount()); } } } };
@Override public void recoveryAction(OperationContext context) throws IOException { if (this.getETagLockCondition() == null && (!Utility.isNullOrEmpty(this.getLockedETag()))) { AccessCondition etagLockCondition = new AccessCondition(); etagLockCondition.setIfMatch(this.getLockedETag()); if (accessCondition != null) { etagLockCondition.setLeaseID(accessCondition.getLeaseID()); } this.setETagLockCondition(etagLockCondition); } if (this.getCurrentRequestByteCount() > 0) { this.setOffset(startingOffset + this.getCurrentRequestByteCount()); if (length != null) { this.setLength(length - this.getCurrentRequestByteCount()); } } } };
appendCondition.setLeaseID(accessCondition.getLeaseID()); appendCondition.setIfAppendPositionEqual(accessCondition.getIfAppendPositionEqual()); appendCondition.setIfMaxSizeLessThanOrEqual(accessCondition.getIfMaxSizeLessThanOrEqual());
@Override public void recoveryAction(OperationContext context) throws IOException { if (this.getETagLockCondition() == null && (!Utility.isNullOrEmpty(this.getLockedETag()))) { AccessCondition etagLockCondition = new AccessCondition(); etagLockCondition.setIfMatch(this.getLockedETag()); if (accessCondition != null) { etagLockCondition.setLeaseID(accessCondition.getLeaseID()); } this.setETagLockCondition(etagLockCondition); } if (this.getCurrentRequestByteCount() > 0) { this.setOffset(startingOffset + this.getCurrentRequestByteCount()); if (length != null) { this.setLength(length - this.getCurrentRequestByteCount()); } } } };
assertTrue(differentLeaseID != null); AccessCondition accessCondition = AccessCondition.generateEmptyCondition(); accessCondition.setLeaseID(differentLeaseID); blob.releaseLease(accessCondition);
assertTrue(differentLeaseID != null); AccessCondition accessCondition = AccessCondition.generateEmptyCondition(); accessCondition.setLeaseID(differentLeaseID); blob.releaseLease(accessCondition);
condition.setLeaseID(proposedLeaseId1); leaseContainer1.releaseLease(condition); leaseContainer1.deleteIfExists(); condition.setLeaseID(proposedLeaseId2); leaseContainer2.releaseLease(condition); leaseContainer2.deleteIfExists();
appendCondition.setLeaseID(accessCondition.getLeaseID()); appendCondition.setIfAppendPositionEqual(accessCondition.getIfAppendPositionEqual()); appendCondition.setIfMaxSizeLessThanOrEqual(accessCondition.getIfMaxSizeLessThanOrEqual());
this.accessCondition.setLeaseID(previousLeaseId);
this.accessCondition.setLeaseID(previousLeaseId);