use of org.apache.accumulo.proxy.thrift.IteratorSetting in project accumulo by apache.
the class SimpleProxyBase method iteratorFunctionality.
@Test
public void iteratorFunctionality() throws Exception {
// iterators
HashMap<String, String> options = new HashMap<>();
options.put("type", "STRING");
options.put("columns", "cf");
IteratorSetting setting = new IteratorSetting(10, tableName, SummingCombiner.class.getName(), options);
client.attachIterator(creds, tableName, setting, EnumSet.allOf(IteratorScope.class));
for (int i = 0; i < 10; i++) {
client.updateAndFlush(creds, tableName, mutation("row1", "cf", "cq", "1"));
}
// 10 updates of "1" in the value w/ SummingCombiner should return value of "10"
assertScan(new String[][] { { "row1", "cf", "cq", "10" } }, tableName);
try {
client.checkIteratorConflicts(creds, tableName, setting, EnumSet.allOf(IteratorScope.class));
fail("checkIteratorConflicts did not throw an exception");
} catch (Exception ex) {
// Expected
}
client.deleteRows(creds, tableName, null, null);
client.removeIterator(creds, tableName, "test", EnumSet.allOf(IteratorScope.class));
String[][] expected = new String[10][];
for (int i = 0; i < 10; i++) {
client.updateAndFlush(creds, tableName, mutation("row" + i, "cf", "cq", "" + i));
expected[i] = new String[] { "row" + i, "cf", "cq", "" + i };
client.flushTable(creds, tableName, null, null, true);
}
assertScan(expected, tableName);
}
use of org.apache.accumulo.proxy.thrift.IteratorSetting in project accumulo by apache.
the class SimpleProxyBase method checkNamespaceIteratorConflictsLoginFailure.
@Test(expected = AccumuloSecurityException.class, timeout = 5000)
public void checkNamespaceIteratorConflictsLoginFailure() throws Exception {
IteratorSetting setting = new IteratorSetting(100, "DebugTheThings", DebugIterator.class.getName(), Collections.emptyMap());
client.checkNamespaceIteratorConflicts(badLogin, namespaceName, setting, EnumSet.allOf(IteratorScope.class));
}
use of org.apache.accumulo.proxy.thrift.IteratorSetting in project accumulo by apache.
the class SimpleProxyBase method attachIteratorWithCompactions.
@Test
public void attachIteratorWithCompactions() throws Exception {
if (client.tableExists(creds, "slow")) {
client.deleteTable(creds, "slow");
}
// create a table that's very slow, so we can look for compactions
client.createTable(creds, "slow", true, TimeType.MILLIS);
IteratorSetting setting = new IteratorSetting(100, "slow", SlowIterator.class.getName(), Collections.singletonMap("sleepTime", "250"));
client.attachIterator(creds, "slow", setting, EnumSet.allOf(IteratorScope.class));
// Should take 10 seconds to read every record
for (int i = 0; i < 40; i++) {
client.updateAndFlush(creds, "slow", mutation("row" + i, "cf", "cq", "value"));
}
Map<String, String> map = client.tableIdMap(creds);
// start a compaction
Thread t = new Thread() {
@Override
public void run() {
TestProxyClient proxyClient2 = null;
try {
if (isKerberosEnabled()) {
UserGroupInformation.loginUserFromKeytab(clientPrincipal, clientKeytab.getAbsolutePath());
proxyClient2 = new TestProxyClient(hostname, proxyPort, factory, proxyPrimary, UserGroupInformation.getCurrentUser());
} else {
proxyClient2 = new TestProxyClient(hostname, proxyPort, factory);
}
Client client2 = proxyClient2.proxy();
client2.compactTable(creds, "slow", null, null, null, true, true, null);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (null != proxyClient2) {
proxyClient2.close();
}
}
}
};
t.start();
final String desiredTableId = map.get("slow");
// Make sure we can find the slow table
assertNotNull(desiredTableId);
// try to catch it in the act
List<ActiveCompaction> compactions = new ArrayList<>();
for (int i = 0; i < 100 && compactions.isEmpty(); i++) {
// Iterate over the tservers
for (String tserver : client.getTabletServers(creds)) {
// And get the compactions on each
List<ActiveCompaction> compactionsOnServer = client.getActiveCompactions(creds, tserver);
for (ActiveCompaction compact : compactionsOnServer) {
// case we want to prune out those that aren't for our slow table
if (desiredTableId.equals(compact.getExtent().tableId)) {
compactions.add(compact);
}
}
// If we found a compaction for the table we wanted, so we can stop looking
if (!compactions.isEmpty())
break;
}
sleepUninterruptibly(10, TimeUnit.MILLISECONDS);
}
t.join();
// verify the compaction information
assertFalse(compactions.isEmpty());
for (ActiveCompaction c : compactions) {
if (desiredTableId.equals(c.getExtent().tableId)) {
assertTrue(c.inputFiles.isEmpty());
assertEquals(CompactionType.MINOR, c.getType());
assertEquals(CompactionReason.USER, c.getReason());
assertEquals("", c.localityGroup);
assertTrue(c.outputFile.contains("default_tablet"));
return;
}
}
fail("Expection to find running compaction for table 'slow' but did not find one");
}
use of org.apache.accumulo.proxy.thrift.IteratorSetting in project accumulo by apache.
the class TestProxyReadWrite method readWriteOneShotWithFilterIterator.
/**
* Insert 100000 cells which have as the row [0..99999] (padded with zeros). Filter the results so only the even numbers come back.
*/
@Test
public void readWriteOneShotWithFilterIterator() throws Exception {
int maxInserts = 10000;
Map<ByteBuffer, List<ColumnUpdate>> mutations = new HashMap<>();
String format = "%1$05d";
for (int i = 0; i < maxInserts; i++) {
addMutation(mutations, String.format(format, i), "cf" + i, "cq" + i, Util.randString(10));
if (i % 1000 == 0 || i == maxInserts - 1) {
tpc.proxy().updateAndFlush(userpass, testtable, mutations);
mutations.clear();
}
}
String regex = ".*[02468]";
org.apache.accumulo.core.client.IteratorSetting is = new org.apache.accumulo.core.client.IteratorSetting(50, regex, RegExFilter.class);
RegExFilter.setRegexs(is, regex, null, null, null, false);
IteratorSetting pis = Util.iteratorSetting2ProxyIteratorSetting(is);
ScanOptions opts = new ScanOptions();
opts.iterators = Collections.singletonList(pis);
String cookie = tpc.proxy().createScanner(userpass, testtable, opts);
int i = 0;
boolean hasNext = true;
int k = 1000;
while (hasNext) {
ScanResult kvList = tpc.proxy().nextK(cookie, k);
for (KeyValue kv : kvList.getResults()) {
assertEquals(Integer.parseInt(new String(kv.getKey().getRow())), i);
i += 2;
}
hasNext = kvList.isMore();
}
}
Aggregations