linyiqun commented on a change in pull request #1503:
URL: https://github.com/apache/hadoop-ozone/pull/1503#discussion_r507038746



##########
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/KeyManagerImpl.java
##########
@@ -2205,6 +2272,167 @@ private void listStatusFindKeyInTableCache(
     return fileStatusList;
   }
 
+  public List<OzoneFileStatus> listStatusV1(OmKeyArgs args, boolean recursive,
+      String startKey, long numEntries, String clientAddress)
+          throws IOException {
+    Preconditions.checkNotNull(args, "Key args can not be null");
+
+    List<OzoneFileStatus> fileStatusList = new ArrayList<>();
+    if (numEntries <= 0) {
+      return fileStatusList;
+    }
+
+    String volumeName = args.getVolumeName();
+    String bucketName = args.getBucketName();
+    String keyName = args.getKeyName();
+    // A map sorted by OmKey to combine results from TableCache and DB.
+    TreeMap<String, OzoneFileStatus> cacheKeyMap = new TreeMap<>();
+    String seekKeyInDB = "";
+    long prefixKeyInDB = Long.MIN_VALUE;
+    String prefixPath = keyName;
+
+    metadataManager.getLock().acquireReadLock(BUCKET_LOCK, volumeName,
+            bucketName);
+    try {
+      if (Strings.isNullOrEmpty(startKey)) {
+        OzoneFileStatus fileStatus = getFileStatus(args, clientAddress);
+        if (fileStatus.isFile()) {
+          return Collections.singletonList(fileStatus);
+        }
+
+        // keyName is a directory
+        if (fileStatus.getKeyInfo() != null) {
+          seekKeyInDB = fileStatus.getKeyInfo().getObjectID()
+                  + OZONE_URI_DELIMITER;
+          prefixKeyInDB = fileStatus.getKeyInfo().getObjectID();
+        } else {
+          String bucketKey = metadataManager.getBucketKey(volumeName,
+                  bucketName);
+          OmBucketInfo omBucketInfo =
+                  metadataManager.getBucketTable().get(bucketKey);
+          seekKeyInDB = omBucketInfo.getObjectID()
+                  + OZONE_URI_DELIMITER;
+          prefixKeyInDB = omBucketInfo.getObjectID();
+        }
+      } else {
+        // startKey will be used in iterator seek and sets the beginning point
+        // for key traversal.
+        // key name will be used as parent ID where the user has requested to
+        // list the keys from.
+        OzoneFileStatus fileStatusInfo = getOzoneFileStatusV1(volumeName,
+                bucketName, startKey, false, null);
+        if (fileStatusInfo != null) {
+          prefixKeyInDB = fileStatusInfo.getKeyInfo().getParentObjectID();
+          seekKeyInDB = prefixKeyInDB + OZONE_URI_DELIMITER
+                  + fileStatusInfo.getKeyInfo().getFileName();
+        }
+      }
+
+      // Not required to search in TableCache because all the deleted keys
+      // are marked directly in directory table or in key table by breaking
+      // the pointer to its sub-dirs. So, there is no issue of inconsistency.
+      int countEntries = 0;

Review comment:
       Currently, CreateFile/CreateDir of V1 version also add entry into double 
buffer cache first, then flush to db. So seems we still need to combine the 
result from table cache and db.
   
   For the further DeleteFile/DeleteDir API implement, we may still follow this 
cache way. Not fully understand why here we say ' deleted keys are marked 
directly in directory table'. Current write type request always operate the 
cache first, then flush to db I think.




----------------------------------------------------------------
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:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: ozone-issues-h...@hadoop.apache.org

Reply via email to