sumitagrawl commented on code in PR #6658:
URL: https://github.com/apache/ozone/pull/6658#discussion_r1599732492


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/types/ListKeysResponse.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.recon.api.types;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * HTTP Response wrapped for listKeys requests.
+ */
+public class ListKeysResponse {
+  /** Path status. */
+  @JsonProperty("status")
+  private ResponseStatus status;
+
+  /** The current path request. */
+  @JsonProperty("path")
+  private String path;
+
+  /** Amount of data mapped to all keys and files in a cluster across all DNs. 
*/
+  @JsonProperty("replicatedDataSize")
+  private long replicatedDataSize;
+
+  /** Amount of data mapped to all keys and files on a single DN. */
+  @JsonProperty("unReplicatedDataSize")
+  private long unReplicatedDataSize;
+
+  /** The number of keys based on limit under the request path. */
+  @JsonProperty("keyCount")
+  private int count;
+
+  /** last key sent. */
+  @JsonProperty("lastKey")
+  @JsonInclude(JsonInclude.Include.NON_EMPTY)
+  private String lastKey;
+
+  /** list of keys. */
+  @JsonProperty("keys")
+  private List<KeyEntityInfo> keys;

Review Comment:
   do count can be derived from keys field as its list and its size can give 
same info



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/OMDBInsightEndpoint.java:
##########
@@ -674,6 +685,645 @@ public Response getDeletedDirectorySummary() {
     return Response.ok(dirSummary).build();
   }
 
+  /**
+   * This API will list out limited 'count' number of keys after applying 
below filters in API parameters:
+   * Default Values of API param filters:
+   *    -- replicationType - empty string and filter will not be applied, so 
list out all keys irrespective of
+   *       replication type.
+   *    -- creationTime - empty string and filter will not be applied, so list 
out keys irrespective of age.
+   *    -- keySize - 0 bytes, which means all keys greater than zero bytes 
will be listed, effectively all.
+   *    -- startPrefix - /
+   *    -- prevKey - ""
+   *    -- limit - 1000
+   *
+   * @param replicationType Filter for RATIS or EC replication keys
+   * @param creationDate Filter for keys created after creationDate in 
"MM-dd-yyyy HH:mm:ss" string format.
+   * @param keySize Filter for Keys greater than keySize in bytes.
+   * @param startPrefix Filter for startPrefix path.
+   * @param prevKey rocksDB last key of page requested.
+   * @param limit Filter for limited count of keys.
+   *
+   * @return the list of keys in JSON structured format as per respective 
bucket layout.
+   *
+   * Now lets consider, we have following OBS, LEGACY and FSO bucket key/files 
namespace tree structure
+   *
+   * For OBS Bucket
+   *
+   * /volume1/obs-bucket/key1
+   * /volume1/obs-bucket/key1/key2
+   * /volume1/obs-bucket/key1/key2/key3
+   * /volume1/obs-bucket/key4
+   * /volume1/obs-bucket/key5
+   * /volume1/obs-bucket/key6
+   * For LEGACY Bucket
+   *
+   * /volume1/legacy-bucket/key
+   * /volume1/legacy-bucket/key1/key2
+   * /volume1/legacy-bucket/key1/key2/key3
+   * /volume1/legacy-bucket/key4
+   * /volume1/legacy-bucket/key5
+   * /volume1/legacy-bucket/key6
+   * For FSO Bucket
+   *
+   * /volume1/fso-bucket/dir1/dir2/dir3
+   * /volume1/fso-bucket/dir1/testfile
+   * /volume1/fso-bucket/dir1/file1
+   * /volume1/fso-bucket/dir1/dir2/testfile
+   * /volume1/fso-bucket/dir1/dir2/file1
+   * /volume1/fso-bucket/dir1/dir2/dir3/testfile
+   * /volume1/fso-bucket/dir1/dir2/dir3/file1
+   * Input Request for OBS bucket:
+   *
+   *    
`api/v1/keys/listKeys?startPrefix=/volume1/obs-bucket&limit=2&replicationType=RATIS`
+   * Output Response:
+   *
+   * {
+   *    "status": "OK",
+   *    "path": "/volume1/obs-bucket",
+   *    "replicatedDataSize": 20971520,
+   *    "unReplicatedDataSize": 20971520,
+   *    "keyCount": 2,
+   *    "lastKey": "/volume1/obs-bucket/key1/key2",
+   *    "keys": [
+   *        {
+   *            "key": "/volume1/obs-bucket/key1",
+   *            "path": "key1",
+   *            "inStateSince": 1715174266126,
+   *            "size": 10485760,
+   *            "replicatedSize": 10485760,
+   *            "replicationInfo": {
+   *                "replicationFactor": "ONE",
+   *                "requiredNodes": 1,
+   *                "replicationType": "RATIS"
+   *            },
+   *            "creationTime": 1715174266126,
+   *            "modificationTime": 1715174267480,
+   *            "isKey": true
+   *        },
+   *        {
+   *            "key": "/volume1/obs-bucket/key1/key2",
+   *            "path": "key1/key2",

Review Comment:
   path is filename or fullpath? if only filename, this name need change to 
keyName



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/OMDBInsightEndpoint.java:
##########
@@ -674,6 +685,645 @@ public Response getDeletedDirectorySummary() {
     return Response.ok(dirSummary).build();
   }
 
+  /**
+   * This API will list out limited 'count' number of keys after applying 
below filters in API parameters:
+   * Default Values of API param filters:
+   *    -- replicationType - empty string and filter will not be applied, so 
list out all keys irrespective of
+   *       replication type.
+   *    -- creationTime - empty string and filter will not be applied, so list 
out keys irrespective of age.
+   *    -- keySize - 0 bytes, which means all keys greater than zero bytes 
will be listed, effectively all.
+   *    -- startPrefix - /
+   *    -- prevKey - ""
+   *    -- limit - 1000
+   *
+   * @param replicationType Filter for RATIS or EC replication keys
+   * @param creationDate Filter for keys created after creationDate in 
"MM-dd-yyyy HH:mm:ss" string format.
+   * @param keySize Filter for Keys greater than keySize in bytes.
+   * @param startPrefix Filter for startPrefix path.
+   * @param prevKey rocksDB last key of page requested.
+   * @param limit Filter for limited count of keys.
+   *
+   * @return the list of keys in JSON structured format as per respective 
bucket layout.
+   *
+   * Now lets consider, we have following OBS, LEGACY and FSO bucket key/files 
namespace tree structure
+   *
+   * For OBS Bucket
+   *
+   * /volume1/obs-bucket/key1
+   * /volume1/obs-bucket/key1/key2
+   * /volume1/obs-bucket/key1/key2/key3
+   * /volume1/obs-bucket/key4
+   * /volume1/obs-bucket/key5
+   * /volume1/obs-bucket/key6
+   * For LEGACY Bucket
+   *
+   * /volume1/legacy-bucket/key
+   * /volume1/legacy-bucket/key1/key2
+   * /volume1/legacy-bucket/key1/key2/key3
+   * /volume1/legacy-bucket/key4
+   * /volume1/legacy-bucket/key5
+   * /volume1/legacy-bucket/key6
+   * For FSO Bucket
+   *
+   * /volume1/fso-bucket/dir1/dir2/dir3
+   * /volume1/fso-bucket/dir1/testfile
+   * /volume1/fso-bucket/dir1/file1
+   * /volume1/fso-bucket/dir1/dir2/testfile
+   * /volume1/fso-bucket/dir1/dir2/file1
+   * /volume1/fso-bucket/dir1/dir2/dir3/testfile
+   * /volume1/fso-bucket/dir1/dir2/dir3/file1
+   * Input Request for OBS bucket:
+   *
+   *    
`api/v1/keys/listKeys?startPrefix=/volume1/obs-bucket&limit=2&replicationType=RATIS`
+   * Output Response:
+   *
+   * {
+   *    "status": "OK",
+   *    "path": "/volume1/obs-bucket",
+   *    "replicatedDataSize": 20971520,
+   *    "unReplicatedDataSize": 20971520,
+   *    "keyCount": 2,
+   *    "lastKey": "/volume1/obs-bucket/key1/key2",
+   *    "keys": [
+   *        {
+   *            "key": "/volume1/obs-bucket/key1",
+   *            "path": "key1",
+   *            "inStateSince": 1715174266126,
+   *            "size": 10485760,
+   *            "replicatedSize": 10485760,
+   *            "replicationInfo": {
+   *                "replicationFactor": "ONE",
+   *                "requiredNodes": 1,
+   *                "replicationType": "RATIS"
+   *            },
+   *            "creationTime": 1715174266126,
+   *            "modificationTime": 1715174267480,
+   *            "isKey": true
+   *        },
+   *        {
+   *            "key": "/volume1/obs-bucket/key1/key2",
+   *            "path": "key1/key2",
+   *            "inStateSince": 1715174269510,
+   *            "size": 10485760,
+   *            "replicatedSize": 10485760,
+   *            "replicationInfo": {
+   *                "replicationFactor": "ONE",
+   *                "requiredNodes": 1,
+   *                "replicationType": "RATIS"
+   *            },
+   *            "creationTime": 1715174269510,
+   *            "modificationTime": 1715174270410,
+   *            "isKey": true
+   *        }
+   *    ]
+   * }
+   * Input Request for FSO bucket:
+   *
+   *        
`api/v1/keys/listKeys?startPrefix=/volume1/fso-bucket&limit=2&replicationType=RATIS`
+   * Output Response:
+   *
+   * {
+   *     "status": "OK",
+   *     "path": "/volume1/fso-bucket",
+   *     "replicatedDataSize": 62914560,
+   *     "unReplicatedDataSize": 20971520,
+   *     "keyCount": 2,
+   *     "lastKey": 
"/-9223372036854775552/-9223372036854775040/-9223372036854774525/testfile",
+   *     "keys": [
+   *         {
+   *             "key": 
"/-9223372036854775552/-9223372036854775040/-9223372036854774525/file1",
+   *             "path": "file1",
+   *             "inStateSince": 1715174237440,
+   *             "size": 10485760,
+   *             "replicatedSize": 31457280,
+   *             "replicationInfo": {
+   *                 "replicationFactor": "THREE",
+   *                 "requiredNodes": 3,
+   *                 "replicationType": "RATIS"
+   *             },
+   *             "creationTime": 1715174237440,
+   *             "modificationTime": 1715174238161,
+   *             "isKey": true
+   *         },
+   *         {
+   *             "key": 
"/-9223372036854775552/-9223372036854775040/-9223372036854774525/testfile",
+   *             "path": "testfile",
+   *             "inStateSince": 1715174234840,
+   *             "size": 10485760,
+   *             "replicatedSize": 31457280,
+   *             "replicationInfo": {
+   *                 "replicationFactor": "THREE",
+   *                 "requiredNodes": 3,
+   *                 "replicationType": "RATIS"
+   *             },
+   *             "creationTime": 1715174234840,
+   *             "modificationTime": 1715174235562,
+   *             "isKey": true
+   *         }
+   *     ]
+   * }
+   * Input Request for Legacy bucket:
+   *
+   *        
`api/v1/keys/listKeys?startPrefix=/volume1/legacy-bucket&limit=2&replicationType=RATIS`
+   * Output Response:
+   *
+   * {
+   *     "status": "OK",
+   *     "path": "/volume1/legacy-bucket",
+   *     "replicatedDataSize": 52428800,
+   *     "unReplicatedDataSize": 52428800,
+   *     "keyCount": 2,
+   *     "lastKey": "/volume1/legacy-bucket/key1/key2",
+   *     "keys": [
+   *         {
+   *             "key": "/volume1/legacy-bucket/key1",
+   *             "path": "key1",
+   *             "inStateSince": 1715174303702,
+   *             "size": 10485760,
+   *             "replicatedSize": 10485760,
+   *             "replicationInfo": {
+   *                 "replicationFactor": "ONE",
+   *                 "requiredNodes": 1,
+   *                 "replicationType": "RATIS"
+   *             },
+   *             "creationTime": 1715174303702,
+   *             "modificationTime": 1715174304619,
+   *             "isKey": true
+   *         },
+   *         {
+   *             "key": "/volume1/legacy-bucket/key1/key2",
+   *             "path": "key1/key2",
+   *             "inStateSince": 1715174306641,
+   *             "size": 41943040,
+   *             "replicatedSize": 41943040,
+   *             "replicationInfo": {
+   *                 "replicationFactor": "ONE",
+   *                 "requiredNodes": 1,
+   *                 "replicationType": "RATIS"
+   *             },
+   *             "creationTime": 1715174306641,
+   *             "modificationTime": 1715174307994,
+   *             "isKey": true
+   *         }
+   *     ]
+   * }
+   * ********************************************************
+   * @throws IOException
+   */
+  @GET
+  @Path("/listKeys")
+  @SuppressWarnings("methodlength")
+  public Response listKeys(@QueryParam("replicationType") String 
replicationType,
+                           @QueryParam("creationDate") String creationDate,
+                           @DefaultValue(DEFAULT_KEY_SIZE) 
@QueryParam("keySize") long keySize,
+                           @DefaultValue(OM_KEY_PREFIX) 
@QueryParam("startPrefix") String startPrefix,
+                           @DefaultValue(StringUtils.EMPTY) 
@QueryParam(RECON_QUERY_PREVKEY) String prevKey,
+                           @DefaultValue(DEFAULT_FETCH_COUNT) 
@QueryParam("limit") int limit) {
+
+
+    // This API supports startPrefix from bucket level.
+    if (startPrefix == null || startPrefix.length() == 0) {
+      return Response.status(Response.Status.BAD_REQUEST).build();
+    }
+    String[] names = startPrefix.split(OM_KEY_PREFIX);
+    if (names.length < 3) {
+      return Response.status(Response.Status.BAD_REQUEST).build();
+    }
+    ListKeysResponse listKeysResponse = new ListKeysResponse();
+    if (!ReconUtils.isInitializationComplete(omMetadataManager)) {
+      listKeysResponse.setStatus(ResponseStatus.INITIALIZING);
+      return Response.ok(listKeysResponse).build();
+    }
+    ParamInfo paramInfo = new ParamInfo(replicationType, creationDate, 
keySize, startPrefix, prevKey,
+        limit, false, "");
+    Response response = getListKeysResponse(paramInfo);
+    if (response.getEntity() instanceof ListKeysResponse) {
+      listKeysResponse = (ListKeysResponse) response.getEntity();
+    }
+
+    List<KeyEntityInfo> keyInfoList = listKeysResponse.getKeys();
+    if (!keyInfoList.isEmpty()) {
+      listKeysResponse.setLastKey(keyInfoList.get(keyInfoList.size() - 
1).getKey());
+    }
+    listKeysResponse.setCount(keyInfoList.size());
+    return Response.ok(listKeysResponse).build();
+  }
+
+  private Response getListKeysResponse(ParamInfo paramInfo) {
+    try {
+      paramInfo.setLimit(Math.max(0, paramInfo.getLimit())); // Ensure limit 
is non-negative
+      ListKeysResponse listKeysResponse = new ListKeysResponse();
+      listKeysResponse.setPath(paramInfo.getStartPrefix());
+      long replicatedTotal = 0;
+      long unreplicatedTotal = 0;
+      boolean keysFound = false; // Flag to track if any keys are found
+
+      // Search keys from non-FSO layout.
+      Map<String, OmKeyInfo> obsKeys;
+      Table<String, OmKeyInfo> keyTable =
+          omMetadataManager.getKeyTable(BucketLayout.LEGACY);
+      obsKeys = retrieveKeysFromTable(keyTable, paramInfo);
+      for (Map.Entry<String, OmKeyInfo> entry : obsKeys.entrySet()) {
+        keysFound = true;
+        KeyEntityInfo keyEntityInfo =
+            createKeyEntityInfoFromOmKeyInfo(entry.getKey(), entry.getValue());
+
+        listKeysResponse.getKeys().add(keyEntityInfo);
+        replicatedTotal += entry.getValue().getReplicatedSize();
+        unreplicatedTotal += entry.getValue().getDataSize();
+      }
+
+      // Search keys from FSO layout.
+      Map<String, OmKeyInfo> fsoKeys = searchKeysInFSO(paramInfo);
+      for (Map.Entry<String, OmKeyInfo> entry : fsoKeys.entrySet()) {
+        keysFound = true;
+        KeyEntityInfo keyEntityInfo =
+            createKeyEntityInfoFromOmKeyInfo(entry.getKey(), entry.getValue());
+
+        listKeysResponse.getKeys().add(keyEntityInfo);
+        replicatedTotal += entry.getValue().getReplicatedSize();
+        unreplicatedTotal += entry.getValue().getDataSize();
+      }
+
+      // If no keys were found, return a response indicating that no keys 
matched
+      if (!keysFound) {
+        return noMatchedKeysResponse(paramInfo.getStartPrefix());
+      }
+
+      // Set the aggregated totals in the response
+      listKeysResponse.setReplicatedDataSize(replicatedTotal);
+      listKeysResponse.setUnReplicatedDataSize(unreplicatedTotal);
+
+      return Response.ok(listKeysResponse).build();
+    } catch (IOException e) {
+      return createInternalServerErrorResponse(
+          "Error searching keys in OM DB: " + e.getMessage());
+    } catch (IllegalArgumentException e) {
+      return createBadRequestResponse(
+          "Invalid startPrefix: " + e.getMessage());
+    }
+  }
+
+  public Map<String, OmKeyInfo> searchKeysInFSO(ParamInfo paramInfo)
+      throws IOException, IllegalArgumentException {
+    Map<String, OmKeyInfo> matchedKeys = new LinkedHashMap<>();
+    // Convert the search prefix to an object path for FSO buckets
+    String startPrefixObjectPath = 
convertToObjectPath(paramInfo.getStartPrefix());
+    String[] names = parseRequestPath(startPrefixObjectPath);
+    Table<String, OmKeyInfo> fileTable =
+        omMetadataManager.getKeyTable(BucketLayout.FILE_SYSTEM_OPTIMIZED);
+
+    // If names.length > 2, then the search prefix is at the volume or bucket 
level hence
+    // no need to find parent or extract id's or find subpaths as the 
fileTable is
+    // suitable for volume and bucket level search
+    if (names.length > 2) {
+      // Fetch the parent ID to search for
+      long parentId = Long.parseLong(names[names.length - 1]);
+
+      // Fetch the nameSpaceSummary for the parent ID
+      NSSummary parentSummary =
+          reconNamespaceSummaryManager.getNSSummary(parentId);
+      if (parentSummary == null) {
+        return matchedKeys;
+      }
+      List<String> subPaths = new ArrayList<>();
+      // Add the initial search prefix object path because it can have both 
files and subdirectories with files.
+      subPaths.add(startPrefixObjectPath);
+
+      // Recursively gather all subpaths
+      gatherSubPaths(parentId, subPaths, Long.parseLong(names[0]), 
Long.parseLong(names[1]));
+      // Iterate over the subpaths and retrieve the files
+      for (String subPath : subPaths) {
+        paramInfo.setStartPrefix(subPath);
+        paramInfo.setLimit(paramInfo.getLimit() - matchedKeys.size());

Review Comment:
   IMO, we should update limit just after updating matchedKeys



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/OMDBInsightEndpoint.java:
##########
@@ -674,6 +685,645 @@ public Response getDeletedDirectorySummary() {
     return Response.ok(dirSummary).build();
   }
 
+  /**
+   * This API will list out limited 'count' number of keys after applying 
below filters in API parameters:
+   * Default Values of API param filters:
+   *    -- replicationType - empty string and filter will not be applied, so 
list out all keys irrespective of
+   *       replication type.
+   *    -- creationTime - empty string and filter will not be applied, so list 
out keys irrespective of age.
+   *    -- keySize - 0 bytes, which means all keys greater than zero bytes 
will be listed, effectively all.
+   *    -- startPrefix - /
+   *    -- prevKey - ""
+   *    -- limit - 1000
+   *
+   * @param replicationType Filter for RATIS or EC replication keys
+   * @param creationDate Filter for keys created after creationDate in 
"MM-dd-yyyy HH:mm:ss" string format.
+   * @param keySize Filter for Keys greater than keySize in bytes.
+   * @param startPrefix Filter for startPrefix path.
+   * @param prevKey rocksDB last key of page requested.
+   * @param limit Filter for limited count of keys.
+   *
+   * @return the list of keys in JSON structured format as per respective 
bucket layout.
+   *
+   * Now lets consider, we have following OBS, LEGACY and FSO bucket key/files 
namespace tree structure
+   *
+   * For OBS Bucket
+   *
+   * /volume1/obs-bucket/key1
+   * /volume1/obs-bucket/key1/key2
+   * /volume1/obs-bucket/key1/key2/key3
+   * /volume1/obs-bucket/key4
+   * /volume1/obs-bucket/key5
+   * /volume1/obs-bucket/key6
+   * For LEGACY Bucket
+   *
+   * /volume1/legacy-bucket/key
+   * /volume1/legacy-bucket/key1/key2
+   * /volume1/legacy-bucket/key1/key2/key3
+   * /volume1/legacy-bucket/key4
+   * /volume1/legacy-bucket/key5
+   * /volume1/legacy-bucket/key6
+   * For FSO Bucket
+   *
+   * /volume1/fso-bucket/dir1/dir2/dir3
+   * /volume1/fso-bucket/dir1/testfile
+   * /volume1/fso-bucket/dir1/file1
+   * /volume1/fso-bucket/dir1/dir2/testfile
+   * /volume1/fso-bucket/dir1/dir2/file1
+   * /volume1/fso-bucket/dir1/dir2/dir3/testfile
+   * /volume1/fso-bucket/dir1/dir2/dir3/file1
+   * Input Request for OBS bucket:
+   *
+   *    
`api/v1/keys/listKeys?startPrefix=/volume1/obs-bucket&limit=2&replicationType=RATIS`
+   * Output Response:
+   *
+   * {
+   *    "status": "OK",
+   *    "path": "/volume1/obs-bucket",
+   *    "replicatedDataSize": 20971520,
+   *    "unReplicatedDataSize": 20971520,
+   *    "keyCount": 2,
+   *    "lastKey": "/volume1/obs-bucket/key1/key2",
+   *    "keys": [
+   *        {
+   *            "key": "/volume1/obs-bucket/key1",
+   *            "path": "key1",
+   *            "inStateSince": 1715174266126,
+   *            "size": 10485760,
+   *            "replicatedSize": 10485760,
+   *            "replicationInfo": {
+   *                "replicationFactor": "ONE",
+   *                "requiredNodes": 1,
+   *                "replicationType": "RATIS"
+   *            },
+   *            "creationTime": 1715174266126,
+   *            "modificationTime": 1715174267480,
+   *            "isKey": true
+   *        },
+   *        {
+   *            "key": "/volume1/obs-bucket/key1/key2",
+   *            "path": "key1/key2",
+   *            "inStateSince": 1715174269510,
+   *            "size": 10485760,
+   *            "replicatedSize": 10485760,
+   *            "replicationInfo": {
+   *                "replicationFactor": "ONE",
+   *                "requiredNodes": 1,
+   *                "replicationType": "RATIS"
+   *            },
+   *            "creationTime": 1715174269510,
+   *            "modificationTime": 1715174270410,
+   *            "isKey": true
+   *        }
+   *    ]
+   * }
+   * Input Request for FSO bucket:
+   *
+   *        
`api/v1/keys/listKeys?startPrefix=/volume1/fso-bucket&limit=2&replicationType=RATIS`
+   * Output Response:
+   *
+   * {
+   *     "status": "OK",
+   *     "path": "/volume1/fso-bucket",
+   *     "replicatedDataSize": 62914560,
+   *     "unReplicatedDataSize": 20971520,
+   *     "keyCount": 2,
+   *     "lastKey": 
"/-9223372036854775552/-9223372036854775040/-9223372036854774525/testfile",
+   *     "keys": [
+   *         {
+   *             "key": 
"/-9223372036854775552/-9223372036854775040/-9223372036854774525/file1",
+   *             "path": "file1",
+   *             "inStateSince": 1715174237440,
+   *             "size": 10485760,
+   *             "replicatedSize": 31457280,
+   *             "replicationInfo": {
+   *                 "replicationFactor": "THREE",
+   *                 "requiredNodes": 3,
+   *                 "replicationType": "RATIS"
+   *             },
+   *             "creationTime": 1715174237440,
+   *             "modificationTime": 1715174238161,
+   *             "isKey": true
+   *         },
+   *         {
+   *             "key": 
"/-9223372036854775552/-9223372036854775040/-9223372036854774525/testfile",
+   *             "path": "testfile",
+   *             "inStateSince": 1715174234840,
+   *             "size": 10485760,
+   *             "replicatedSize": 31457280,
+   *             "replicationInfo": {
+   *                 "replicationFactor": "THREE",
+   *                 "requiredNodes": 3,
+   *                 "replicationType": "RATIS"
+   *             },
+   *             "creationTime": 1715174234840,
+   *             "modificationTime": 1715174235562,
+   *             "isKey": true
+   *         }
+   *     ]
+   * }
+   * Input Request for Legacy bucket:
+   *
+   *        
`api/v1/keys/listKeys?startPrefix=/volume1/legacy-bucket&limit=2&replicationType=RATIS`
+   * Output Response:
+   *
+   * {
+   *     "status": "OK",
+   *     "path": "/volume1/legacy-bucket",
+   *     "replicatedDataSize": 52428800,
+   *     "unReplicatedDataSize": 52428800,
+   *     "keyCount": 2,
+   *     "lastKey": "/volume1/legacy-bucket/key1/key2",
+   *     "keys": [
+   *         {
+   *             "key": "/volume1/legacy-bucket/key1",
+   *             "path": "key1",
+   *             "inStateSince": 1715174303702,
+   *             "size": 10485760,
+   *             "replicatedSize": 10485760,
+   *             "replicationInfo": {
+   *                 "replicationFactor": "ONE",
+   *                 "requiredNodes": 1,
+   *                 "replicationType": "RATIS"
+   *             },
+   *             "creationTime": 1715174303702,
+   *             "modificationTime": 1715174304619,
+   *             "isKey": true
+   *         },
+   *         {
+   *             "key": "/volume1/legacy-bucket/key1/key2",
+   *             "path": "key1/key2",
+   *             "inStateSince": 1715174306641,
+   *             "size": 41943040,
+   *             "replicatedSize": 41943040,
+   *             "replicationInfo": {
+   *                 "replicationFactor": "ONE",
+   *                 "requiredNodes": 1,
+   *                 "replicationType": "RATIS"
+   *             },
+   *             "creationTime": 1715174306641,
+   *             "modificationTime": 1715174307994,
+   *             "isKey": true
+   *         }
+   *     ]
+   * }
+   * ********************************************************
+   * @throws IOException
+   */
+  @GET
+  @Path("/listKeys")
+  @SuppressWarnings("methodlength")
+  public Response listKeys(@QueryParam("replicationType") String 
replicationType,
+                           @QueryParam("creationDate") String creationDate,
+                           @DefaultValue(DEFAULT_KEY_SIZE) 
@QueryParam("keySize") long keySize,
+                           @DefaultValue(OM_KEY_PREFIX) 
@QueryParam("startPrefix") String startPrefix,
+                           @DefaultValue(StringUtils.EMPTY) 
@QueryParam(RECON_QUERY_PREVKEY) String prevKey,
+                           @DefaultValue(DEFAULT_FETCH_COUNT) 
@QueryParam("limit") int limit) {
+
+
+    // This API supports startPrefix from bucket level.
+    if (startPrefix == null || startPrefix.length() == 0) {
+      return Response.status(Response.Status.BAD_REQUEST).build();
+    }
+    String[] names = startPrefix.split(OM_KEY_PREFIX);
+    if (names.length < 3) {
+      return Response.status(Response.Status.BAD_REQUEST).build();
+    }
+    ListKeysResponse listKeysResponse = new ListKeysResponse();
+    if (!ReconUtils.isInitializationComplete(omMetadataManager)) {
+      listKeysResponse.setStatus(ResponseStatus.INITIALIZING);
+      return Response.ok(listKeysResponse).build();
+    }
+    ParamInfo paramInfo = new ParamInfo(replicationType, creationDate, 
keySize, startPrefix, prevKey,
+        limit, false, "");
+    Response response = getListKeysResponse(paramInfo);
+    if (response.getEntity() instanceof ListKeysResponse) {
+      listKeysResponse = (ListKeysResponse) response.getEntity();
+    }
+
+    List<KeyEntityInfo> keyInfoList = listKeysResponse.getKeys();
+    if (!keyInfoList.isEmpty()) {
+      listKeysResponse.setLastKey(keyInfoList.get(keyInfoList.size() - 
1).getKey());
+    }
+    listKeysResponse.setCount(keyInfoList.size());
+    return Response.ok(listKeysResponse).build();
+  }
+
+  private Response getListKeysResponse(ParamInfo paramInfo) {
+    try {
+      paramInfo.setLimit(Math.max(0, paramInfo.getLimit())); // Ensure limit 
is non-negative
+      ListKeysResponse listKeysResponse = new ListKeysResponse();
+      listKeysResponse.setPath(paramInfo.getStartPrefix());
+      long replicatedTotal = 0;
+      long unreplicatedTotal = 0;
+      boolean keysFound = false; // Flag to track if any keys are found
+
+      // Search keys from non-FSO layout.
+      Map<String, OmKeyInfo> obsKeys;
+      Table<String, OmKeyInfo> keyTable =
+          omMetadataManager.getKeyTable(BucketLayout.LEGACY);
+      obsKeys = retrieveKeysFromTable(keyTable, paramInfo);
+      for (Map.Entry<String, OmKeyInfo> entry : obsKeys.entrySet()) {
+        keysFound = true;
+        KeyEntityInfo keyEntityInfo =
+            createKeyEntityInfoFromOmKeyInfo(entry.getKey(), entry.getValue());
+
+        listKeysResponse.getKeys().add(keyEntityInfo);
+        replicatedTotal += entry.getValue().getReplicatedSize();
+        unreplicatedTotal += entry.getValue().getDataSize();
+      }
+
+      // Search keys from FSO layout.
+      Map<String, OmKeyInfo> fsoKeys = searchKeysInFSO(paramInfo);
+      for (Map.Entry<String, OmKeyInfo> entry : fsoKeys.entrySet()) {
+        keysFound = true;
+        KeyEntityInfo keyEntityInfo =
+            createKeyEntityInfoFromOmKeyInfo(entry.getKey(), entry.getValue());
+
+        listKeysResponse.getKeys().add(keyEntityInfo);
+        replicatedTotal += entry.getValue().getReplicatedSize();
+        unreplicatedTotal += entry.getValue().getDataSize();
+      }
+
+      // If no keys were found, return a response indicating that no keys 
matched
+      if (!keysFound) {
+        return noMatchedKeysResponse(paramInfo.getStartPrefix());
+      }
+
+      // Set the aggregated totals in the response
+      listKeysResponse.setReplicatedDataSize(replicatedTotal);
+      listKeysResponse.setUnReplicatedDataSize(unreplicatedTotal);
+
+      return Response.ok(listKeysResponse).build();
+    } catch (IOException e) {
+      return createInternalServerErrorResponse(
+          "Error searching keys in OM DB: " + e.getMessage());
+    } catch (IllegalArgumentException e) {
+      return createBadRequestResponse(
+          "Invalid startPrefix: " + e.getMessage());
+    }
+  }
+
+  public Map<String, OmKeyInfo> searchKeysInFSO(ParamInfo paramInfo)
+      throws IOException, IllegalArgumentException {
+    Map<String, OmKeyInfo> matchedKeys = new LinkedHashMap<>();
+    // Convert the search prefix to an object path for FSO buckets
+    String startPrefixObjectPath = 
convertToObjectPath(paramInfo.getStartPrefix());
+    String[] names = parseRequestPath(startPrefixObjectPath);
+    Table<String, OmKeyInfo> fileTable =
+        omMetadataManager.getKeyTable(BucketLayout.FILE_SYSTEM_OPTIMIZED);
+
+    // If names.length > 2, then the search prefix is at the volume or bucket 
level hence
+    // no need to find parent or extract id's or find subpaths as the 
fileTable is
+    // suitable for volume and bucket level search
+    if (names.length > 2) {
+      // Fetch the parent ID to search for
+      long parentId = Long.parseLong(names[names.length - 1]);
+
+      // Fetch the nameSpaceSummary for the parent ID
+      NSSummary parentSummary =
+          reconNamespaceSummaryManager.getNSSummary(parentId);
+      if (parentSummary == null) {
+        return matchedKeys;
+      }
+      List<String> subPaths = new ArrayList<>();
+      // Add the initial search prefix object path because it can have both 
files and subdirectories with files.
+      subPaths.add(startPrefixObjectPath);
+
+      // Recursively gather all subpaths
+      gatherSubPaths(parentId, subPaths, Long.parseLong(names[0]), 
Long.parseLong(names[1]));
+      // Iterate over the subpaths and retrieve the files
+      for (String subPath : subPaths) {
+        paramInfo.setStartPrefix(subPath);
+        paramInfo.setLimit(paramInfo.getLimit() - matchedKeys.size());
+        matchedKeys.putAll(
+            retrieveKeysFromTable(fileTable, paramInfo));
+        if (matchedKeys.size() >= paramInfo.getLimit()) {

Review Comment:
   It need check for paramInfo.geetLimit() > 0, this check gives less count as,
   limit=10, matchedKeys=6 ==> new limit=4
   if (6 >= 4) is true and break, but still having limit of "4" to be filled.



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/OMDBInsightEndpoint.java:
##########
@@ -674,6 +685,645 @@ public Response getDeletedDirectorySummary() {
     return Response.ok(dirSummary).build();
   }
 
+  /**
+   * This API will list out limited 'count' number of keys after applying 
below filters in API parameters:
+   * Default Values of API param filters:
+   *    -- replicationType - empty string and filter will not be applied, so 
list out all keys irrespective of
+   *       replication type.
+   *    -- creationTime - empty string and filter will not be applied, so list 
out keys irrespective of age.
+   *    -- keySize - 0 bytes, which means all keys greater than zero bytes 
will be listed, effectively all.
+   *    -- startPrefix - /
+   *    -- prevKey - ""
+   *    -- limit - 1000
+   *
+   * @param replicationType Filter for RATIS or EC replication keys
+   * @param creationDate Filter for keys created after creationDate in 
"MM-dd-yyyy HH:mm:ss" string format.
+   * @param keySize Filter for Keys greater than keySize in bytes.
+   * @param startPrefix Filter for startPrefix path.
+   * @param prevKey rocksDB last key of page requested.
+   * @param limit Filter for limited count of keys.
+   *
+   * @return the list of keys in JSON structured format as per respective 
bucket layout.
+   *
+   * Now lets consider, we have following OBS, LEGACY and FSO bucket key/files 
namespace tree structure
+   *
+   * For OBS Bucket
+   *
+   * /volume1/obs-bucket/key1
+   * /volume1/obs-bucket/key1/key2
+   * /volume1/obs-bucket/key1/key2/key3
+   * /volume1/obs-bucket/key4
+   * /volume1/obs-bucket/key5
+   * /volume1/obs-bucket/key6
+   * For LEGACY Bucket
+   *
+   * /volume1/legacy-bucket/key
+   * /volume1/legacy-bucket/key1/key2
+   * /volume1/legacy-bucket/key1/key2/key3
+   * /volume1/legacy-bucket/key4
+   * /volume1/legacy-bucket/key5
+   * /volume1/legacy-bucket/key6
+   * For FSO Bucket
+   *
+   * /volume1/fso-bucket/dir1/dir2/dir3
+   * /volume1/fso-bucket/dir1/testfile
+   * /volume1/fso-bucket/dir1/file1
+   * /volume1/fso-bucket/dir1/dir2/testfile
+   * /volume1/fso-bucket/dir1/dir2/file1
+   * /volume1/fso-bucket/dir1/dir2/dir3/testfile
+   * /volume1/fso-bucket/dir1/dir2/dir3/file1
+   * Input Request for OBS bucket:
+   *
+   *    
`api/v1/keys/listKeys?startPrefix=/volume1/obs-bucket&limit=2&replicationType=RATIS`
+   * Output Response:
+   *
+   * {
+   *    "status": "OK",
+   *    "path": "/volume1/obs-bucket",
+   *    "replicatedDataSize": 20971520,
+   *    "unReplicatedDataSize": 20971520,
+   *    "keyCount": 2,
+   *    "lastKey": "/volume1/obs-bucket/key1/key2",
+   *    "keys": [
+   *        {
+   *            "key": "/volume1/obs-bucket/key1",
+   *            "path": "key1",
+   *            "inStateSince": 1715174266126,
+   *            "size": 10485760,
+   *            "replicatedSize": 10485760,
+   *            "replicationInfo": {
+   *                "replicationFactor": "ONE",
+   *                "requiredNodes": 1,
+   *                "replicationType": "RATIS"
+   *            },
+   *            "creationTime": 1715174266126,
+   *            "modificationTime": 1715174267480,
+   *            "isKey": true
+   *        },
+   *        {
+   *            "key": "/volume1/obs-bucket/key1/key2",
+   *            "path": "key1/key2",
+   *            "inStateSince": 1715174269510,
+   *            "size": 10485760,
+   *            "replicatedSize": 10485760,
+   *            "replicationInfo": {
+   *                "replicationFactor": "ONE",
+   *                "requiredNodes": 1,
+   *                "replicationType": "RATIS"
+   *            },
+   *            "creationTime": 1715174269510,
+   *            "modificationTime": 1715174270410,
+   *            "isKey": true
+   *        }
+   *    ]
+   * }
+   * Input Request for FSO bucket:
+   *
+   *        
`api/v1/keys/listKeys?startPrefix=/volume1/fso-bucket&limit=2&replicationType=RATIS`
+   * Output Response:
+   *
+   * {
+   *     "status": "OK",
+   *     "path": "/volume1/fso-bucket",
+   *     "replicatedDataSize": 62914560,
+   *     "unReplicatedDataSize": 20971520,
+   *     "keyCount": 2,
+   *     "lastKey": 
"/-9223372036854775552/-9223372036854775040/-9223372036854774525/testfile",
+   *     "keys": [
+   *         {
+   *             "key": 
"/-9223372036854775552/-9223372036854775040/-9223372036854774525/file1",
+   *             "path": "file1",
+   *             "inStateSince": 1715174237440,
+   *             "size": 10485760,
+   *             "replicatedSize": 31457280,
+   *             "replicationInfo": {
+   *                 "replicationFactor": "THREE",
+   *                 "requiredNodes": 3,
+   *                 "replicationType": "RATIS"
+   *             },
+   *             "creationTime": 1715174237440,
+   *             "modificationTime": 1715174238161,
+   *             "isKey": true
+   *         },
+   *         {
+   *             "key": 
"/-9223372036854775552/-9223372036854775040/-9223372036854774525/testfile",
+   *             "path": "testfile",
+   *             "inStateSince": 1715174234840,
+   *             "size": 10485760,
+   *             "replicatedSize": 31457280,
+   *             "replicationInfo": {
+   *                 "replicationFactor": "THREE",
+   *                 "requiredNodes": 3,
+   *                 "replicationType": "RATIS"
+   *             },
+   *             "creationTime": 1715174234840,
+   *             "modificationTime": 1715174235562,
+   *             "isKey": true
+   *         }
+   *     ]
+   * }
+   * Input Request for Legacy bucket:
+   *
+   *        
`api/v1/keys/listKeys?startPrefix=/volume1/legacy-bucket&limit=2&replicationType=RATIS`
+   * Output Response:
+   *
+   * {
+   *     "status": "OK",
+   *     "path": "/volume1/legacy-bucket",
+   *     "replicatedDataSize": 52428800,
+   *     "unReplicatedDataSize": 52428800,
+   *     "keyCount": 2,
+   *     "lastKey": "/volume1/legacy-bucket/key1/key2",
+   *     "keys": [
+   *         {
+   *             "key": "/volume1/legacy-bucket/key1",
+   *             "path": "key1",
+   *             "inStateSince": 1715174303702,
+   *             "size": 10485760,
+   *             "replicatedSize": 10485760,
+   *             "replicationInfo": {
+   *                 "replicationFactor": "ONE",
+   *                 "requiredNodes": 1,
+   *                 "replicationType": "RATIS"
+   *             },
+   *             "creationTime": 1715174303702,
+   *             "modificationTime": 1715174304619,
+   *             "isKey": true
+   *         },
+   *         {
+   *             "key": "/volume1/legacy-bucket/key1/key2",
+   *             "path": "key1/key2",
+   *             "inStateSince": 1715174306641,
+   *             "size": 41943040,
+   *             "replicatedSize": 41943040,
+   *             "replicationInfo": {
+   *                 "replicationFactor": "ONE",
+   *                 "requiredNodes": 1,
+   *                 "replicationType": "RATIS"
+   *             },
+   *             "creationTime": 1715174306641,
+   *             "modificationTime": 1715174307994,
+   *             "isKey": true
+   *         }
+   *     ]
+   * }
+   * ********************************************************
+   * @throws IOException
+   */
+  @GET
+  @Path("/listKeys")
+  @SuppressWarnings("methodlength")
+  public Response listKeys(@QueryParam("replicationType") String 
replicationType,
+                           @QueryParam("creationDate") String creationDate,
+                           @DefaultValue(DEFAULT_KEY_SIZE) 
@QueryParam("keySize") long keySize,
+                           @DefaultValue(OM_KEY_PREFIX) 
@QueryParam("startPrefix") String startPrefix,
+                           @DefaultValue(StringUtils.EMPTY) 
@QueryParam(RECON_QUERY_PREVKEY) String prevKey,
+                           @DefaultValue(DEFAULT_FETCH_COUNT) 
@QueryParam("limit") int limit) {
+
+
+    // This API supports startPrefix from bucket level.
+    if (startPrefix == null || startPrefix.length() == 0) {
+      return Response.status(Response.Status.BAD_REQUEST).build();
+    }
+    String[] names = startPrefix.split(OM_KEY_PREFIX);
+    if (names.length < 3) {
+      return Response.status(Response.Status.BAD_REQUEST).build();
+    }
+    ListKeysResponse listKeysResponse = new ListKeysResponse();
+    if (!ReconUtils.isInitializationComplete(omMetadataManager)) {
+      listKeysResponse.setStatus(ResponseStatus.INITIALIZING);
+      return Response.ok(listKeysResponse).build();
+    }
+    ParamInfo paramInfo = new ParamInfo(replicationType, creationDate, 
keySize, startPrefix, prevKey,
+        limit, false, "");
+    Response response = getListKeysResponse(paramInfo);
+    if (response.getEntity() instanceof ListKeysResponse) {
+      listKeysResponse = (ListKeysResponse) response.getEntity();
+    }
+
+    List<KeyEntityInfo> keyInfoList = listKeysResponse.getKeys();
+    if (!keyInfoList.isEmpty()) {
+      listKeysResponse.setLastKey(keyInfoList.get(keyInfoList.size() - 
1).getKey());
+    }
+    listKeysResponse.setCount(keyInfoList.size());
+    return Response.ok(listKeysResponse).build();
+  }
+
+  private Response getListKeysResponse(ParamInfo paramInfo) {
+    try {
+      paramInfo.setLimit(Math.max(0, paramInfo.getLimit())); // Ensure limit 
is non-negative
+      ListKeysResponse listKeysResponse = new ListKeysResponse();
+      listKeysResponse.setPath(paramInfo.getStartPrefix());
+      long replicatedTotal = 0;
+      long unreplicatedTotal = 0;
+      boolean keysFound = false; // Flag to track if any keys are found
+
+      // Search keys from non-FSO layout.
+      Map<String, OmKeyInfo> obsKeys;
+      Table<String, OmKeyInfo> keyTable =
+          omMetadataManager.getKeyTable(BucketLayout.LEGACY);
+      obsKeys = retrieveKeysFromTable(keyTable, paramInfo);
+      for (Map.Entry<String, OmKeyInfo> entry : obsKeys.entrySet()) {
+        keysFound = true;
+        KeyEntityInfo keyEntityInfo =
+            createKeyEntityInfoFromOmKeyInfo(entry.getKey(), entry.getValue());
+
+        listKeysResponse.getKeys().add(keyEntityInfo);
+        replicatedTotal += entry.getValue().getReplicatedSize();
+        unreplicatedTotal += entry.getValue().getDataSize();
+      }
+
+      // Search keys from FSO layout.
+      Map<String, OmKeyInfo> fsoKeys = searchKeysInFSO(paramInfo);
+      for (Map.Entry<String, OmKeyInfo> entry : fsoKeys.entrySet()) {
+        keysFound = true;
+        KeyEntityInfo keyEntityInfo =
+            createKeyEntityInfoFromOmKeyInfo(entry.getKey(), entry.getValue());
+
+        listKeysResponse.getKeys().add(keyEntityInfo);
+        replicatedTotal += entry.getValue().getReplicatedSize();
+        unreplicatedTotal += entry.getValue().getDataSize();
+      }
+
+      // If no keys were found, return a response indicating that no keys 
matched
+      if (!keysFound) {
+        return noMatchedKeysResponse(paramInfo.getStartPrefix());
+      }
+
+      // Set the aggregated totals in the response
+      listKeysResponse.setReplicatedDataSize(replicatedTotal);
+      listKeysResponse.setUnReplicatedDataSize(unreplicatedTotal);
+
+      return Response.ok(listKeysResponse).build();
+    } catch (IOException e) {
+      return createInternalServerErrorResponse(
+          "Error searching keys in OM DB: " + e.getMessage());
+    } catch (IllegalArgumentException e) {
+      return createBadRequestResponse(
+          "Invalid startPrefix: " + e.getMessage());
+    }
+  }
+
+  public Map<String, OmKeyInfo> searchKeysInFSO(ParamInfo paramInfo)
+      throws IOException, IllegalArgumentException {
+    Map<String, OmKeyInfo> matchedKeys = new LinkedHashMap<>();
+    // Convert the search prefix to an object path for FSO buckets
+    String startPrefixObjectPath = 
convertToObjectPath(paramInfo.getStartPrefix());
+    String[] names = parseRequestPath(startPrefixObjectPath);
+    Table<String, OmKeyInfo> fileTable =
+        omMetadataManager.getKeyTable(BucketLayout.FILE_SYSTEM_OPTIMIZED);
+
+    // If names.length > 2, then the search prefix is at the volume or bucket 
level hence
+    // no need to find parent or extract id's or find subpaths as the 
fileTable is
+    // suitable for volume and bucket level search
+    if (names.length > 2) {
+      // Fetch the parent ID to search for
+      long parentId = Long.parseLong(names[names.length - 1]);
+
+      // Fetch the nameSpaceSummary for the parent ID
+      NSSummary parentSummary =
+          reconNamespaceSummaryManager.getNSSummary(parentId);
+      if (parentSummary == null) {
+        return matchedKeys;
+      }
+      List<String> subPaths = new ArrayList<>();
+      // Add the initial search prefix object path because it can have both 
files and subdirectories with files.
+      subPaths.add(startPrefixObjectPath);
+
+      // Recursively gather all subpaths
+      gatherSubPaths(parentId, subPaths, Long.parseLong(names[0]), 
Long.parseLong(names[1]));
+      // Iterate over the subpaths and retrieve the files
+      for (String subPath : subPaths) {
+        paramInfo.setStartPrefix(subPath);
+        paramInfo.setLimit(paramInfo.getLimit() - matchedKeys.size());
+        matchedKeys.putAll(
+            retrieveKeysFromTable(fileTable, paramInfo));

Review Comment:
   If limit over UI selection is 20, but this will list all in same parent 
directory, can be 100, do not follow limit restriction.



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/OMDBInsightEndpoint.java:
##########
@@ -674,6 +685,645 @@ public Response getDeletedDirectorySummary() {
     return Response.ok(dirSummary).build();
   }
 
+  /**
+   * This API will list out limited 'count' number of keys after applying 
below filters in API parameters:
+   * Default Values of API param filters:
+   *    -- replicationType - empty string and filter will not be applied, so 
list out all keys irrespective of
+   *       replication type.
+   *    -- creationTime - empty string and filter will not be applied, so list 
out keys irrespective of age.
+   *    -- keySize - 0 bytes, which means all keys greater than zero bytes 
will be listed, effectively all.
+   *    -- startPrefix - /
+   *    -- prevKey - ""
+   *    -- limit - 1000
+   *
+   * @param replicationType Filter for RATIS or EC replication keys
+   * @param creationDate Filter for keys created after creationDate in 
"MM-dd-yyyy HH:mm:ss" string format.
+   * @param keySize Filter for Keys greater than keySize in bytes.
+   * @param startPrefix Filter for startPrefix path.
+   * @param prevKey rocksDB last key of page requested.
+   * @param limit Filter for limited count of keys.
+   *
+   * @return the list of keys in JSON structured format as per respective 
bucket layout.
+   *
+   * Now lets consider, we have following OBS, LEGACY and FSO bucket key/files 
namespace tree structure
+   *
+   * For OBS Bucket
+   *
+   * /volume1/obs-bucket/key1
+   * /volume1/obs-bucket/key1/key2
+   * /volume1/obs-bucket/key1/key2/key3
+   * /volume1/obs-bucket/key4
+   * /volume1/obs-bucket/key5
+   * /volume1/obs-bucket/key6
+   * For LEGACY Bucket
+   *
+   * /volume1/legacy-bucket/key
+   * /volume1/legacy-bucket/key1/key2
+   * /volume1/legacy-bucket/key1/key2/key3
+   * /volume1/legacy-bucket/key4
+   * /volume1/legacy-bucket/key5
+   * /volume1/legacy-bucket/key6
+   * For FSO Bucket
+   *
+   * /volume1/fso-bucket/dir1/dir2/dir3
+   * /volume1/fso-bucket/dir1/testfile
+   * /volume1/fso-bucket/dir1/file1
+   * /volume1/fso-bucket/dir1/dir2/testfile
+   * /volume1/fso-bucket/dir1/dir2/file1
+   * /volume1/fso-bucket/dir1/dir2/dir3/testfile
+   * /volume1/fso-bucket/dir1/dir2/dir3/file1
+   * Input Request for OBS bucket:
+   *
+   *    
`api/v1/keys/listKeys?startPrefix=/volume1/obs-bucket&limit=2&replicationType=RATIS`
+   * Output Response:
+   *
+   * {
+   *    "status": "OK",
+   *    "path": "/volume1/obs-bucket",
+   *    "replicatedDataSize": 20971520,
+   *    "unReplicatedDataSize": 20971520,
+   *    "keyCount": 2,
+   *    "lastKey": "/volume1/obs-bucket/key1/key2",
+   *    "keys": [
+   *        {
+   *            "key": "/volume1/obs-bucket/key1",
+   *            "path": "key1",
+   *            "inStateSince": 1715174266126,
+   *            "size": 10485760,
+   *            "replicatedSize": 10485760,
+   *            "replicationInfo": {
+   *                "replicationFactor": "ONE",
+   *                "requiredNodes": 1,
+   *                "replicationType": "RATIS"
+   *            },
+   *            "creationTime": 1715174266126,
+   *            "modificationTime": 1715174267480,
+   *            "isKey": true
+   *        },
+   *        {
+   *            "key": "/volume1/obs-bucket/key1/key2",
+   *            "path": "key1/key2",
+   *            "inStateSince": 1715174269510,
+   *            "size": 10485760,
+   *            "replicatedSize": 10485760,
+   *            "replicationInfo": {
+   *                "replicationFactor": "ONE",
+   *                "requiredNodes": 1,
+   *                "replicationType": "RATIS"
+   *            },
+   *            "creationTime": 1715174269510,
+   *            "modificationTime": 1715174270410,
+   *            "isKey": true
+   *        }
+   *    ]
+   * }
+   * Input Request for FSO bucket:
+   *
+   *        
`api/v1/keys/listKeys?startPrefix=/volume1/fso-bucket&limit=2&replicationType=RATIS`
+   * Output Response:
+   *
+   * {
+   *     "status": "OK",
+   *     "path": "/volume1/fso-bucket",
+   *     "replicatedDataSize": 62914560,
+   *     "unReplicatedDataSize": 20971520,
+   *     "keyCount": 2,
+   *     "lastKey": 
"/-9223372036854775552/-9223372036854775040/-9223372036854774525/testfile",
+   *     "keys": [
+   *         {
+   *             "key": 
"/-9223372036854775552/-9223372036854775040/-9223372036854774525/file1",
+   *             "path": "file1",
+   *             "inStateSince": 1715174237440,
+   *             "size": 10485760,
+   *             "replicatedSize": 31457280,
+   *             "replicationInfo": {
+   *                 "replicationFactor": "THREE",
+   *                 "requiredNodes": 3,
+   *                 "replicationType": "RATIS"
+   *             },
+   *             "creationTime": 1715174237440,
+   *             "modificationTime": 1715174238161,
+   *             "isKey": true
+   *         },
+   *         {
+   *             "key": 
"/-9223372036854775552/-9223372036854775040/-9223372036854774525/testfile",
+   *             "path": "testfile",
+   *             "inStateSince": 1715174234840,

Review Comment:
   any difference between isStateSince with modificationTime and creationTime ? 
what are different states?



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/OMDBInsightEndpoint.java:
##########
@@ -674,6 +685,645 @@ public Response getDeletedDirectorySummary() {
     return Response.ok(dirSummary).build();
   }
 
+  /**
+   * This API will list out limited 'count' number of keys after applying 
below filters in API parameters:
+   * Default Values of API param filters:
+   *    -- replicationType - empty string and filter will not be applied, so 
list out all keys irrespective of
+   *       replication type.
+   *    -- creationTime - empty string and filter will not be applied, so list 
out keys irrespective of age.
+   *    -- keySize - 0 bytes, which means all keys greater than zero bytes 
will be listed, effectively all.
+   *    -- startPrefix - /
+   *    -- prevKey - ""
+   *    -- limit - 1000
+   *
+   * @param replicationType Filter for RATIS or EC replication keys
+   * @param creationDate Filter for keys created after creationDate in 
"MM-dd-yyyy HH:mm:ss" string format.
+   * @param keySize Filter for Keys greater than keySize in bytes.
+   * @param startPrefix Filter for startPrefix path.
+   * @param prevKey rocksDB last key of page requested.
+   * @param limit Filter for limited count of keys.
+   *
+   * @return the list of keys in JSON structured format as per respective 
bucket layout.
+   *
+   * Now lets consider, we have following OBS, LEGACY and FSO bucket key/files 
namespace tree structure
+   *
+   * For OBS Bucket
+   *
+   * /volume1/obs-bucket/key1
+   * /volume1/obs-bucket/key1/key2
+   * /volume1/obs-bucket/key1/key2/key3
+   * /volume1/obs-bucket/key4
+   * /volume1/obs-bucket/key5
+   * /volume1/obs-bucket/key6
+   * For LEGACY Bucket
+   *
+   * /volume1/legacy-bucket/key
+   * /volume1/legacy-bucket/key1/key2
+   * /volume1/legacy-bucket/key1/key2/key3
+   * /volume1/legacy-bucket/key4
+   * /volume1/legacy-bucket/key5
+   * /volume1/legacy-bucket/key6
+   * For FSO Bucket
+   *
+   * /volume1/fso-bucket/dir1/dir2/dir3
+   * /volume1/fso-bucket/dir1/testfile
+   * /volume1/fso-bucket/dir1/file1
+   * /volume1/fso-bucket/dir1/dir2/testfile
+   * /volume1/fso-bucket/dir1/dir2/file1
+   * /volume1/fso-bucket/dir1/dir2/dir3/testfile
+   * /volume1/fso-bucket/dir1/dir2/dir3/file1
+   * Input Request for OBS bucket:
+   *
+   *    
`api/v1/keys/listKeys?startPrefix=/volume1/obs-bucket&limit=2&replicationType=RATIS`
+   * Output Response:
+   *
+   * {
+   *    "status": "OK",
+   *    "path": "/volume1/obs-bucket",
+   *    "replicatedDataSize": 20971520,
+   *    "unReplicatedDataSize": 20971520,
+   *    "keyCount": 2,
+   *    "lastKey": "/volume1/obs-bucket/key1/key2",
+   *    "keys": [
+   *        {
+   *            "key": "/volume1/obs-bucket/key1",
+   *            "path": "key1",
+   *            "inStateSince": 1715174266126,
+   *            "size": 10485760,
+   *            "replicatedSize": 10485760,
+   *            "replicationInfo": {
+   *                "replicationFactor": "ONE",
+   *                "requiredNodes": 1,
+   *                "replicationType": "RATIS"
+   *            },
+   *            "creationTime": 1715174266126,
+   *            "modificationTime": 1715174267480,
+   *            "isKey": true
+   *        },
+   *        {
+   *            "key": "/volume1/obs-bucket/key1/key2",
+   *            "path": "key1/key2",
+   *            "inStateSince": 1715174269510,
+   *            "size": 10485760,
+   *            "replicatedSize": 10485760,
+   *            "replicationInfo": {
+   *                "replicationFactor": "ONE",
+   *                "requiredNodes": 1,
+   *                "replicationType": "RATIS"
+   *            },
+   *            "creationTime": 1715174269510,
+   *            "modificationTime": 1715174270410,
+   *            "isKey": true
+   *        }
+   *    ]
+   * }
+   * Input Request for FSO bucket:
+   *
+   *        
`api/v1/keys/listKeys?startPrefix=/volume1/fso-bucket&limit=2&replicationType=RATIS`
+   * Output Response:
+   *
+   * {
+   *     "status": "OK",
+   *     "path": "/volume1/fso-bucket",
+   *     "replicatedDataSize": 62914560,
+   *     "unReplicatedDataSize": 20971520,
+   *     "keyCount": 2,
+   *     "lastKey": 
"/-9223372036854775552/-9223372036854775040/-9223372036854774525/testfile",
+   *     "keys": [
+   *         {
+   *             "key": 
"/-9223372036854775552/-9223372036854775040/-9223372036854774525/file1",
+   *             "path": "file1",
+   *             "inStateSince": 1715174237440,
+   *             "size": 10485760,
+   *             "replicatedSize": 31457280,
+   *             "replicationInfo": {
+   *                 "replicationFactor": "THREE",
+   *                 "requiredNodes": 3,
+   *                 "replicationType": "RATIS"
+   *             },
+   *             "creationTime": 1715174237440,
+   *             "modificationTime": 1715174238161,
+   *             "isKey": true
+   *         },
+   *         {
+   *             "key": 
"/-9223372036854775552/-9223372036854775040/-9223372036854774525/testfile",
+   *             "path": "testfile",
+   *             "inStateSince": 1715174234840,
+   *             "size": 10485760,
+   *             "replicatedSize": 31457280,
+   *             "replicationInfo": {
+   *                 "replicationFactor": "THREE",
+   *                 "requiredNodes": 3,
+   *                 "replicationType": "RATIS"
+   *             },
+   *             "creationTime": 1715174234840,
+   *             "modificationTime": 1715174235562,
+   *             "isKey": true
+   *         }
+   *     ]
+   * }
+   * Input Request for Legacy bucket:
+   *
+   *        
`api/v1/keys/listKeys?startPrefix=/volume1/legacy-bucket&limit=2&replicationType=RATIS`
+   * Output Response:
+   *
+   * {
+   *     "status": "OK",
+   *     "path": "/volume1/legacy-bucket",
+   *     "replicatedDataSize": 52428800,
+   *     "unReplicatedDataSize": 52428800,
+   *     "keyCount": 2,
+   *     "lastKey": "/volume1/legacy-bucket/key1/key2",
+   *     "keys": [
+   *         {
+   *             "key": "/volume1/legacy-bucket/key1",
+   *             "path": "key1",
+   *             "inStateSince": 1715174303702,
+   *             "size": 10485760,
+   *             "replicatedSize": 10485760,
+   *             "replicationInfo": {
+   *                 "replicationFactor": "ONE",
+   *                 "requiredNodes": 1,
+   *                 "replicationType": "RATIS"
+   *             },
+   *             "creationTime": 1715174303702,
+   *             "modificationTime": 1715174304619,
+   *             "isKey": true
+   *         },
+   *         {
+   *             "key": "/volume1/legacy-bucket/key1/key2",
+   *             "path": "key1/key2",
+   *             "inStateSince": 1715174306641,
+   *             "size": 41943040,
+   *             "replicatedSize": 41943040,
+   *             "replicationInfo": {
+   *                 "replicationFactor": "ONE",
+   *                 "requiredNodes": 1,
+   *                 "replicationType": "RATIS"
+   *             },
+   *             "creationTime": 1715174306641,
+   *             "modificationTime": 1715174307994,
+   *             "isKey": true
+   *         }
+   *     ]
+   * }
+   * ********************************************************
+   * @throws IOException
+   */
+  @GET
+  @Path("/listKeys")
+  @SuppressWarnings("methodlength")
+  public Response listKeys(@QueryParam("replicationType") String 
replicationType,
+                           @QueryParam("creationDate") String creationDate,
+                           @DefaultValue(DEFAULT_KEY_SIZE) 
@QueryParam("keySize") long keySize,
+                           @DefaultValue(OM_KEY_PREFIX) 
@QueryParam("startPrefix") String startPrefix,
+                           @DefaultValue(StringUtils.EMPTY) 
@QueryParam(RECON_QUERY_PREVKEY) String prevKey,
+                           @DefaultValue(DEFAULT_FETCH_COUNT) 
@QueryParam("limit") int limit) {
+
+
+    // This API supports startPrefix from bucket level.
+    if (startPrefix == null || startPrefix.length() == 0) {
+      return Response.status(Response.Status.BAD_REQUEST).build();
+    }
+    String[] names = startPrefix.split(OM_KEY_PREFIX);

Review Comment:
   it must have atleast 3 part, volume, bucket and key. what if need list all 
keys in a bucket?



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/OMDBInsightEndpoint.java:
##########
@@ -674,6 +685,645 @@ public Response getDeletedDirectorySummary() {
     return Response.ok(dirSummary).build();
   }
 
+  /**
+   * This API will list out limited 'count' number of keys after applying 
below filters in API parameters:
+   * Default Values of API param filters:
+   *    -- replicationType - empty string and filter will not be applied, so 
list out all keys irrespective of
+   *       replication type.
+   *    -- creationTime - empty string and filter will not be applied, so list 
out keys irrespective of age.
+   *    -- keySize - 0 bytes, which means all keys greater than zero bytes 
will be listed, effectively all.
+   *    -- startPrefix - /
+   *    -- prevKey - ""
+   *    -- limit - 1000
+   *
+   * @param replicationType Filter for RATIS or EC replication keys
+   * @param creationDate Filter for keys created after creationDate in 
"MM-dd-yyyy HH:mm:ss" string format.
+   * @param keySize Filter for Keys greater than keySize in bytes.
+   * @param startPrefix Filter for startPrefix path.
+   * @param prevKey rocksDB last key of page requested.
+   * @param limit Filter for limited count of keys.
+   *
+   * @return the list of keys in JSON structured format as per respective 
bucket layout.
+   *
+   * Now lets consider, we have following OBS, LEGACY and FSO bucket key/files 
namespace tree structure
+   *
+   * For OBS Bucket
+   *
+   * /volume1/obs-bucket/key1
+   * /volume1/obs-bucket/key1/key2
+   * /volume1/obs-bucket/key1/key2/key3
+   * /volume1/obs-bucket/key4
+   * /volume1/obs-bucket/key5
+   * /volume1/obs-bucket/key6
+   * For LEGACY Bucket
+   *
+   * /volume1/legacy-bucket/key
+   * /volume1/legacy-bucket/key1/key2
+   * /volume1/legacy-bucket/key1/key2/key3
+   * /volume1/legacy-bucket/key4
+   * /volume1/legacy-bucket/key5
+   * /volume1/legacy-bucket/key6
+   * For FSO Bucket
+   *
+   * /volume1/fso-bucket/dir1/dir2/dir3
+   * /volume1/fso-bucket/dir1/testfile
+   * /volume1/fso-bucket/dir1/file1
+   * /volume1/fso-bucket/dir1/dir2/testfile
+   * /volume1/fso-bucket/dir1/dir2/file1
+   * /volume1/fso-bucket/dir1/dir2/dir3/testfile
+   * /volume1/fso-bucket/dir1/dir2/dir3/file1
+   * Input Request for OBS bucket:
+   *
+   *    
`api/v1/keys/listKeys?startPrefix=/volume1/obs-bucket&limit=2&replicationType=RATIS`
+   * Output Response:
+   *
+   * {
+   *    "status": "OK",
+   *    "path": "/volume1/obs-bucket",
+   *    "replicatedDataSize": 20971520,
+   *    "unReplicatedDataSize": 20971520,
+   *    "keyCount": 2,
+   *    "lastKey": "/volume1/obs-bucket/key1/key2",
+   *    "keys": [
+   *        {
+   *            "key": "/volume1/obs-bucket/key1",
+   *            "path": "key1",
+   *            "inStateSince": 1715174266126,
+   *            "size": 10485760,
+   *            "replicatedSize": 10485760,
+   *            "replicationInfo": {
+   *                "replicationFactor": "ONE",
+   *                "requiredNodes": 1,
+   *                "replicationType": "RATIS"
+   *            },
+   *            "creationTime": 1715174266126,
+   *            "modificationTime": 1715174267480,
+   *            "isKey": true
+   *        },
+   *        {
+   *            "key": "/volume1/obs-bucket/key1/key2",
+   *            "path": "key1/key2",
+   *            "inStateSince": 1715174269510,
+   *            "size": 10485760,
+   *            "replicatedSize": 10485760,
+   *            "replicationInfo": {
+   *                "replicationFactor": "ONE",
+   *                "requiredNodes": 1,
+   *                "replicationType": "RATIS"
+   *            },
+   *            "creationTime": 1715174269510,
+   *            "modificationTime": 1715174270410,
+   *            "isKey": true
+   *        }
+   *    ]
+   * }
+   * Input Request for FSO bucket:
+   *
+   *        
`api/v1/keys/listKeys?startPrefix=/volume1/fso-bucket&limit=2&replicationType=RATIS`
+   * Output Response:
+   *
+   * {
+   *     "status": "OK",
+   *     "path": "/volume1/fso-bucket",
+   *     "replicatedDataSize": 62914560,
+   *     "unReplicatedDataSize": 20971520,
+   *     "keyCount": 2,
+   *     "lastKey": 
"/-9223372036854775552/-9223372036854775040/-9223372036854774525/testfile",
+   *     "keys": [
+   *         {
+   *             "key": 
"/-9223372036854775552/-9223372036854775040/-9223372036854774525/file1",
+   *             "path": "file1",
+   *             "inStateSince": 1715174237440,
+   *             "size": 10485760,
+   *             "replicatedSize": 31457280,
+   *             "replicationInfo": {
+   *                 "replicationFactor": "THREE",
+   *                 "requiredNodes": 3,
+   *                 "replicationType": "RATIS"
+   *             },
+   *             "creationTime": 1715174237440,
+   *             "modificationTime": 1715174238161,
+   *             "isKey": true
+   *         },
+   *         {
+   *             "key": 
"/-9223372036854775552/-9223372036854775040/-9223372036854774525/testfile",
+   *             "path": "testfile",
+   *             "inStateSince": 1715174234840,
+   *             "size": 10485760,
+   *             "replicatedSize": 31457280,
+   *             "replicationInfo": {
+   *                 "replicationFactor": "THREE",
+   *                 "requiredNodes": 3,
+   *                 "replicationType": "RATIS"
+   *             },
+   *             "creationTime": 1715174234840,
+   *             "modificationTime": 1715174235562,
+   *             "isKey": true
+   *         }
+   *     ]
+   * }
+   * Input Request for Legacy bucket:
+   *
+   *        
`api/v1/keys/listKeys?startPrefix=/volume1/legacy-bucket&limit=2&replicationType=RATIS`
+   * Output Response:
+   *
+   * {
+   *     "status": "OK",
+   *     "path": "/volume1/legacy-bucket",
+   *     "replicatedDataSize": 52428800,
+   *     "unReplicatedDataSize": 52428800,
+   *     "keyCount": 2,
+   *     "lastKey": "/volume1/legacy-bucket/key1/key2",
+   *     "keys": [
+   *         {
+   *             "key": "/volume1/legacy-bucket/key1",
+   *             "path": "key1",
+   *             "inStateSince": 1715174303702,
+   *             "size": 10485760,
+   *             "replicatedSize": 10485760,
+   *             "replicationInfo": {
+   *                 "replicationFactor": "ONE",
+   *                 "requiredNodes": 1,
+   *                 "replicationType": "RATIS"
+   *             },
+   *             "creationTime": 1715174303702,
+   *             "modificationTime": 1715174304619,
+   *             "isKey": true
+   *         },
+   *         {
+   *             "key": "/volume1/legacy-bucket/key1/key2",
+   *             "path": "key1/key2",
+   *             "inStateSince": 1715174306641,
+   *             "size": 41943040,
+   *             "replicatedSize": 41943040,
+   *             "replicationInfo": {
+   *                 "replicationFactor": "ONE",
+   *                 "requiredNodes": 1,
+   *                 "replicationType": "RATIS"
+   *             },
+   *             "creationTime": 1715174306641,
+   *             "modificationTime": 1715174307994,
+   *             "isKey": true
+   *         }
+   *     ]
+   * }
+   * ********************************************************
+   * @throws IOException
+   */
+  @GET
+  @Path("/listKeys")
+  @SuppressWarnings("methodlength")
+  public Response listKeys(@QueryParam("replicationType") String 
replicationType,
+                           @QueryParam("creationDate") String creationDate,
+                           @DefaultValue(DEFAULT_KEY_SIZE) 
@QueryParam("keySize") long keySize,
+                           @DefaultValue(OM_KEY_PREFIX) 
@QueryParam("startPrefix") String startPrefix,
+                           @DefaultValue(StringUtils.EMPTY) 
@QueryParam(RECON_QUERY_PREVKEY) String prevKey,
+                           @DefaultValue(DEFAULT_FETCH_COUNT) 
@QueryParam("limit") int limit) {
+
+
+    // This API supports startPrefix from bucket level.
+    if (startPrefix == null || startPrefix.length() == 0) {
+      return Response.status(Response.Status.BAD_REQUEST).build();
+    }
+    String[] names = startPrefix.split(OM_KEY_PREFIX);
+    if (names.length < 3) {
+      return Response.status(Response.Status.BAD_REQUEST).build();
+    }
+    ListKeysResponse listKeysResponse = new ListKeysResponse();
+    if (!ReconUtils.isInitializationComplete(omMetadataManager)) {
+      listKeysResponse.setStatus(ResponseStatus.INITIALIZING);
+      return Response.ok(listKeysResponse).build();
+    }
+    ParamInfo paramInfo = new ParamInfo(replicationType, creationDate, 
keySize, startPrefix, prevKey,
+        limit, false, "");
+    Response response = getListKeysResponse(paramInfo);
+    if (response.getEntity() instanceof ListKeysResponse) {
+      listKeysResponse = (ListKeysResponse) response.getEntity();
+    }
+
+    List<KeyEntityInfo> keyInfoList = listKeysResponse.getKeys();
+    if (!keyInfoList.isEmpty()) {
+      listKeysResponse.setLastKey(keyInfoList.get(keyInfoList.size() - 
1).getKey());
+    }
+    listKeysResponse.setCount(keyInfoList.size());
+    return Response.ok(listKeysResponse).build();
+  }
+
+  private Response getListKeysResponse(ParamInfo paramInfo) {
+    try {
+      paramInfo.setLimit(Math.max(0, paramInfo.getLimit())); // Ensure limit 
is non-negative
+      ListKeysResponse listKeysResponse = new ListKeysResponse();
+      listKeysResponse.setPath(paramInfo.getStartPrefix());
+      long replicatedTotal = 0;
+      long unreplicatedTotal = 0;
+      boolean keysFound = false; // Flag to track if any keys are found
+
+      // Search keys from non-FSO layout.
+      Map<String, OmKeyInfo> obsKeys;
+      Table<String, OmKeyInfo> keyTable =
+          omMetadataManager.getKeyTable(BucketLayout.LEGACY);
+      obsKeys = retrieveKeysFromTable(keyTable, paramInfo);
+      for (Map.Entry<String, OmKeyInfo> entry : obsKeys.entrySet()) {
+        keysFound = true;
+        KeyEntityInfo keyEntityInfo =
+            createKeyEntityInfoFromOmKeyInfo(entry.getKey(), entry.getValue());
+
+        listKeysResponse.getKeys().add(keyEntityInfo);
+        replicatedTotal += entry.getValue().getReplicatedSize();
+        unreplicatedTotal += entry.getValue().getDataSize();
+      }
+
+      // Search keys from FSO layout.
+      Map<String, OmKeyInfo> fsoKeys = searchKeysInFSO(paramInfo);
+      for (Map.Entry<String, OmKeyInfo> entry : fsoKeys.entrySet()) {
+        keysFound = true;
+        KeyEntityInfo keyEntityInfo =
+            createKeyEntityInfoFromOmKeyInfo(entry.getKey(), entry.getValue());
+
+        listKeysResponse.getKeys().add(keyEntityInfo);
+        replicatedTotal += entry.getValue().getReplicatedSize();
+        unreplicatedTotal += entry.getValue().getDataSize();
+      }
+
+      // If no keys were found, return a response indicating that no keys 
matched
+      if (!keysFound) {
+        return noMatchedKeysResponse(paramInfo.getStartPrefix());
+      }
+
+      // Set the aggregated totals in the response
+      listKeysResponse.setReplicatedDataSize(replicatedTotal);
+      listKeysResponse.setUnReplicatedDataSize(unreplicatedTotal);
+
+      return Response.ok(listKeysResponse).build();
+    } catch (IOException e) {
+      return createInternalServerErrorResponse(
+          "Error searching keys in OM DB: " + e.getMessage());
+    } catch (IllegalArgumentException e) {
+      return createBadRequestResponse(
+          "Invalid startPrefix: " + e.getMessage());
+    }
+  }
+
+  public Map<String, OmKeyInfo> searchKeysInFSO(ParamInfo paramInfo)
+      throws IOException, IllegalArgumentException {
+    Map<String, OmKeyInfo> matchedKeys = new LinkedHashMap<>();
+    // Convert the search prefix to an object path for FSO buckets
+    String startPrefixObjectPath = 
convertToObjectPath(paramInfo.getStartPrefix());
+    String[] names = parseRequestPath(startPrefixObjectPath);
+    Table<String, OmKeyInfo> fileTable =
+        omMetadataManager.getKeyTable(BucketLayout.FILE_SYSTEM_OPTIMIZED);
+
+    // If names.length > 2, then the search prefix is at the volume or bucket 
level hence
+    // no need to find parent or extract id's or find subpaths as the 
fileTable is
+    // suitable for volume and bucket level search
+    if (names.length > 2) {
+      // Fetch the parent ID to search for
+      long parentId = Long.parseLong(names[names.length - 1]);
+
+      // Fetch the nameSpaceSummary for the parent ID
+      NSSummary parentSummary =
+          reconNamespaceSummaryManager.getNSSummary(parentId);
+      if (parentSummary == null) {
+        return matchedKeys;
+      }
+      List<String> subPaths = new ArrayList<>();
+      // Add the initial search prefix object path because it can have both 
files and subdirectories with files.
+      subPaths.add(startPrefixObjectPath);
+
+      // Recursively gather all subpaths
+      gatherSubPaths(parentId, subPaths, Long.parseLong(names[0]), 
Long.parseLong(names[1]));
+      // Iterate over the subpaths and retrieve the files
+      for (String subPath : subPaths) {
+        paramInfo.setStartPrefix(subPath);
+        paramInfo.setLimit(paramInfo.getLimit() - matchedKeys.size());
+        matchedKeys.putAll(
+            retrieveKeysFromTable(fileTable, paramInfo));
+        if (matchedKeys.size() >= paramInfo.getLimit()) {
+          break;
+        }
+      }
+      return matchedKeys;
+    }
+
+    paramInfo.setStartPrefix(startPrefixObjectPath);
+    // Iterate over for bucket and volume level search
+    matchedKeys.putAll(
+        retrieveKeysFromTable(fileTable, paramInfo));
+    return matchedKeys;
+  }
+
+  /**
+   * Finds all subdirectories under a parent directory in an FSO bucket. It 
builds
+   * a list of paths for these subdirectories. These sub-directories are then 
used
+   * to search for files in the fileTable.
+   * <p>
+   * How it works:
+   * - Starts from a parent directory identified by parentId.
+   * - Looks through all child directories of this parent.
+   * - For each child, it creates a path that starts with 
volumeID/bucketID/parentId,
+   * following our fileTable format
+   * - Adds these paths to a list and explores each child further for more 
subdirectories.
+   *
+   * @param parentId The ID of the directory we start exploring from.
+   * @param subPaths A list where we collect paths to all subdirectories.
+   * @param volumeID
+   * @param bucketID
+   * @throws IOException If there are problems accessing directory information.
+   */
+  private void gatherSubPaths(long parentId, List<String> subPaths,
+                              long volumeID, long bucketID) throws IOException 
{
+    // Fetch the NSSummary object for parentId
+    NSSummary parentSummary =
+        reconNamespaceSummaryManager.getNSSummary(parentId);
+    if (parentSummary == null) {
+      return;
+    }
+
+    Set<Long> childDirIds = parentSummary.getChildDir();
+    for (Long childId : childDirIds) {
+      // Fetch the NSSummary for each child directory
+      NSSummary childSummary =
+          reconNamespaceSummaryManager.getNSSummary(childId);
+      if (childSummary != null) {
+        String subPath =
+            constructObjectPathWithPrefix(volumeID, bucketID, childId);
+        // Add to subPaths
+        subPaths.add(subPath);
+        // Recurse into this child directory
+        gatherSubPaths(childId, subPaths, volumeID, bucketID);
+      }
+    }
+  }
+
+
+  /**
+   * Converts a key prefix into an object path for FSO buckets, using IDs.
+   * <p>
+   * This method transforms a user-provided path (e.g., "volume/bucket/dir1") 
into
+   * a database-friendly format ("/volumeID/bucketID/ParentId/") by replacing 
names
+   * with their corresponding IDs. It simplifies database queries for FSO 
bucket operations.
+   *
+   * @param prevKeyPrefix The path to be converted, not including key or 
directory names/IDs.
+   * @return The object path as "/volumeID/bucketID/ParentId/".
+   * @throws IOException If database access fails.
+   */
+  public String convertToObjectPath(String prevKeyPrefix)
+      throws IOException, IllegalArgumentException {
+
+    String[] names = parseRequestPath(
+        normalizePath(prevKeyPrefix, BucketLayout.FILE_SYSTEM_OPTIMIZED));
+
+    // Root-Level :- Return the original path
+    if (names.length == 0) {
+      return prevKeyPrefix;
+    }
+
+    // Volume-Level :- Fetch the volumeID
+    String volumeName = names[0];

Review Comment:
   It seems format for prvKey for fso is 
`/<volumeId>/<bucketi>/<parentId>/<keyName>,` as below logic for getDirInfo() 
assume same. So seems all below steps not requried for volumeId/bucketId..
   OR logic for getting objectId and assuming parentId in key seems wrong.



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