use of org.apache.accumulo.core.client.TableExistsException 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.TableExistsException in project accumulo by apache.
the class MockTableOperationsTest method testTableNotFound.
@Test
public void testTableNotFound() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException {
IteratorSetting setting = new IteratorSetting(100, "myvers", VersioningIterator.class);
String t = "tableName";
try {
conn.tableOperations().attachIterator(t, setting);
Assert.fail();
} catch (TableNotFoundException e) {
}
try {
conn.tableOperations().checkIteratorConflicts(t, setting, EnumSet.allOf(IteratorScope.class));
Assert.fail();
} catch (TableNotFoundException e) {
}
try {
conn.tableOperations().delete(t);
Assert.fail();
} catch (TableNotFoundException e) {
}
try {
conn.tableOperations().getIteratorSetting(t, "myvers", IteratorScope.scan);
Assert.fail();
} catch (TableNotFoundException e) {
}
try {
conn.tableOperations().getProperties(t);
Assert.fail();
} catch (TableNotFoundException e) {
}
try {
conn.tableOperations().listSplits(t);
Assert.fail();
} catch (TableNotFoundException e) {
}
try {
conn.tableOperations().listIterators(t);
Assert.fail();
} catch (TableNotFoundException e) {
}
try {
conn.tableOperations().removeIterator(t, null, EnumSet.noneOf(IteratorScope.class));
Assert.fail();
} catch (TableNotFoundException e) {
}
try {
conn.tableOperations().rename(t, t);
Assert.fail();
} catch (TableNotFoundException e) {
}
conn.tableOperations().create(t);
try {
conn.tableOperations().create(t);
Assert.fail();
} catch (TableExistsException e) {
}
try {
conn.tableOperations().rename(t, t);
Assert.fail();
} catch (TableExistsException e) {
}
}
use of org.apache.accumulo.core.client.TableExistsException in project accumulo by apache.
the class TableChangeStateIT method createData.
/**
* Create the provided table and populate with some data using a batch writer. The table is scanned to ensure it was populated as expected.
*
* @param tableName
* the name of the table
*/
private void createData(final String tableName) {
try {
// create table.
connector.tableOperations().create(tableName);
BatchWriter bw = connector.createBatchWriter(tableName, new BatchWriterConfig());
// populate
for (int i = 0; i < NUM_ROWS; i++) {
Mutation m = new Mutation(new Text(String.format("%05d", i)));
m.put(new Text("col" + Integer.toString((i % 3) + 1)), new Text("qual"), new Value("junk".getBytes(UTF_8)));
bw.addMutation(m);
}
bw.close();
long startTimestamp = System.nanoTime();
try (Scanner scanner = connector.createScanner(tableName, Authorizations.EMPTY)) {
int count = 0;
for (Map.Entry<Key, Value> elt : scanner) {
String expected = String.format("%05d", count);
assert (elt.getKey().getRow().toString().equals(expected));
count++;
}
log.trace("Scan time for {} rows {} ms", NUM_ROWS, TimeUnit.MILLISECONDS.convert((System.nanoTime() - startTimestamp), TimeUnit.NANOSECONDS));
if (count != NUM_ROWS) {
throw new IllegalStateException(String.format("Number of rows %1$d does not match expected %2$d", count, NUM_ROWS));
}
}
} catch (AccumuloException | AccumuloSecurityException | TableNotFoundException | TableExistsException ex) {
throw new IllegalStateException("Create data failed with exception", ex);
}
}
use of org.apache.accumulo.core.client.TableExistsException in project incubator-rya by apache.
the class CopyTool method createTableIfNeeded.
/**
* Creates the child table if it doesn't already exist.
* @param childTableName the name of the child table.
* @throws IOException
*/
public void createTableIfNeeded(final String childTableName) throws IOException {
try {
final Configuration childConfig = MergeToolMapper.getChildConfig(conf);
final AccumuloRdfConfiguration childAccumuloRdfConfiguration = new AccumuloRdfConfiguration(childConfig);
childAccumuloRdfConfiguration.setTablePrefix(childTablePrefix);
final Connector childConnector = AccumuloRyaUtils.setupConnector(childAccumuloRdfConfiguration);
if (!childConnector.tableOperations().exists(childTableName)) {
log.info("Creating table: " + childTableName);
childConnector.tableOperations().create(childTableName);
log.info("Created table: " + childTableName);
log.info("Granting authorizations to table: " + childTableName);
childConnector.securityOperations().grantTablePermission(childUserName, childTableName, TablePermission.WRITE);
log.info("Granted authorizations to table: " + childTableName);
}
} catch (TableExistsException | AccumuloException | AccumuloSecurityException e) {
throw new IOException(e);
}
}
use of org.apache.accumulo.core.client.TableExistsException in project incubator-rya by apache.
the class MergeTool method createTempTableIfNeeded.
/**
* Creates the temp child table if it doesn't already exist in the parent.
* @param childTableName the name of the child table.
* @throws IOException
*/
public void createTempTableIfNeeded(final String childTableName) throws IOException {
try {
final AccumuloRdfConfiguration accumuloRdfConfiguration = new AccumuloRdfConfiguration(conf);
accumuloRdfConfiguration.setTablePrefix(childTablePrefix);
final Connector connector = AccumuloRyaUtils.setupConnector(accumuloRdfConfiguration);
if (!connector.tableOperations().exists(childTableName)) {
log.info("Creating table: " + childTableName);
connector.tableOperations().create(childTableName);
log.info("Created table: " + childTableName);
log.info("Granting authorizations to table: " + childTableName);
final SecurityOperations secOps = connector.securityOperations();
secOps.grantTablePermission(userName, childTableName, TablePermission.WRITE);
log.info("Granted authorizations to table: " + childTableName);
final Authorizations parentAuths = secOps.getUserAuthorizations(userName);
// Add child authorizations so the temp parent table can be accessed.
if (!parentAuths.equals(childAuthorizations)) {
final List<String> childAuthList = findUniqueAuthsFromChild(parentAuths.toString(), childAuthorizations.toString());
tempChildAuths = Joiner.on(",").join(childAuthList);
log.info("Adding the authorization, \"" + tempChildAuths + "\", to the parent user, \"" + userName + "\"");
final Authorizations newAuths = AccumuloRyaUtils.addUserAuths(userName, secOps, new Authorizations(tempChildAuths));
secOps.changeUserAuthorizations(userName, newAuths);
}
}
} catch (TableExistsException | AccumuloException | AccumuloSecurityException e) {
throw new IOException(e);
}
}
Aggregations