Browse Source

HDFS-12692. Ozone: fix javadoc/unit test for calling MetadataStore.getRangeKVs with non existing key. Contributed by Elek, Marton.

Yiqun Lin 7 years ago
parent
commit
393a02d8e1

+ 1 - 1
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/utils/LevelDBStore.java

@@ -286,7 +286,7 @@ public class LevelDBStore implements MetadataStore {
    * If the startKey is specified and found in levelDB, this key and the keys
    * after this key will be included in the result. If the startKey is null
    * all entries will be included as long as other conditions are satisfied.
-   * If the given startKey doesn't exist, an IOException will be thrown.
+   * If the given startKey doesn't exist, an empty list will be returned.
    * <p>
    * The count argument is to limit number of total entries to return,
    * the value for count must be an integer greater than 0.

+ 1 - 1
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/utils/MetadataStore.java

@@ -78,7 +78,7 @@ public interface MetadataStore extends Closeable{
    * If the startKey is specified and found in levelDB, this key and the keys
    * after this key will be included in the result. If the startKey is null
    * all entries will be included as long as other conditions are satisfied.
-   * If the given startKey doesn't exist, an IOException will be thrown.
+   * If the given startKey doesn't exist and empty list will be returned.
    * <p>
    * The count argument is to limit number of total entries to return,
    * the value for count must be an integer greater than 0.

+ 5 - 1
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/TestMetadataStore.java

@@ -95,7 +95,7 @@ public class TestMetadataStore {
 
     // Add 20 entries.
     // {a0 : a-value0} to {a9 : a-value9}
-    // {b0 : a-value0} to {b0 : b-value9}
+    // {b0 : b-value0} to {b9 : b-value9}
     for (int i=0; i<10; i++) {
       store.put(getBytes("a" + i), getBytes("a-value" + i));
       store.put(getBytes("b" + i), getBytes("b-value" + i));
@@ -242,6 +242,10 @@ public class TestMetadataStore {
     Assert.assertEquals(5, result.size());
     Assert.assertEquals("a-value2", getString(result.get(2).getValue()));
 
+    // Empty list if startKey doesn't exist.
+    result = store.getRangeKVs(getBytes("a12"), 5);
+    Assert.assertEquals(0, result.size());
+
     // Returns max available entries after a valid startKey.
     result = store.getRangeKVs(getBytes("b0"), MAX_GETRANGE_LENGTH);
     Assert.assertEquals(10, result.size());