smengcl commented on code in PR #5847:
URL: https://github.com/apache/ozone/pull/5847#discussion_r1461296466
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/file/OMRecoverLeaseRequest.java:
##########
@@ -186,60 +179,56 @@ public OMClientResponse
validateAndUpdateCache(OzoneManager ozoneManager,
return omClientResponse;
}
- private String doWork(OzoneManager ozoneManager, long transactionLogIndex)
- throws IOException {
-
+ private RecoverLeaseResponse doWork(OzoneManager ozoneManager,
+ long transactionLogIndex) throws IOException {
final long volumeId = omMetadataManager.getVolumeId(volumeName);
- final long bucketId = omMetadataManager.getBucketId(
- volumeName, bucketName);
+ final long bucketId = omMetadataManager.getBucketId(volumeName,
bucketName);
Iterator<Path> pathComponents = Paths.get(keyName).iterator();
long parentID = OMFileRequest.getParentID(volumeId, bucketId,
pathComponents, keyName, omMetadataManager,
"Cannot recover file : " + keyName
+ " as parent directory doesn't exist");
String fileName = OzoneFSUtils.getFileName(keyName);
- dbFileKey = omMetadataManager.getOzonePathKey(volumeId, bucketId,
- parentID, fileName);
+ dbFileKey = omMetadataManager.getOzonePathKey(volumeId, bucketId,
parentID, fileName);
keyInfo = getKey(dbFileKey);
if (keyInfo == null) {
- throw new OMException("Key:" + keyName + " not found", KEY_NOT_FOUND);
+ throw new OMException("Key:" + keyName + " not found in keyTable",
KEY_NOT_FOUND);
}
- final String clientId = keyInfo.getMetadata().remove(
- OzoneConsts.HSYNC_CLIENT_ID);
- if (clientId == null) {
+
+ final String writerId =
keyInfo.getMetadata().get(OzoneConsts.HSYNC_CLIENT_ID);
+ if (writerId == null) {
// if file is closed, do nothing and return right away.
- LOG.warn("Key:" + keyName + " is already closed");
- return null;
+ throw new OMException("Key: " + keyName + " is already closed",
KEY_ALREADY_CLOSED);
}
- String openFileDBKey = omMetadataManager.getOpenFileName(
- volumeId, bucketId, parentID, fileName, Long.parseLong(clientId));
- if (openFileDBKey != null) {
- commitKey(dbFileKey, keyInfo, fileName, ozoneManager,
- transactionLogIndex);
- removeOpenKey(openFileDBKey, fileName, transactionLogIndex);
+
+ dbOpenFileKey = omMetadataManager.getOpenFileName(
+ volumeId, bucketId, parentID, fileName, Long.parseLong(writerId));
+ openKeyInfo =
omMetadataManager.getOpenKeyTable(getBucketLayout()).get(dbOpenFileKey);
+ if (openKeyInfo == null) {
+ throw new OMException("Open Key " + dbOpenFileKey + " not found in
openKeyTable", KEY_NOT_FOUND);
+ }
+
+ if (openKeyInfo.getMetadata().containsKey(OzoneConsts.LEASE_RECOVERY)) {
+ LOG.debug("Key: " + keyName + " is already under recovery");
+ } else {
+ openKeyInfo.getMetadata().put(OzoneConsts.LEASE_RECOVERY, "true");
+ openKeyInfo.setUpdateID(transactionLogIndex,
ozoneManager.isRatisEnabled());
+ openKeyInfo.setModificationTime(Time.now());
+ // Add to cache.
+ omMetadataManager.getOpenKeyTable(getBucketLayout()).addCacheEntry(
+ new CacheKey<>(dbOpenFileKey), CacheValue.get(transactionLogIndex,
openKeyInfo));
Review Comment:
i.e.
```suggestion
// Add to cache.
omMetadataManager.getOpenKeyTable(getBucketLayout()).addCacheEntry(
dbOpenFileKey, openKeyInfo, transactionLogIndex);
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]