ivandika3 commented on code in PR #5753:
URL: https://github.com/apache/ozone/pull/5753#discussion_r1424872118


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/file/OMRecoverLeaseRequest.java:
##########
@@ -212,8 +211,7 @@ private String doWork(OzoneManager ozoneManager, long 
transactionLogIndex)
       LOG.warn("Key:" + keyName + " is already closed");
       return null;
     }
-    String openFileDBKey = omMetadataManager.getOpenFileName(
-            volumeId, bucketId, parentID, fileName, Long.parseLong(clientId));
+    String openFileDBKey = getKey.getOpenFileName();

Review Comment:
   Correct me if I'm wrong, but since `clientID` is not set in `OmGetKey` 
class, the `openFileDBKey` will take null as the `clientID`?
   
   You can refer to the earlier review on passing the `clientID` instead of 
storing it in the `OmGetKey` class. 
   
   Also you can refer to 
https://github.com/ivandika3/ozone/commit/4803bb27faa4b7790763d9952520fa62fd057d39#diff-4a6940e76f86d73b1112150209e4f32b9fb9c08aa5b9557e75ccb31b671ceafd
 (still a rough work).



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/helpers/OmGetKey.java:
##########
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.hadoop.ozone.om.helpers;
+
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Iterator;
+
+/**
+ * This class help to get metadata keys.
+ */
+public final class OmGetKey {
+
+  private String volumeName;
+  private String bucketName;
+  private String keyName;
+  private OMMetadataManager omMetadataManager;
+  private long clientID;

Review Comment:
   How about we remove `clientID` from the helper class? Instead, we can pass 
the `clientID` in the `getOpenFileName(long clientID)`.
   
   This makes the helper class reusable for getting different FSO-related DB 
keys, for example for FSO multipart open key 
(`OMMetadataManager#getMultipartKey`), which has the DB key format 
`/{volumeId}/{bucketId}/{parentId}/{fileName}/{uploadId}`, we can pass 
`uploadId` instead.
   
   To see what I meant, you can refer to 
https://github.com/ivandika3/ozone/commit/4803bb27faa4b7790763d9952520fa62fd057d39#diff-fae9ce494b51c92df1ea1465582a7ce2ea29afaf3aa06008ce5f0a7b41a17cbcR140-R153



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/helpers/OmGetKey.java:
##########
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.hadoop.ozone.om.helpers;
+
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Iterator;
+
+/**
+ * This class help to get metadata keys.
+ */
+public final class OmGetKey {
+
+  private String volumeName;
+  private String bucketName;
+  private String keyName;
+  private OMMetadataManager omMetadataManager;
+  private long clientID;
+
+  private String fileName;
+  private Iterator<Path> pathComponents;
+  private long volumeId;
+  private long bucketId;
+  private long parentID;
+
+
+  @SuppressWarnings("checkstyle:parameternumber")
+  private OmGetKey(String volumeName, String bucketName, String keyName, 
+      OMMetadataManager omMetadataManager, long clientID,
+      String fileName, Iterator<Path> pathComponents, long volumeId,
+      long bucketId, long parentID) {
+    this.volumeName = volumeName;
+    this.bucketName = bucketName;
+    this.keyName = keyName;
+    this.omMetadataManager = omMetadataManager;
+    this.clientID = clientID;
+
+    this.fileName = fileName;
+    this.pathComponents = pathComponents;
+    this.volumeId = volumeId;
+    this.bucketId = bucketId;
+    this.parentID = parentID;
+  }
+
+  /**
+   * Builder class for OmGetKey.
+   */
+  public static class Builder {
+    private String volumeName;
+    private String bucketName;
+    private String keyName;
+    private OMMetadataManager omMetadataManager;
+    private long clientID;
+    private String errMsg;
+
+    public Builder() {
+      this.errMsg = null;
+    }
+
+    public Builder setVolumeName(String volumeName) {
+      this.volumeName = volumeName;
+      return this;
+    }
+
+    public Builder setBucketName(String bucketName) {
+      this.bucketName = bucketName;
+      return this;
+    }
+
+    public Builder setKeyName(String keyName) {
+      this.keyName = keyName;
+      return this;
+    }
+
+    public Builder setOmMetadataManager(OMMetadataManager omMetadataManager) {
+      this.omMetadataManager = omMetadataManager;
+      return this;
+    }
+
+    public Builder setClientID(long clientID) {
+      this.clientID = clientID;
+      return this;
+    }
+
+    public Builder setErrMsg(String errMsg) {
+      this.errMsg = errMsg;
+      return this;
+    }
+
+    public OmGetKey build() throws IOException {
+      String fileName = OzoneFSUtils.getFileName(this.keyName);
+      Iterator<Path> pathComponents = Paths.get(this.keyName).iterator();
+      final long volumeId = omMetadataManager.getVolumeId(this.volumeName);
+      final long bucketId = omMetadataManager.getBucketId(this.volumeName,
+          this.bucketName);
+      long parentID = OMFileRequest
+          .getParentID(volumeId, bucketId, pathComponents, this.keyName,
+          this.omMetadataManager, this.errMsg);

Review Comment:
   This can be addressed in another Jira ticket, but from what I see since the 
`pathComponents` is derived from the `keyName`. We can remove this in 
`pathComponents` from the `OMFileRequest#getParentID` method arguments and 
instead call the   `Iterator<Path> pathComponents = 
Paths.get(this.keyName).iterator();` inside the `OMFileRequest#getParentID` 
instead.
   
   I did some rough work on this: 
https://github.com/ivandika3/ozone/commit/4803bb27faa4b7790763d9952520fa62fd057d39#diff-4ea3716be41b5b8969a751fdc62db55f498b23ddb6f4d1085605dc974057dd1e



-- 
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]

Reply via email to