You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by cs...@apache.org on 2023/10/20 10:52:35 UTC
[accumulo] branch main updated: Add tests to SampleIT for files with ranges (#3824)
This is an automated email from the ASF dual-hosted git repository.
cshannon pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push:
new 0d8b9d1939 Add tests to SampleIT for files with ranges (#3824)
0d8b9d1939 is described below
commit 0d8b9d1939de4612243d2cb54b799a8ab9d7d298
Author: Christopher L. Shannon <ch...@gmail.com>
AuthorDate: Fri Oct 20 06:52:29 2023 -0400
Add tests to SampleIT for files with ranges (#3824)
This updates the sample ITs to test that sampling works correctly with
fenced files and that only sample data that is in the given ranges will
be returned on scans
This addresses part of #3766
---
.../java/org/apache/accumulo/test/SampleIT.java | 136 ++++++++++++++++++++-
.../accumulo/test/util/FileMetadataUtil.java | 75 +++++++++++-
2 files changed, 205 insertions(+), 6 deletions(-)
diff --git a/test/src/main/java/org/apache/accumulo/test/SampleIT.java b/test/src/main/java/org/apache/accumulo/test/SampleIT.java
index 369444ac0a..c4f4a5fbd6 100644
--- a/test/src/main/java/org/apache/accumulo/test/SampleIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/SampleIT.java
@@ -18,6 +18,7 @@
*/
package org.apache.accumulo.test;
+import static org.apache.accumulo.test.util.FileMetadataUtil.countFiles;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -26,11 +27,13 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
+import java.util.stream.Collectors;
import org.apache.accumulo.core.client.Accumulo;
import org.apache.accumulo.core.client.AccumuloClient;
@@ -52,6 +55,7 @@ import org.apache.accumulo.core.client.sample.RowSampler;
import org.apache.accumulo.core.client.sample.SamplerConfiguration;
import org.apache.accumulo.core.clientImpl.ClientContext;
import org.apache.accumulo.core.clientImpl.OfflineScanner;
+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.Mutation;
@@ -63,6 +67,8 @@ import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
import org.apache.accumulo.core.iterators.WrappingIterator;
import org.apache.accumulo.core.security.Authorizations;
import org.apache.accumulo.harness.AccumuloClusterHarness;
+import org.apache.accumulo.test.util.FileMetadataUtil;
+import org.apache.hadoop.io.Text;
import org.junit.jupiter.api.Test;
import com.google.common.collect.Iterables;
@@ -120,14 +126,75 @@ public class SampleIT extends AccumuloClusterHarness {
}
}
+ @Test
+ public void testSampleFencing() throws Exception {
+
+ try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
+ String tableName = getUniqueNames(1)[0];
+ String clone = tableName + "_clone";
+
+ createTable(client, tableName, new NewTableConfiguration().enableSampling(SC1));
+
+ BatchWriter bw = client.createBatchWriter(tableName);
+
+ TreeMap<Key,Value> expected = new TreeMap<>();
+ writeData(bw, SC1, expected);
+ assertEquals(20, expected.size());
+
+ Scanner scanner = client.createScanner(tableName, Authorizations.EMPTY);
+ Scanner isoScanner =
+ new IsolatedScanner(client.createScanner(tableName, Authorizations.EMPTY));
+ Scanner csiScanner =
+ new ClientSideIteratorScanner(client.createScanner(tableName, Authorizations.EMPTY));
+ scanner.setSamplerConfiguration(SC1);
+ csiScanner.setSamplerConfiguration(SC1);
+ isoScanner.setSamplerConfiguration(SC1);
+ isoScanner.setBatchSize(10);
+
+ try (BatchScanner bScanner = client.createBatchScanner(tableName)) {
+ bScanner.setSamplerConfiguration(SC1);
+ bScanner.setRanges(Arrays.asList(new Range()));
+
+ check(expected, scanner, bScanner, isoScanner, csiScanner);
+
+ client.tableOperations().flush(tableName, null, null, true);
+
+ // Fence off the data to a Range that is a subset of the original data
+ Range fenced = new Range(new Text(String.format("r_%06d", 3000)),
+ new Text(String.format("r_%06d", 6000)));
+ FileMetadataUtil.splitFilesIntoRanges(getServerContext(), tableName, Set.of(fenced));
+ assertEquals(1, countFiles(getServerContext(), tableName));
+
+ // Build the map of expected values to be seen by filtering out keys not in the fenced range
+ TreeMap<Key,Value> fenceExpected =
+ expected.entrySet().stream().filter(entry -> fenced.contains(entry.getKey())).collect(
+ Collectors.toMap(Entry::getKey, Entry::getValue, (v1, v2) -> v1, TreeMap::new));
+
+ Scanner oScanner = newOfflineScanner(client, tableName, clone, SC1);
+
+ // verify only the correct values in the fenced range are seen
+ check(fenceExpected, scanner, bScanner, isoScanner, csiScanner, oScanner);
+ }
+ }
+ }
+
@Test
public void testBasic() throws Exception {
+ testBasic(Set.of());
+ }
+
+ @Test
+ public void testBasicWithFencedFiles() throws Exception {
+ testBasic(createRanges());
+ }
+
+ private void testBasic(Set<Range> fileRanges) throws Exception {
try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
String tableName = getUniqueNames(1)[0];
String clone = tableName + "_clone";
- client.tableOperations().create(tableName, new NewTableConfiguration().enableSampling(SC1));
+ createTable(client, tableName, new NewTableConfiguration().enableSampling(SC1));
BatchWriter bw = client.createBatchWriter(tableName);
@@ -153,6 +220,12 @@ public class SampleIT extends AccumuloClusterHarness {
client.tableOperations().flush(tableName, null, null, true);
+ // Split files into ranged files if provided
+ if (!fileRanges.isEmpty()) {
+ FileMetadataUtil.splitFilesIntoRanges(getServerContext(), tableName, fileRanges);
+ assertEquals(fileRanges.size(), countFiles(getServerContext(), tableName));
+ }
+
Scanner oScanner = newOfflineScanner(client, tableName, clone, SC1);
check(expected, scanner, bScanner, isoScanner, csiScanner, oScanner);
@@ -293,11 +366,20 @@ public class SampleIT extends AccumuloClusterHarness {
@Test
public void testIterator() throws Exception {
+ testIterator(Set.of());
+ }
+
+ @Test
+ public void testIteratorFencedFiles() throws Exception {
+ testIterator(createRanges());
+ }
+
+ private void testIterator(Set<Range> fileRanges) throws Exception {
try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
String tableName = getUniqueNames(1)[0];
String clone = tableName + "_clone";
- client.tableOperations().create(tableName, new NewTableConfiguration().enableSampling(SC1));
+ createTable(client, tableName, new NewTableConfiguration().enableSampling(SC1));
TreeMap<Key,Value> expected = new TreeMap<>();
try (BatchWriter bw = client.createBatchWriter(tableName)) {
@@ -346,6 +428,12 @@ public class SampleIT extends AccumuloClusterHarness {
// flush an rerun same test against files
client.tableOperations().flush(tableName, null, null, true);
+ // Split files into ranged files if provided
+ if (!fileRanges.isEmpty()) {
+ FileMetadataUtil.splitFilesIntoRanges(getServerContext(), tableName, fileRanges);
+ assertEquals(fileRanges.size(), countFiles(getServerContext(), tableName));
+ }
+
oScanner = newOfflineScanner(client, tableName, clone, null);
oScanner.addScanIterator(new IteratorSetting(100, IteratorThatUsesSample.class));
scanners = Arrays.asList(scanner, isoScanner, bScanner, csiScanner, oScanner);
@@ -401,12 +489,21 @@ public class SampleIT extends AccumuloClusterHarness {
@Test
public void testSampleNotPresent() throws Exception {
+ testSampleNotPresent(Set.of());
+ }
+
+ @Test
+ public void testSampleNotPresentFencedFiles() throws Exception {
+ testSampleNotPresent(createRanges());
+ }
+
+ private void testSampleNotPresent(Set<Range> fileRanges) throws Exception {
try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
String tableName = getUniqueNames(1)[0];
String clone = tableName + "_clone";
- client.tableOperations().create(tableName);
+ createTable(client, tableName, new NewTableConfiguration());
TreeMap<Key,Value> expected = new TreeMap<>();
try (BatchWriter bw = client.createBatchWriter(tableName)) {
@@ -425,12 +522,17 @@ public class SampleIT extends AccumuloClusterHarness {
client.tableOperations().flush(tableName, null, null, true);
+ // Split files into ranged files if provided
+ if (!fileRanges.isEmpty()) {
+ FileMetadataUtil.splitFilesIntoRanges(getServerContext(), tableName, fileRanges);
+ assertEquals(fileRanges.size(), countFiles(getServerContext(), tableName));
+ }
+
Scanner oScanner = newOfflineScanner(client, tableName, clone, SC1);
assertSampleNotPresent(SC1, scanner, isoScanner, bScanner, csiScanner, oScanner);
// configure sampling, however there exist an rfile w/o sample data... so should still see
// sample not present exception
-
updateSamplingConfig(client, tableName, SC1);
// create clone with new config
@@ -509,4 +611,30 @@ public class SampleIT extends AccumuloClusterHarness {
actual.size(), expected.size(), s.getClass().getSimpleName()));
}
}
+
+ private Set<Range> createRanges() {
+ Set<Range> ranges = new HashSet<>();
+
+ int splits = 10;
+
+ for (int i = 0; i < splits; i++) {
+ Text start = i > 0 ? new Text(String.format("r_%06d", i * 1000)) : null;
+ Text end = i < splits - 1 ? new Text(String.format("r_%06d", (i + 1) * 1000)) : null;
+ ranges.add(new Range(start, end));
+ }
+
+ return ranges;
+ }
+
+ // Create a table and disable compactions. This is important to prevent intermittent
+ // failures when testing if sampling is configured or not. Some of the tests first
+ // assert sampling is not available, then configures sampling and tests it still isn't
+ // available before triggering a compaction to confirm it is now available. Intermittent
+ // GCs can make these tests non-deterministic when there are a lot of files created
+ // during the fencing tests.
+ private void createTable(AccumuloClient client, String tableName, NewTableConfiguration ntc)
+ throws Exception {
+ ntc.setProperties(Map.of(Property.TABLE_MAJC_RATIO.getKey(), "9999"));
+ client.tableOperations().create(tableName, ntc);
+ }
}
diff --git a/test/src/main/java/org/apache/accumulo/test/util/FileMetadataUtil.java b/test/src/main/java/org/apache/accumulo/test/util/FileMetadataUtil.java
index f84d5138b8..b4bc67d854 100644
--- a/test/src/main/java/org/apache/accumulo/test/util/FileMetadataUtil.java
+++ b/test/src/main/java/org/apache/accumulo/test/util/FileMetadataUtil.java
@@ -23,17 +23,25 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
+import java.util.TreeMap;
+import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
import org.apache.accumulo.core.metadata.StoredTabletFile;
+import org.apache.accumulo.core.metadata.schema.Ample.TabletMutator;
import org.apache.accumulo.core.metadata.schema.DataFileValue;
import org.apache.accumulo.core.metadata.schema.TabletMetadata;
import org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType;
import org.apache.accumulo.core.metadata.schema.TabletsMetadata;
import org.apache.accumulo.server.ServerContext;
+import org.apache.hadoop.io.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.Preconditions;
+
public class FileMetadataUtil {
private static final Logger log = LoggerFactory.getLogger(FileMetadataUtil.class);
@@ -53,8 +61,8 @@ public class FileMetadataUtil {
// Read each file referenced by that table
int i = 0;
for (TabletMetadata tabletMetadata : tabletsMetadata) {
- for (Entry<StoredTabletFile,DataFileValue> fileEntry : tabletMetadata.getFilesMap()
- .entrySet()) {
+ for (Entry<StoredTabletFile,
+ DataFileValue> fileEntry : new TreeMap<>(tabletMetadata.getFilesMap()).entrySet()) {
StoredTabletFile file = fileEntry.getKey();
DataFileValue dfv = fileEntry.getValue();
files.put(file, dfv);
@@ -73,4 +81,67 @@ public class FileMetadataUtil {
return files;
}
+
+ public static int countFiles(final ServerContext ctx, String tableName) {
+ return countFiles(ctx, tableName, null, null);
+ }
+
+ public static int countFiles(final ServerContext ctx, String tableName, Text tabletStartRow,
+ Text tabletEndRow) {
+ final TableId tableId = TableId.of(ctx.tableOperations().tableIdMap().get(tableName));
+ try (TabletsMetadata tabletsMetadata = ctx.getAmple().readTablets().forTable(tableId)
+ .overlapping(tabletStartRow, tabletEndRow).fetch(ColumnType.FILES).build()) {
+ return tabletsMetadata.stream().mapToInt(tm -> tm.getFilesMap().size()).sum();
+ }
+ }
+
+ public static void splitFilesIntoRanges(final ServerContext ctx, String tableName,
+ Set<Range> fileRanges) throws Exception {
+ splitFilesIntoRanges(ctx, tableName, null, null, fileRanges);
+ }
+
+ public static void splitFilesIntoRanges(final ServerContext ctx, String tableName,
+ Text tabletStartRow, Text tabletEndRow, Set<Range> fileRanges) throws Exception {
+ Preconditions.checkArgument(!fileRanges.isEmpty(), "Ranges must not be empty");
+
+ final TableId tableId = TableId.of(ctx.tableOperations().tableIdMap().get(tableName));
+
+ // Bring tablet offline so we can modify file metadata
+ ctx.tableOperations().offline(tableName, true);
+
+ try (TabletsMetadata tabletsMetadata =
+ ctx.getAmple().readTablets().forTable(tableId).overlapping(tabletStartRow, tabletEndRow)
+ .fetch(ColumnType.FILES, ColumnType.PREV_ROW).build()) {
+
+ // Read each file and split to 10 ranges
+ for (TabletMetadata tabletMetadata : tabletsMetadata) {
+ final KeyExtent ke = tabletMetadata.getExtent();
+
+ // Create a mutation to delete the existing file metadata entry with infinite range
+ TabletMutator mutator = ctx.getAmple().mutateTablet(ke);
+
+ // Read each files and split into the given ranges
+ for (Entry<StoredTabletFile,DataFileValue> fileEntry : tabletMetadata.getFilesMap()
+ .entrySet()) {
+ StoredTabletFile file = fileEntry.getKey();
+ DataFileValue value = fileEntry.getValue();
+
+ // Create a mutation to delete the existing file metadata entry with infinite range
+ mutator.deleteFile(file);
+
+ fileRanges.forEach(range -> {
+ final DataFileValue newValue =
+ new DataFileValue(Integer.max(1, (int) (value.getSize() / fileRanges.size())),
+ Integer.max(1, (int) (value.getNumEntries() / fileRanges.size())));
+ mutator.putFile(StoredTabletFile.of(file.getPath(), range), newValue);
+ });
+
+ mutator.mutate();
+ }
+ }
+ }
+
+ ctx.tableOperations().online(tableName, true);
+ }
+
}