This is an automated email from the ASF dual-hosted git repository.
sshenoy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 3b3742c466 HDDS-7713. listKeys with prefix path as key for FSO buckets
is redundant. (#5170)
3b3742c466 is described below
commit 3b3742c466ba313016d0b30f2049ad33dbfd09e8
Author: Tejaskriya <[email protected]>
AuthorDate: Mon Aug 14 13:20:06 2023 +0530
HDDS-7713. listKeys with prefix path as key for FSO buckets is redundant.
(#5170)
---
.../apache/hadoop/ozone/client/OzoneBucket.java | 16 +++++++++-------
.../hadoop/ozone/om/TestListKeysWithFSO.java | 5 +++++
.../hadoop/ozone/om/TestObjectStoreWithFSO.java | 22 +++++++++++++++++++++-
3 files changed, 35 insertions(+), 8 deletions(-)
diff --git
a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneBucket.java
b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneBucket.java
index 4210876f98..cf847702ff 100644
---
a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneBucket.java
+++
b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneBucket.java
@@ -1450,14 +1450,16 @@ public class OzoneBucket extends WithMetadata {
}
if (status != null) {
- OmKeyInfo keyInfo = status.getKeyInfo();
- String keyName = keyInfo.getKeyName();
-
- if (status.isDirectory()) {
- // add trailing slash to represent directory
- keyName =
- OzoneFSUtils.addTrailingSlashIfNeeded(keyInfo.getKeyName());
+ // not required to addKeyPrefix
+ // case-3) if the keyPrefix corresponds to a file and not a dir,
+ // prefix should not be added to avoid duplicate entry
+ if (!status.isDirectory()) {
+ return;
}
+ OmKeyInfo keyInfo = status.getKeyInfo();
+ // add trailing slash to represent directory
+ String keyName =
+ OzoneFSUtils.addTrailingSlashIfNeeded(keyInfo.getKeyName());
// removeStartKey - as the startKey is a placeholder, which is
// managed internally to traverse leaf node's sub-paths.
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestListKeysWithFSO.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestListKeysWithFSO.java
index 5b6edace4d..3902e0b6ac 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestListKeysWithFSO.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestListKeysWithFSO.java
@@ -263,6 +263,11 @@ public class TestListKeysWithFSO {
expectedKeys =
getExpectedKeyList("a1", "a1/b3/e3/e31.tx", legacyOzoneBucket);
checkKeyList("a1", "a1/b3/e3/e31.tx", expectedKeys, fsoOzoneBucket);
+
+ // case-10: keyPrefix corresponds an exist file
+ expectedKeys =
+ getExpectedKeyList("a1/b3/e3/e31.tx", "", legacyOzoneBucket);
+ checkKeyList("a1/b3/e3/e31.tx", "", expectedKeys, fsoOzoneBucket);
}
@Test
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestObjectStoreWithFSO.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestObjectStoreWithFSO.java
index 2da98434bb..55ffca602a 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestObjectStoreWithFSO.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestObjectStoreWithFSO.java
@@ -375,7 +375,7 @@ public class TestObjectStoreWithFSO {
* |
* a
* |
- * -----------------------------------
+ * --------------------------------------
* | | |
* b1 b2 b3
* ----- -------- ----------
@@ -454,12 +454,17 @@ public class TestObjectStoreWithFSO {
checkKeyList(ozoneKeyIterator, expectedKeys);
// Intermediate level keyPrefix - 3rd level
+ // Without trailing slash
ozoneKeyIterator =
ozoneBucket.listKeys("a/b2/d1", null);
expectedKeys = new LinkedList<>();
expectedKeys.add("a/b2/d1/");
expectedKeys.add("a/b2/d1/d11.tx");
checkKeyList(ozoneKeyIterator, expectedKeys);
+ // With trailing slash
+ ozoneKeyIterator =
+ ozoneBucket.listKeys("a/b2/d1/", null);
+ checkKeyList(ozoneKeyIterator, expectedKeys);
// Boundary of a level
ozoneKeyIterator =
@@ -473,6 +478,21 @@ public class TestObjectStoreWithFSO {
ozoneBucket.listKeys("a/b3/e3", "a/b3/e3/e31.tx");
expectedKeys = new LinkedList<>();
checkKeyList(ozoneKeyIterator, expectedKeys);
+
+ // Key level, prefix=key case
+ ozoneKeyIterator =
+ ozoneBucket.listKeys("a/b1/c1/c1.tx");
+ expectedKeys = new LinkedList<>();
+ expectedKeys.add("a/b1/c1/c1.tx");
+ checkKeyList(ozoneKeyIterator, expectedKeys);
+
+ // Key directly under bucket
+ createTestKey(ozoneBucket, "key1.tx", "key1");
+ ozoneKeyIterator =
+ ozoneBucket.listKeys("key1.tx");
+ expectedKeys = new LinkedList<>();
+ expectedKeys.add("key1.tx");
+ checkKeyList(ozoneKeyIterator, expectedKeys);
}
private void verifyFullTreeStructure(Iterator<? extends OzoneKey> keyItr) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]