This is an automated email from the ASF dual-hosted git repository.
dlmarion pushed a commit to branch elasticity
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/elasticity by this push:
new b0f02ea6de Validate seek range in TabletManagementIterator (#4507)
b0f02ea6de is described below
commit b0f02ea6dec86297bd752aba73ee67ff11c06c16
Author: Dave Marion <[email protected]>
AuthorDate: Fri May 10 08:32:23 2024 -0400
Validate seek range in TabletManagementIterator (#4507)
Closes #4496
---
.../manager/state/TabletManagementIterator.java | 21 ++++++++
.../state/TabletManagementIteratorTest.java | 60 ++++++++++++++++++++++
2 files changed, 81 insertions(+)
diff --git
a/server/base/src/main/java/org/apache/accumulo/server/manager/state/TabletManagementIterator.java
b/server/base/src/main/java/org/apache/accumulo/server/manager/state/TabletManagementIterator.java
index 3f5397a7a4..4b2ba5d4f7 100644
---
a/server/base/src/main/java/org/apache/accumulo/server/manager/state/TabletManagementIterator.java
+++
b/server/base/src/main/java/org/apache/accumulo/server/manager/state/TabletManagementIterator.java
@@ -20,6 +20,7 @@ package org.apache.accumulo.server.manager.state;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
@@ -35,7 +36,9 @@ import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.conf.ConfigurationCopy;
import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.iterators.IteratorEnvironment;
import org.apache.accumulo.core.iterators.SkippingIterator;
@@ -167,6 +170,23 @@ public class TabletManagementIterator extends
SkippingIterator {
balancer.init(benv);
}
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies,
boolean inclusive)
+ throws IOException {
+ if (range != null) {
+ // This iterator sits on top of the WholeRowIterator (see
configureScanner), so enforce
+ // that the start and end keys in the Range only have a row component to
the key.
+ for (Key k : new Key[] {range.getStartKey(), range.getEndKey()}) {
+ if (k != null && k.compareTo(new Key(k.getRow())) != 0) {
+ throw new IllegalArgumentException(
+ "TabletManagementIterator must be seeked with keys that only
contain a row, supplied range: "
+ + range);
+ }
+ }
+ }
+ super.seek(range, columnFamilies, inclusive);
+ }
+
@Override
public Key getTopKey() {
return topKey;
@@ -299,4 +319,5 @@ public class TabletManagementIterator extends
SkippingIterator {
return ALL_COMPACTION_KINDS;
}
}
+
}
diff --git
a/server/base/src/test/java/org/apache/accumulo/server/manager/state/TabletManagementIteratorTest.java
b/server/base/src/test/java/org/apache/accumulo/server/manager/state/TabletManagementIteratorTest.java
new file mode 100644
index 0000000000..a673777721
--- /dev/null
+++
b/server/base/src/test/java/org/apache/accumulo/server/manager/state/TabletManagementIteratorTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.accumulo.server.manager.state;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.IOException;
+import java.util.Set;
+
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.junit.jupiter.api.Test;
+
+public class TabletManagementIteratorTest {
+
+ @Test
+ public void testRanges() throws IOException {
+ TabletManagementIterator iter = new TabletManagementIterator();
+
+ // We don't call init, so expect a IllegalStateException on success and
+ // and IllegalArgumentException on failure
+ Key goodStartKey = new Key("row");
+ Key goodEndKey = new Key("rowEnd");
+
+ Key badStartKey = new Key("row", "colf", "colq", 1234L);
+ Key badEndKey = new Key("rowEnd", "colf", "colq", 1234L);
+
+ assertThrows(IllegalStateException.class, () -> iter.seek(null, Set.of(),
false));
+ assertThrows(IllegalStateException.class,
+ () -> iter.seek(new Range((Key) null, (Key) null), Set.of(), false));
+ assertThrows(IllegalStateException.class,
+ () -> iter.seek(new Range(goodStartKey, goodEndKey), Set.of(), false));
+ assertTrue(assertThrows(IllegalArgumentException.class,
+ () -> iter.seek(new Range(goodStartKey, badEndKey), Set.of(),
false)).getMessage()
+ .startsWith("TabletManagementIterator must be seeked"));
+ assertTrue(assertThrows(IllegalArgumentException.class,
+ () -> iter.seek(new Range(badStartKey, goodEndKey), Set.of(),
false)).getMessage()
+ .startsWith("TabletManagementIterator must be seeked"));
+ assertTrue(assertThrows(IllegalArgumentException.class,
+ () -> iter.seek(new Range(badStartKey, badEndKey), Set.of(),
false)).getMessage()
+ .startsWith("TabletManagementIterator must be seeked"));
+ }
+}