use of org.apache.accumulo.core.client.BatchWriterConfig in project accumulo by apache.
the class DeleteManyCommand method execute.
@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception {
final String tableName = OptUtil.getTableOpt(cl, shellState);
final ScanInterpreter interpeter = getInterpreter(cl, tableName, shellState);
// handle first argument, if present, the authorizations list to
// scan with
final Authorizations auths = getAuths(cl, shellState);
final Scanner scanner = shellState.getAccumuloClient().createScanner(tableName, auths);
scanner.addScanIterator(new IteratorSetting(Integer.MAX_VALUE, "NOVALUE", SortedKeyIterator.class));
// handle session-specific scan iterators
addScanIterators(shellState, cl, scanner, tableName);
// handle remaining optional arguments
scanner.setRange(getRange(cl, interpeter));
scanner.setTimeout(getTimeout(cl), TimeUnit.MILLISECONDS);
// handle columns
fetchColumns(cl, scanner, interpeter);
// output / delete the records
final BatchWriter writer = shellState.getAccumuloClient().createBatchWriter(tableName, new BatchWriterConfig().setTimeout(getTimeout(cl), TimeUnit.MILLISECONDS));
FormatterConfig config = new FormatterConfig();
config.setPrintTimestamps(cl.hasOption(timestampOpt.getOpt()));
shellState.printLines(new DeleterFormatter(writer, scanner, config, shellState, cl.hasOption(forceOpt.getOpt())), false);
return 0;
}
use of org.apache.accumulo.core.client.BatchWriterConfig in project accumulo by apache.
the class CleanUpIT method run.
@SuppressWarnings("deprecation")
@Test
public void run() throws Exception {
// CleanUp for Connectors will not work if there are active AccumuloClients
assertEquals(0, SingletonManager.getReservationCount());
// CleanUp was created to clean up after connectors. This test intentionally creates a connector
// instead of an AccumuloClient
org.apache.accumulo.core.client.Connector conn = new org.apache.accumulo.core.client.ZooKeeperInstance(getCluster().getInstanceName(), getCluster().getZooKeepers()).getConnector(getPrincipal(), getToken());
String tableName = getUniqueNames(1)[0];
conn.tableOperations().create(tableName);
BatchWriter bw = conn.createBatchWriter(tableName, new BatchWriterConfig());
Mutation m1 = new Mutation("r1");
m1.put("cf1", "cq1", 1, "5");
bw.addMutation(m1);
bw.flush();
try (Scanner scanner = conn.createScanner(tableName, new Authorizations())) {
int count = 0;
for (Entry<Key, Value> entry : scanner) {
count++;
if (!entry.getValue().toString().equals("5")) {
fail("Unexpected value " + entry.getValue());
}
}
assertEquals("Unexpected count", 1, count);
int threadCount = countThreads();
if (threadCount < 2) {
printThreadNames();
fail("Not seeing expected threads. Saw " + threadCount);
}
org.apache.accumulo.core.util.CleanUp.shutdownNow(conn);
Mutation m2 = new Mutation("r2");
m2.put("cf1", "cq1", 1, "6");
bw.addMutation(m1);
assertThrows(MutationsRejectedException.class, bw::flush);
// expect this to fail also, want to clean up batch writer threads
assertThrows(MutationsRejectedException.class, bw::close);
assertThrows(IllegalStateException.class, () -> Iterables.size(scanner));
threadCount = countThreads();
if (threadCount > 0) {
printThreadNames();
fail("Threads did not go away. Saw " + threadCount);
}
}
}
use of org.apache.accumulo.core.client.BatchWriterConfig in project accumulo by apache.
the class UnusedWALIT method writeSomeData.
private void writeSomeData(AccumuloClient client, String table, int startRow, int rowCount, int startCol, int colCount) throws Exception {
BatchWriterConfig config = new BatchWriterConfig();
config.setMaxMemory(10 * 1024 * 1024);
BatchWriter bw = client.createBatchWriter(table, config);
for (int r = startRow; r < startRow + rowCount; r++) {
Mutation m = new Mutation(Integer.toHexString(r));
for (int c = startCol; c < startCol + colCount; c++) {
m.put("", Integer.toHexString(c), "");
}
bw.addMutation(m);
}
bw.close();
}
use of org.apache.accumulo.core.client.BatchWriterConfig in project accumulo by apache.
the class BatchWriterFlushIT method runLatencyTest.
private void runLatencyTest(AccumuloClient client, String tableName) throws Exception {
// should automatically flush after 2 seconds
try (BatchWriter bw = client.createBatchWriter(tableName, new BatchWriterConfig().setMaxLatency(1000, TimeUnit.MILLISECONDS));
Scanner scanner = client.createScanner(tableName, Authorizations.EMPTY)) {
Mutation m = new Mutation(new Text(String.format("r_%10d", 1)));
m.put("cf", "cq", "1");
bw.addMutation(m);
sleepUninterruptibly(500, TimeUnit.MILLISECONDS);
int count = Iterators.size(scanner.iterator());
if (count != 0) {
throw new Exception("Flushed too soon");
}
sleepUninterruptibly(1500, TimeUnit.MILLISECONDS);
count = Iterators.size(scanner.iterator());
if (count != 1) {
throw new Exception("Did not flush");
}
}
}
use of org.apache.accumulo.core.client.BatchWriterConfig in project accumulo by apache.
the class MetricsIT method doWorkToGenerateMetrics.
private void doWorkToGenerateMetrics() throws Exception {
try (AccumuloClient client = Accumulo.newClient().from(getClientProperties()).build()) {
String tableName = this.getClass().getSimpleName();
client.tableOperations().create(tableName);
BatchWriterConfig config = new BatchWriterConfig().setMaxMemory(0);
try (BatchWriter writer = client.createBatchWriter(tableName, config)) {
Mutation m = new Mutation("row");
m.put("cf", "cq", new Value("value"));
writer.addMutation(m);
}
client.tableOperations().flush(tableName);
try (BatchWriter writer = client.createBatchWriter(tableName, config)) {
Mutation m = new Mutation("row");
m.put("cf", "cq", new Value("value"));
writer.addMutation(m);
}
client.tableOperations().compact(tableName, new CompactionConfig());
client.tableOperations().delete(tableName);
while (client.tableOperations().exists(tableName)) {
Thread.sleep(1000);
}
}
}
Aggregations