This is an automated email from the ASF dual-hosted git repository. kturner pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/accumulo.git
commit b63afacfa6d0f9d5be7b2ea8887befb08ea84b6c Merge: 372fe8fd4f f2448f28da Author: Keith Turner <ktur...@apache.org> AuthorDate: Fri Jun 14 17:30:16 2024 -0400 Merge branch '2.1' .../core/metadata/schema/TabletMetadataTest.java | 27 +++++++++++++++++++ .../shell/commands/ActiveCompactionHelper.java | 30 +++++++++------------- .../shell/commands/ListCompactionsCommand.java | 2 +- 3 files changed, 40 insertions(+), 19 deletions(-) diff --cc core/src/test/java/org/apache/accumulo/core/metadata/schema/TabletMetadataTest.java index 8c3d84de2c,a164efc8ed..586f697ae8 --- a/core/src/test/java/org/apache/accumulo/core/metadata/schema/TabletMetadataTest.java +++ b/core/src/test/java/org/apache/accumulo/core/metadata/schema/TabletMetadataTest.java @@@ -26,9 -24,7 +26,10 @@@ import static org.apache.accumulo.core. import static org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily.DIRECTORY_COLUMN; import static org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily.FLUSH_COLUMN; import static org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily.TIME_COLUMN; +import static org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn.SUSPEND_COLUMN; +import static org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily.OLD_PREV_ROW_COLUMN; +import static org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily.SPLIT_RATIO_COLUMN; + import static org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.DIR; import static org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.LAST; import static org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.LOCATION; import static org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.PREV_ROW; @@@ -352,68 -289,32 +353,94 @@@ public class TabletMetadataTest assertTrue(closeCalled.get()); } + @Test + public void testTmBuilderImmutable() { + TabletMetadata.Builder b = new Builder(); + var tm = b.build(EnumSet.allOf(ColumnType.class)); + + ExternalCompactionId ecid = ExternalCompactionId.generate(UUID.randomUUID()); + ReferencedTabletFile tmpFile = + ReferencedTabletFile.of(new Path("file:///accumulo/tables/t-0/b-0/c1.rf")); + CompactionExecutorId ceid = CompactionExecutorIdImpl.externalId("G1"); + StoredTabletFile stf = StoredTabletFile.of(new Path("file:///accumulo/tables/t-0/b-0/b2.rf")); + Set<StoredTabletFile> jobFiles = Set.of(stf); + ExternalCompactionMetadata ecMeta = new ExternalCompactionMetadata(jobFiles, jobFiles, tmpFile, + "localhost:4444", CompactionKind.SYSTEM, (short) 2, ceid, false, false, 44L); + + // Verify the various collections are immutable and non-null (except for getKeyValues) if + // nothing set on the builder + assertTrue(tm.getExternalCompactions().isEmpty()); + assertThrows(UnsupportedOperationException.class, + () -> tm.getExternalCompactions().put(ecid, ecMeta)); + assertTrue(tm.getFiles().isEmpty()); + assertTrue(tm.getFilesMap().isEmpty()); + assertThrows(UnsupportedOperationException.class, () -> tm.getFiles().add(stf)); + assertThrows(UnsupportedOperationException.class, + () -> tm.getFilesMap().put(stf, new DataFileValue(0, 0, 0))); + assertTrue(tm.getLogs().isEmpty()); + assertThrows(UnsupportedOperationException.class, + () -> tm.getLogs().add(LogEntry.fromPath("localhost+8020/" + UUID.randomUUID()))); + assertTrue(tm.getScans().isEmpty()); + assertThrows(UnsupportedOperationException.class, () -> tm.getScans().add(stf)); + assertTrue(tm.getLoaded().isEmpty()); + assertThrows(UnsupportedOperationException.class, () -> tm.getLoaded().put(stf, 0L)); + assertThrows(IllegalStateException.class, tm::getKeyValues); + + // Set some data in the collections and very they are not empty but still immutable + b.extCompaction(ecid, ecMeta); + b.file(stf, new DataFileValue(0, 0, 0)); + b.log(LogEntry.fromPath("localhost+8020/" + UUID.randomUUID())); + b.scan(stf); + b.loadedFile(stf, 0L); + b.keyValue(new AbstractMap.SimpleImmutableEntry<>(new Key(), new Value())); + var tm2 = b.build(EnumSet.allOf(ColumnType.class)); + + assertEquals(1, tm2.getExternalCompactions().size()); + assertThrows(UnsupportedOperationException.class, + () -> tm2.getExternalCompactions().put(ecid, ecMeta)); + assertEquals(1, tm2.getFiles().size()); + assertEquals(1, tm2.getFilesMap().size()); + assertThrows(UnsupportedOperationException.class, () -> tm2.getFiles().add(stf)); + assertThrows(UnsupportedOperationException.class, + () -> tm2.getFilesMap().put(stf, new DataFileValue(0, 0, 0))); + assertEquals(1, tm2.getLogs().size()); + assertThrows(UnsupportedOperationException.class, + () -> tm2.getLogs().add(LogEntry.fromPath("localhost+8020/" + UUID.randomUUID()))); + assertEquals(1, tm2.getScans().size()); + assertThrows(UnsupportedOperationException.class, () -> tm2.getScans().add(stf)); + assertEquals(1, tm2.getLoaded().size()); + assertThrows(UnsupportedOperationException.class, () -> tm2.getLoaded().put(stf, 0L)); + assertEquals(1, tm2.getKeyValues().size()); + assertThrows(UnsupportedOperationException.class, () -> tm2.getKeyValues().remove(null)); + + } + + @Test + public void testAbsentPrevRow() { + // If the prev row is fetched, then it is expected to be seen. Ensure that if it was not seen + // that TabletMetadata fails when attempting to use it. Want to ensure null is not returned for + // this case. + Mutation mutation = + new Mutation(MetadataSchema.TabletsSection.encodeRow(TableId.of("5"), new Text("df"))); + DIRECTORY_COLUMN.put(mutation, new Value("d1")); + SortedMap<Key,Value> rowMap = toRowMap(mutation); + + var tm = TabletMetadata.convertRow(rowMap.entrySet().iterator(), + EnumSet.allOf(ColumnType.class), false); + + var msg = assertThrows(IllegalStateException.class, tm::getExtent).getMessage(); + assertTrue(msg.contains("No prev endrow seen")); + msg = assertThrows(IllegalStateException.class, tm::getPrevEndRow).getMessage(); + assertTrue(msg.contains("No prev endrow seen")); + + // should see a slightly different error message when the prev row is not fetched + tm = TabletMetadata.convertRow(rowMap.entrySet().iterator(), EnumSet.of(DIR), false); + msg = assertThrows(IllegalStateException.class, tm::getExtent).getMessage(); + assertTrue(msg.contains("PREV_ROW was not fetched")); + msg = assertThrows(IllegalStateException.class, tm::getPrevEndRow).getMessage(); + assertTrue(msg.contains("PREV_ROW was not fetched")); + } + private SortedMap<Key,Value> toRowMap(Mutation mutation) { SortedMap<Key,Value> rowMap = new TreeMap<>(); mutation.getUpdates().forEach(cu -> {