snehavarma commented on a change in pull request #1925:
URL: https://github.com/apache/hadoop/pull/1925#discussion_r595327566
##########
File path:
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystemStore.java
##########
@@ -702,15 +735,72 @@ public OutputStream openFileForWrite(final Path path,
final FileSystem.Statistic
isAppendBlob = true;
}
+ SelfRenewingLease lease = maybeCreateLease(relativePath);
+
return new AbfsOutputStream(
client,
statistics,
relativePath,
offset,
- populateAbfsOutputStreamContext(isAppendBlob));
+ populateAbfsOutputStreamContext(isAppendBlob, lease));
}
}
+ /**
+ * Acquire a lease on an ABFS file for a specified duration. This requires
the file to exist.
+ *
+ * @param path file name
+ * @param duration time lease will be held before expiring
+ * @return the acquired lease ID
+ * @throws AzureBlobFileSystemException on any exception while acquiring the
lease
+ */
+ public String acquireLease(final Path path, final int duration) throws
AzureBlobFileSystemException {
+ LOG.debug("lease path: {}", path);
+
+ final AbfsRestOperation op =
+ client.acquireLease(getRelativePath(path), duration);
+
+ return
op.getResult().getResponseHeader(HttpHeaderConfigurations.X_MS_LEASE_ID);
+ }
+
+ /**
Review comment:
Yes if the file is being created then infinite lease can be
automatically taken, for other cases yes you may need the acquire lease code.
RenewLease code might be something you can completely get rid of
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]