supratimdeka commented on a change in pull request #623: HDDS-2941. file create 
: create key table entries for intermediate directories in the path
URL: https://github.com/apache/hadoop-ozone/pull/623#discussion_r392674818
 
 

 ##########
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/file/OMFileCreateRequest.java
 ##########
 @@ -379,6 +358,65 @@ public OMClientResponse 
validateAndUpdateCache(OzoneManager ozoneManager,
     return omClientResponse;
   }
 
+  private void checkAllParentsExist(OzoneManager ozoneManager,
+      KeyArgs keyArgs,
+      OMFileRequest.OMPathInfo pathInfo) throws IOException {
+    Boolean canBeCreated = false;
+    String keyName = keyArgs.getKeyName();
+    OMFileRequest.OMDirectoryResult omDirectoryResult =
+        pathInfo.getDirectoryResult();
+
+    if (ozoneManager.createPrefixEntries()) {
+      // if immediate parent exists, assume higher level directories exist.
+      if (pathInfo.getDirectParentExists()) {
+        canBeCreated = true;
+      }
+    } else {
+      String volumeName = keyArgs.getVolumeName();
+      String bucketName = keyArgs.getBucketName();
+
+      // We cannot create a file if complete parent directories don't exist.
+
+      // verifyFilesInPath, checks only the path and its parent directories.
+      // But there may be some keys below the given path. So this method
+      // checks them.
+
+      // Example:
+      // Existing keys in table
+      // a/b/c/d/e
+      // a/b/c/d/f
+      // a/b
+
+      // Take an example if given key to be created with isRecursive set
+      // to false is "a/b/c/e".
+      // There is no key in keyTable with the provided path.
+      // Check in case if there are keys exist in given path. (This can
+      // happen if keys are directly created using key requests.)
+
+      // We need to do this check only in the case of non-recursive, so
+      // not included the checks done in checkKeysUnderPath in
+      // verifyFilesInPath method, as that method is common method for
+      // directory and file create request. This also avoid's this
+      // unnecessary check which is not required for those cases.
+      if (omDirectoryResult == NONE ||
+          omDirectoryResult == DIRECTORY_EXISTS_IN_GIVENPATH) {
+        canBeCreated =
+            checkKeysUnderPath(ozoneManager.getMetadataManager(), volumeName,
+                bucketName, keyName);
+      } else if (omDirectoryResult == FILE_EXISTS_IN_GIVENPATH) {
+        canBeCreated = false;
 
 Review comment:
   This code has changed.

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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to