This is an automated email from the ASF dual-hosted git repository.

kturner pushed a commit to branch no-chop-merge
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/no-chop-merge by this push:
     new 883d3d8b32 adds range validation to tablet file objects
883d3d8b32 is described below

commit 883d3d8b32faf839b98b6f3a604bc0d3f8813302
Author: Keith Turner <[email protected]>
AuthorDate: Fri Jul 14 21:02:00 2023 -0400

    adds range validation to tablet file objects
---
 .../core/metadata/ReferencedTabletFile.java        |  3 ++-
 .../accumulo/core/metadata/StoredTabletFile.java   | 23 +++++++++++++++++++++-
 .../metadata/schema/ReferencedTabletFileTest.java  | 23 ++++++++++++++++++++++
 3 files changed, 47 insertions(+), 2 deletions(-)

diff --git 
a/core/src/main/java/org/apache/accumulo/core/metadata/ReferencedTabletFile.java
 
b/core/src/main/java/org/apache/accumulo/core/metadata/ReferencedTabletFile.java
index 0300f0ee31..bd5af63091 100644
--- 
a/core/src/main/java/org/apache/accumulo/core/metadata/ReferencedTabletFile.java
+++ 
b/core/src/main/java/org/apache/accumulo/core/metadata/ReferencedTabletFile.java
@@ -19,6 +19,7 @@
 package org.apache.accumulo.core.metadata;
 
 import static org.apache.accumulo.core.Constants.HDFS_TABLES_DIR;
+import static 
org.apache.accumulo.core.metadata.StoredTabletFile.requireRowRange;
 
 import java.net.URI;
 import java.util.Comparator;
@@ -165,7 +166,7 @@ public class ReferencedTabletFile extends 
AbstractTabletFile<ReferencedTabletFil
    * qualify an absolute path or create a new file.
    */
   public ReferencedTabletFile(Path metaPath, Range range) {
-    super(Objects.requireNonNull(metaPath), range);
+    super(Objects.requireNonNull(metaPath), requireRowRange(range));
     log.trace("Parsing TabletFile from {}", metaPath);
     parts = parsePath(metaPath);
   }
diff --git 
a/core/src/main/java/org/apache/accumulo/core/metadata/StoredTabletFile.java 
b/core/src/main/java/org/apache/accumulo/core/metadata/StoredTabletFile.java
index e0c6f9f4a6..545867bba2 100644
--- a/core/src/main/java/org/apache/accumulo/core/metadata/StoredTabletFile.java
+++ b/core/src/main/java/org/apache/accumulo/core/metadata/StoredTabletFile.java
@@ -33,6 +33,7 @@ import org.apache.hadoop.io.DataInputBuffer;
 import org.apache.hadoop.io.DataOutputBuffer;
 import org.apache.hadoop.io.Text;
 
+import com.google.common.base.Preconditions;
 import com.google.gson.Gson;
 
 /**
@@ -161,12 +162,32 @@ public class StoredTabletFile extends 
AbstractTabletFile<StoredTabletFile> {
     return new StoredTabletFile(metadataEntry);
   }
 
+  private static boolean isOnlyRowSet(Key key) {
+    return key.getColumnFamilyData().length() == 0 && 
key.getColumnQualifierData().length() == 0
+        && key.getColumnVisibilityData().length() == 0 && key.getTimestamp() 
== Long.MAX_VALUE;
+  }
+
+  static Range requireRowRange(Range range) {
+    if (!range.isInfiniteStartKey()) {
+      Preconditions.checkArgument(range.isStartKeyInclusive() && 
isOnlyRowSet(range.getStartKey()),
+          "Range is not a row range %s", range);
+    }
+
+    if (!range.isInfiniteStopKey()) {
+      Preconditions.checkArgument(!range.isEndKeyInclusive() && 
isOnlyRowSet(range.getEndKey()),
+          "Range is not a row range %s", range);
+    }
+
+    return range;
+  }
+
   public static StoredTabletFile of(final URI path, Range range) {
     return of(new Path(Objects.requireNonNull(path)), range);
   }
 
   public static StoredTabletFile of(final Path path, Range range) {
-    return new StoredTabletFile(new TabletFileCq(Objects.requireNonNull(path), 
range));
+    return new StoredTabletFile(
+        new TabletFileCq(Objects.requireNonNull(path), 
requireRowRange(range)));
   }
 
   private static final Gson gson = 
ByteArrayToBase64TypeAdapter.createBase64Gson();
diff --git 
a/core/src/test/java/org/apache/accumulo/core/metadata/schema/ReferencedTabletFileTest.java
 
b/core/src/test/java/org/apache/accumulo/core/metadata/schema/ReferencedTabletFileTest.java
index a71f26365c..ff4b818926 100644
--- 
a/core/src/test/java/org/apache/accumulo/core/metadata/schema/ReferencedTabletFileTest.java
+++ 
b/core/src/test/java/org/apache/accumulo/core/metadata/schema/ReferencedTabletFileTest.java
@@ -24,10 +24,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.net.URI;
 
+import org.apache.accumulo.core.data.Key;
 import org.apache.accumulo.core.data.Range;
 import org.apache.accumulo.core.data.TableId;
 import org.apache.accumulo.core.metadata.ReferencedTabletFile;
 import org.apache.accumulo.core.metadata.StoredTabletFile;
+import org.apache.hadoop.fs.Path;
 import org.junit.jupiter.api.Test;
 
 public class ReferencedTabletFileTest {
@@ -117,4 +119,25 @@ public class ReferencedTabletFileTest {
     assertEquals(niceFile.hashCode(), uglyFile.hashCode());
   }
 
+  @Test
+  public void testNonRowRange() {
+    Path testPath = new 
Path("hdfs://localhost:8020/accumulo/tables/2a/default_tablet/F0000070.rf");
+
+    // range where start key is not a row key
+    Range r1 = new Range(new Key("r1", "f1"), true, null, false);
+    assertThrows(IllegalArgumentException.class, () -> new 
ReferencedTabletFile(testPath, r1));
+
+    // range where end key is not a row key
+    Range r2 = new Range(null, true, new Key("r1", "f1"), false);
+    assertThrows(IllegalArgumentException.class, () -> new 
ReferencedTabletFile(testPath, r2));
+
+    // range where the key looks like a row, but the start key inclusivity is 
not whats expected
+    Range r3 = new Range(new Key("r1"), false, new Key("r2"), false);
+    assertThrows(IllegalArgumentException.class, () -> new 
ReferencedTabletFile(testPath, r3));
+
+    // range where the key looks like a row, but the end key inclusivity is 
not whats expected
+    Range r4 = new Range(new Key("r1"), true, new Key("r2"), true);
+    assertThrows(IllegalArgumentException.class, () -> new 
ReferencedTabletFile(testPath, r4));
+  }
+
 }

Reply via email to