Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

87 changes: 75 additions & 12 deletions src/test/java/org/apache/accumulo/proxy/its/SimpleProxyBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@
import org.apache.accumulo.cluster.ClusterUser;
import org.apache.accumulo.core.client.Accumulo;
import org.apache.accumulo.core.client.AccumuloClient;
import org.apache.accumulo.core.client.admin.compaction.TooManyDeletesSelector;
import org.apache.accumulo.core.client.security.tokens.KerberosToken;
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
import org.apache.accumulo.core.client.summary.summarizers.DeletesSummarizer;
import org.apache.accumulo.core.clientImpl.ClientInfo;
import org.apache.accumulo.core.clientImpl.Namespace;
import org.apache.accumulo.core.conf.DefaultConfiguration;
Expand Down Expand Up @@ -2216,6 +2218,7 @@ private int countFiles(String table) throws Exception {
break;
}
}
client.closeScanner(scanner);
return result;
}

Expand Down Expand Up @@ -2257,27 +2260,87 @@ public void testGetRowRange() throws Exception {
assertEquals(range.stop.timestamp, range.stop.timestamp);
}

private void addFile(String tableName, int startRow, int endRow, boolean delete)
throws TException {
Map<ByteBuffer,List<ColumnUpdate>> mutation = new HashMap<>();

for (int i = startRow; i < endRow; i++) {
String row = String.format("%09d", i);
ColumnUpdate columnUpdate = newColUpdate("cf", "cq", "v" + i);
columnUpdate.setDeleteCell(delete);
mutation.put(s2bb(row), List.of(columnUpdate));
}

client.updateAndFlush(sharedSecret, tableName, mutation);
client.flushTable(sharedSecret, tableName, null, null, true);
}

/**
* Test to make sure we can specify a Selector from the proxy client, and it will take effect when
* compactions occur
*/
@Test
public void testCompactionSelector() throws Exception {

String[] data = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z".split(" ");
final int expectedFileCount = data.length;
// delete table so new tables won't have the same name
client.deleteTable(sharedSecret, tableName);

final String[] tableNames = getUniqueNameArray(3);

for (String datum : data) {
client.addSplits(sharedSecret, tableName, Set.of(s2bb(datum)));
client.updateAndFlush(sharedSecret, tableName, mutation(datum, "cf", "cq", datum));
client.flushTable(sharedSecret, tableName, null, null, true);
// for each table, set the summarizer property needed for TooManyDeletesSelector
final String summarizerKey = Property.TABLE_SUMMARIZER_PREFIX + "s1";
final String summarizerClassName = DeletesSummarizer.class.getName();

for (String tableName : tableNames) {
client.createTable(sharedSecret, tableName, true, TimeType.MILLIS);
client.setTableProperty(sharedSecret, tableName, summarizerKey, summarizerClassName);
}

assertEquals(expectedFileCount, countFiles(tableName), "Unexpected file count");
// add files to each table

addFile(tableNames[0], 1, 1000, false);
addFile(tableNames[0], 1, 1000, true);

addFile(tableNames[1], 1, 1000, false);
addFile(tableNames[1], 1000, 2000, false);

addFile(tableNames[2], 1, 2000, false);
addFile(tableNames[2], 1, 1000, true);

final String messagePrefix = "Unexpected file count on table ";

for (String tableName : tableNames) {
assertEquals(2, countFiles(tableName), messagePrefix + tableName);
}

// compact the tables and check for expected file counts

final String selectorClassname = TooManyDeletesSelector.class.getName();
PluginConfig selector = new PluginConfig(selectorClassname, Map.of("threshold", ".99"));

for (String tableName : tableNames) {
client.compactTable(sharedSecret, tableName, null, null, null, true, true, selector, null);
}

assertEquals(0, countFiles(tableNames[0]), messagePrefix + tableNames[0]);
assertEquals(2, countFiles(tableNames[1]), messagePrefix + tableNames[1]);
assertEquals(2, countFiles(tableNames[2]), messagePrefix + tableNames[2]);

// create a selector with different properties then compact and check file counts

selector = new PluginConfig(selectorClassname, Map.of("threshold", ".40"));

for (String tableName : tableNames) {
client.compactTable(sharedSecret, tableName, null, null, null, true, true, selector, null);
}

String selectorClassname = SelectHalfSelector.class.getName();
PluginConfig selector = new PluginConfig(selectorClassname, Map.of());
assertEquals(0, countFiles(tableNames[0]), messagePrefix + tableNames[0]);
assertEquals(2, countFiles(tableNames[1]), messagePrefix + tableNames[1]);
assertEquals(1, countFiles(tableNames[2]), messagePrefix + tableNames[2]);

client.compactTable(sharedSecret, tableName, null, null, null, true, true, selector, null);
client.compactTable(sharedSecret, tableNames[1], null, null, null, true, true, null, null);

// SelectHalfSelector should lead to half the files being compacted
Wait.waitFor(() -> countFiles(tableName) == (expectedFileCount / 2));
assertEquals(1, countFiles(tableNames[1]), messagePrefix + tableNames[2]);
}

@Test
Expand Down