Search in sources :

Example 1 with TableNotFoundException

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();
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) Text(org.apache.hadoop.io.Text) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) TableExistsException(org.apache.accumulo.core.client.TableExistsException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) AccumuloException(org.apache.accumulo.core.client.AccumuloException)

Example 2 with TableNotFoundException

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();
}
Also used : Connector(org.apache.accumulo.core.client.Connector) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) CountDownLatch(java.util.concurrent.CountDownLatch) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Test(org.junit.Test)

Example 3 with TableNotFoundException

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");
        }
    }
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Entry(java.util.Map.Entry) Random(java.util.Random) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key)

Example 4 with TableNotFoundException

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;
}
Also used : Status(org.apache.accumulo.server.replication.proto.Replication.Status) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException)

Example 5 with TableNotFoundException

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);
            }
        }
    };
}
Also used : TInfo(org.apache.accumulo.core.trace.thrift.TInfo) TException(org.apache.thrift.TException) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) Table(org.apache.accumulo.core.client.impl.Table) ReplicationTable(org.apache.accumulo.core.replication.ReplicationTable) Set(java.util.Set) Instance(org.apache.accumulo.core.client.Instance) TCredentials(org.apache.accumulo.core.security.thrift.TCredentials) ClientContext(org.apache.accumulo.core.client.impl.ClientContext) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TException(org.apache.thrift.TException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) Master(org.apache.accumulo.master.Master) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) MasterClientServiceHandler(org.apache.accumulo.master.MasterClientServiceHandler) TCredentials(org.apache.accumulo.core.security.thrift.TCredentials) Credentials(org.apache.accumulo.core.client.impl.Credentials) ReplicationOperationsImpl(org.apache.accumulo.core.client.impl.ReplicationOperationsImpl)

Aggregations

TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)160 AccumuloException (org.apache.accumulo.core.client.AccumuloException)100 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)89 Text (org.apache.hadoop.io.Text)51 Value (org.apache.accumulo.core.data.Value)46 Key (org.apache.accumulo.core.data.Key)42 Scanner (org.apache.accumulo.core.client.Scanner)36 IOException (java.io.IOException)34 BatchWriter (org.apache.accumulo.core.client.BatchWriter)31 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)31 Connector (org.apache.accumulo.core.client.Connector)30 Mutation (org.apache.accumulo.core.data.Mutation)29 Range (org.apache.accumulo.core.data.Range)28 Authorizations (org.apache.accumulo.core.security.Authorizations)26 ArrayList (java.util.ArrayList)25 Entry (java.util.Map.Entry)25 TableExistsException (org.apache.accumulo.core.client.TableExistsException)25 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)23 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)23 HashMap (java.util.HashMap)19