use of org.apache.accumulo.core.client.TableNotFoundException in project accumulo by apache.
the class ConcurrencyIT method runTest.
static void runTest(Connector c, String tableName) throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, MutationsRejectedException, Exception, InterruptedException {
c.tableOperations().create(tableName);
IteratorSetting is = new IteratorSetting(10, SlowIterator.class);
SlowIterator.setSleepTime(is, 50);
c.tableOperations().attachIterator(tableName, is, EnumSet.of(IteratorScope.minc, IteratorScope.majc));
c.tableOperations().setProperty(tableName, Property.TABLE_MAJC_RATIO.getKey(), "1.0");
BatchWriter bw = c.createBatchWriter(tableName, new BatchWriterConfig());
for (int i = 0; i < 50; i++) {
Mutation m = new Mutation(new Text(String.format("%06d", i)));
m.put(new Text("cf1"), new Text("cq1"), new Value("foo".getBytes(UTF_8)));
bw.addMutation(m);
}
bw.flush();
ScanTask st0 = new ScanTask(c, tableName, 300);
st0.start();
ScanTask st1 = new ScanTask(c, tableName, 100);
st1.start();
sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
c.tableOperations().flush(tableName, null, null, true);
for (int i = 0; i < 50; i++) {
Mutation m = new Mutation(new Text(String.format("%06d", i)));
m.put(new Text("cf1"), new Text("cq1"), new Value("foo".getBytes(UTF_8)));
bw.addMutation(m);
}
bw.flush();
ScanTask st2 = new ScanTask(c, tableName, 100);
st2.start();
st1.join();
st2.join();
if (st1.count != 50)
throw new Exception("Thread 1 did not see 50, saw " + st1.count);
if (st2.count != 50)
throw new Exception("Thread 2 did not see 50, saw " + st2.count);
ScanTask st3 = new ScanTask(c, tableName, 150);
st3.start();
sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
c.tableOperations().flush(tableName, null, null, false);
st3.join();
if (st3.count != 50)
throw new Exception("Thread 3 did not see 50, saw " + st3.count);
st0.join();
if (st0.count != 50)
throw new Exception("Thread 0 did not see 50, saw " + st0.count);
bw.close();
}
use of org.apache.accumulo.core.client.TableNotFoundException in project accumulo by apache.
the class ConcurrentDeleteTableIT method testConcurrentDeleteTablesOps.
@Test
public void testConcurrentDeleteTablesOps() throws Exception {
final Connector c = getConnector();
String[] tables = getUniqueNames(2);
TreeSet<Text> splits = createSplits();
ExecutorService es = Executors.newFixedThreadPool(20);
int count = 0;
for (final String table : tables) {
c.tableOperations().create(table);
c.tableOperations().addSplits(table, splits);
writeData(c, table);
if (count == 1) {
c.tableOperations().flush(table, null, null, true);
}
count++;
int numDeleteOps = 20;
final CountDownLatch cdl = new CountDownLatch(numDeleteOps);
List<Future<?>> futures = new ArrayList<>();
for (int i = 0; i < numDeleteOps; i++) {
Future<?> future = es.submit(new Runnable() {
@Override
public void run() {
try {
cdl.countDown();
cdl.await();
c.tableOperations().delete(table);
} catch (TableNotFoundException e) {
// expected
} catch (InterruptedException | AccumuloException | AccumuloSecurityException e) {
throw new RuntimeException(e);
}
}
});
futures.add(future);
}
for (Future<?> future : futures) {
future.get();
}
try {
c.createScanner(table, Authorizations.EMPTY);
Assert.fail("Expected table " + table + " to be gone.");
} catch (TableNotFoundException tnfe) {
// expected
}
FunctionalTestUtils.assertNoDanglingFateLocks(getConnector().getInstance(), getCluster());
}
es.shutdown();
}
use of org.apache.accumulo.core.client.TableNotFoundException in project accumulo by apache.
the class BatchWriterFlushIT method runFlushTest.
private void runFlushTest(String tableName) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, MutationsRejectedException, Exception {
BatchWriter bw = getConnector().createBatchWriter(tableName, new BatchWriterConfig());
try (Scanner scanner = getConnector().createScanner(tableName, Authorizations.EMPTY)) {
Random r = new Random();
for (int i = 0; i < 4; i++) {
for (int j = 0; j < NUM_TO_FLUSH; j++) {
int row = i * NUM_TO_FLUSH + j;
Mutation m = new Mutation(new Text(String.format("r_%10d", row)));
m.put(new Text("cf"), new Text("cq"), new Value(("" + row).getBytes()));
bw.addMutation(m);
}
bw.flush();
for (int k = 0; k < 10; k++) {
int rowToLookup = r.nextInt(NUM_TO_FLUSH) + i * NUM_TO_FLUSH;
scanner.setRange(new Range(new Text(String.format("r_%10d", rowToLookup))));
Iterator<Entry<Key, Value>> iter = scanner.iterator();
if (!iter.hasNext())
throw new Exception(" row " + rowToLookup + " not found after flush");
Entry<Key, Value> entry = iter.next();
if (iter.hasNext())
throw new Exception("Scanner returned too much");
verifyEntry(rowToLookup, entry);
}
// scan all data just flushed
scanner.setRange(new Range(new Text(String.format("r_%10d", i * NUM_TO_FLUSH)), true, new Text(String.format("r_%10d", (i + 1) * NUM_TO_FLUSH)), false));
Iterator<Entry<Key, Value>> iter = scanner.iterator();
for (int j = 0; j < NUM_TO_FLUSH; j++) {
int row = i * NUM_TO_FLUSH + j;
if (!iter.hasNext())
throw new Exception("Scan stopped permaturely at " + row);
Entry<Key, Value> entry = iter.next();
verifyEntry(row, entry);
}
if (iter.hasNext())
throw new Exception("Scanner returned too much");
}
bw.close();
// test adding a mutation to a closed batch writer
boolean caught = false;
try {
bw.addMutation(new Mutation(new Text("foobar")));
} catch (IllegalStateException ise) {
caught = true;
}
if (!caught) {
throw new Exception("Adding to closed batch writer did not fail");
}
}
}
use of org.apache.accumulo.core.client.TableNotFoundException in project accumulo by apache.
the class MockReplicaSystem method replicate.
@Override
public Status replicate(Path p, Status status, ReplicationTarget target, ReplicaSystemHelper helper) {
Status newStatus;
if (status.getClosed() && status.getInfiniteEnd()) {
Status.Builder builder = Status.newBuilder(status);
if (status.getInfiniteEnd()) {
builder.setBegin(Long.MAX_VALUE);
} else {
builder.setBegin(status.getEnd());
}
newStatus = builder.build();
} else {
log.info("{} with status {} is not closed and with infinite length, ignoring", p, status);
newStatus = status;
}
log.debug("Sleeping for {}ms before finishing replication on {}", sleep, p);
try {
Thread.sleep(sleep);
} catch (InterruptedException e) {
log.error("Interrupted while sleeping, will report no progress", e);
Thread.currentThread().interrupt();
return status;
}
log.info("For {}, received {}, returned {}", p, ProtobufUtil.toString(status), ProtobufUtil.toString(newStatus));
try {
helper.recordNewStatus(p, newStatus, target);
} catch (TableNotFoundException e) {
log.error("Tried to update status in replication table for {} as {}, but the table did not exist", p, ProtobufUtil.toString(newStatus), e);
return status;
} catch (AccumuloException | AccumuloSecurityException e) {
log.error("Tried to record new status in replication table for {} as {}, but got an error", p, ProtobufUtil.toString(newStatus), e);
return status;
}
return newStatus;
}
use of org.apache.accumulo.core.client.TableNotFoundException in project accumulo by apache.
the class ReplicationOperationsImplIT method getReplicationOperations.
/**
* Spoof out the Master so we can call the implementation without starting a full instance.
*/
private ReplicationOperationsImpl getReplicationOperations() throws Exception {
Master master = EasyMock.createMock(Master.class);
EasyMock.expect(master.getConnector()).andReturn(conn).anyTimes();
EasyMock.expect(master.getInstance()).andReturn(inst).anyTimes();
EasyMock.replay(master);
final MasterClientServiceHandler mcsh = new MasterClientServiceHandler(master) {
@Override
protected Table.ID getTableId(Instance inst, String tableName) throws ThriftTableOperationException {
try {
return Table.ID.of(conn.tableOperations().tableIdMap().get(tableName));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
ClientContext context = new ClientContext(inst, new Credentials("root", new PasswordToken(ROOT_PASSWORD)), getClientConfig());
return new ReplicationOperationsImpl(context) {
@Override
protected boolean getMasterDrain(final TInfo tinfo, final TCredentials rpcCreds, final String tableName, final Set<String> wals) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
try {
return mcsh.drainReplicationTable(tinfo, rpcCreds, tableName, wals);
} catch (TException e) {
throw new RuntimeException(e);
}
}
};
}
Aggregations