Search in sources :

Example 6 with TableNotFoundException

use of org.apache.accumulo.core.client.TableNotFoundException in project accumulo by apache.

the class ShellPluginConfigurationCommand method getPluginClass.

public static <T> Class<? extends T> getPluginClass(final String tableName, final Shell shellState, final Class<T> clazz, final Property pluginProp) {
    Iterator<Entry<String, String>> props;
    try {
        props = shellState.getConnector().tableOperations().getProperties(tableName).iterator();
    } catch (AccumuloException | TableNotFoundException e) {
        return null;
    }
    while (props.hasNext()) {
        final Entry<String, String> ent = props.next();
        if (ent.getKey().equals(pluginProp.toString())) {
            Class<? extends T> pluginClazz;
            String[] args = new String[2];
            try {
                Options o = new Options();
                o.addOption(OptUtil.tableOpt());
                args[0] = "-t";
                args[1] = tableName;
                CommandLine cl = new BasicParser().parse(o, args);
                pluginClazz = shellState.getClassLoader(cl, shellState).loadClass(ent.getValue()).asSubclass(clazz);
            } catch (ClassNotFoundException e) {
                LoggerFactory.getLogger(ShellPluginConfigurationCommand.class).error("Class not found {}", e.getMessage());
                return null;
            } catch (ParseException e) {
                LoggerFactory.getLogger(ShellPluginConfigurationCommand.class).error("Error parsing table: {} {}", Arrays.toString(args), e.getMessage());
                return null;
            } catch (TableNotFoundException e) {
                LoggerFactory.getLogger(ShellPluginConfigurationCommand.class).error("Table not found: {} {}", tableName, e.getMessage());
                return null;
            } catch (Exception e) {
                LoggerFactory.getLogger(ShellPluginConfigurationCommand.class).error("Error: {}", e.getMessage());
                return null;
            }
            return pluginClazz;
        }
    }
    return null;
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) Options(org.apache.commons.cli.Options) AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ParseException(org.apache.commons.cli.ParseException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) BasicParser(org.apache.commons.cli.BasicParser) Entry(java.util.Map.Entry) CommandLine(org.apache.commons.cli.CommandLine) ParseException(org.apache.commons.cli.ParseException)

Example 7 with TableNotFoundException

use of org.apache.accumulo.core.client.TableNotFoundException in project accumulo by apache.

the class MasterClientServiceHandler method waitForFlush.

@Override
public void waitForFlush(TInfo tinfo, TCredentials c, String tableIdStr, ByteBuffer startRow, ByteBuffer endRow, long flushID, long maxLoops) throws ThriftSecurityException, ThriftTableOperationException {
    Table.ID tableId = Table.ID.of(tableIdStr);
    Namespace.ID namespaceId = getNamespaceIdFromTableId(TableOperation.FLUSH, tableId);
    master.security.canFlush(c, tableId, namespaceId);
    if (endRow != null && startRow != null && ByteBufferUtil.toText(startRow).compareTo(ByteBufferUtil.toText(endRow)) >= 0)
        throw new ThriftTableOperationException(tableId.canonicalID(), null, TableOperation.FLUSH, TableOperationExceptionType.BAD_RANGE, "start row must be less than end row");
    Set<TServerInstance> serversToFlush = new HashSet<>(master.tserverSet.getCurrentServers());
    for (long l = 0; l < maxLoops; l++) {
        for (TServerInstance instance : serversToFlush) {
            try {
                final TServerConnection server = master.tserverSet.getConnection(instance);
                if (server != null)
                    server.flush(master.masterLock, tableId, ByteBufferUtil.toBytes(startRow), ByteBufferUtil.toBytes(endRow));
            } catch (TException ex) {
                Master.log.error(ex.toString());
            }
        }
        if (l == maxLoops - 1)
            break;
        sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
        serversToFlush.clear();
        try {
            Connector conn = master.getConnector();
            Scanner scanner;
            if (tableId.equals(MetadataTable.ID)) {
                scanner = new IsolatedScanner(conn.createScanner(RootTable.NAME, Authorizations.EMPTY));
                scanner.setRange(MetadataSchema.TabletsSection.getRange());
            } else {
                scanner = new IsolatedScanner(conn.createScanner(MetadataTable.NAME, Authorizations.EMPTY));
                Range range = new KeyExtent(tableId, null, ByteBufferUtil.toText(startRow)).toMetadataRange();
                scanner.setRange(range.clip(MetadataSchema.TabletsSection.getRange()));
            }
            TabletsSection.ServerColumnFamily.FLUSH_COLUMN.fetch(scanner);
            TabletsSection.ServerColumnFamily.DIRECTORY_COLUMN.fetch(scanner);
            scanner.fetchColumnFamily(TabletsSection.CurrentLocationColumnFamily.NAME);
            scanner.fetchColumnFamily(LogColumnFamily.NAME);
            RowIterator ri = new RowIterator(scanner);
            int tabletsToWaitFor = 0;
            int tabletCount = 0;
            Text ert = ByteBufferUtil.toText(endRow);
            while (ri.hasNext()) {
                Iterator<Entry<Key, Value>> row = ri.next();
                long tabletFlushID = -1;
                int logs = 0;
                boolean online = false;
                TServerInstance server = null;
                Entry<Key, Value> entry = null;
                while (row.hasNext()) {
                    entry = row.next();
                    Key key = entry.getKey();
                    if (TabletsSection.ServerColumnFamily.FLUSH_COLUMN.equals(key.getColumnFamily(), key.getColumnQualifier())) {
                        tabletFlushID = Long.parseLong(entry.getValue().toString());
                    }
                    if (LogColumnFamily.NAME.equals(key.getColumnFamily()))
                        logs++;
                    if (TabletsSection.CurrentLocationColumnFamily.NAME.equals(key.getColumnFamily())) {
                        online = true;
                        server = new TServerInstance(entry.getValue(), key.getColumnQualifier());
                    }
                }
                // when tablet is not online and has no logs, there is no reason to wait for it
                if ((online || logs > 0) && tabletFlushID < flushID) {
                    tabletsToWaitFor++;
                    if (server != null)
                        serversToFlush.add(server);
                }
                tabletCount++;
                Text tabletEndRow = new KeyExtent(entry.getKey().getRow(), (Text) null).getEndRow();
                if (tabletEndRow == null || (ert != null && tabletEndRow.compareTo(ert) >= 0))
                    break;
            }
            if (tabletsToWaitFor == 0)
                break;
            if (tabletCount == 0 && !Tables.exists(master.getInstance(), tableId))
                throw new ThriftTableOperationException(tableId.canonicalID(), null, TableOperation.FLUSH, TableOperationExceptionType.NOTFOUND, null);
        } catch (AccumuloException | TabletDeletedException e) {
            Master.log.debug("Failed to scan {} table to wait for flush {}", MetadataTable.NAME, tableId, e);
        } catch (AccumuloSecurityException e) {
            Master.log.warn("{}", e.getMessage(), e);
            throw new ThriftSecurityException();
        } catch (TableNotFoundException e) {
            Master.log.error("{}", e.getMessage(), e);
            throw new ThriftTableOperationException();
        }
    }
}
Also used : TException(org.apache.thrift.TException) Connector(org.apache.accumulo.core.client.Connector) BatchScanner(org.apache.accumulo.core.client.BatchScanner) IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Scanner(org.apache.accumulo.core.client.Scanner) TKeyExtent(org.apache.accumulo.core.data.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Entry(java.util.Map.Entry) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) HashSet(java.util.HashSet) AccumuloException(org.apache.accumulo.core.client.AccumuloException) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) RootTable(org.apache.accumulo.core.metadata.RootTable) Table(org.apache.accumulo.core.client.impl.Table) ReplicationTable(org.apache.accumulo.core.replication.ReplicationTable) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) TabletDeletedException(org.apache.accumulo.server.util.TabletIterator.TabletDeletedException) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) Namespace(org.apache.accumulo.core.client.impl.Namespace) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) TServerConnection(org.apache.accumulo.server.master.LiveTServerSet.TServerConnection) RowIterator(org.apache.accumulo.core.client.RowIterator) Value(org.apache.accumulo.core.data.Value) IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Key(org.apache.accumulo.core.data.Key)

Example 8 with TableNotFoundException

use of org.apache.accumulo.core.client.TableNotFoundException in project accumulo by apache.

the class GarbageCollectWriteAheadLogs method removeReplicationEntries.

protected int removeReplicationEntries(Map<UUID, TServerInstance> candidates) throws IOException, KeeperException, InterruptedException {
    Connector conn;
    try {
        conn = context.getConnector();
        try {
            final Scanner s = ReplicationTable.getScanner(conn);
            StatusSection.limit(s);
            for (Entry<Key, Value> entry : s) {
                UUID id = path2uuid(new Path(entry.getKey().getRow().toString()));
                candidates.remove(id);
                log.info("Ignore closed log " + id + " because it is being replicated");
            }
        } catch (ReplicationTableOfflineException ex) {
            return candidates.size();
        }
        final Scanner scanner = conn.createScanner(MetadataTable.NAME, Authorizations.EMPTY);
        scanner.fetchColumnFamily(MetadataSchema.ReplicationSection.COLF);
        scanner.setRange(MetadataSchema.ReplicationSection.getRange());
        for (Entry<Key, Value> entry : scanner) {
            Text file = new Text();
            MetadataSchema.ReplicationSection.getFile(entry.getKey(), file);
            UUID id = path2uuid(new Path(file.toString()));
            candidates.remove(id);
            log.info("Ignore closed log " + id + " because it is being replicated");
        }
        return candidates.size();
    } catch (AccumuloException | AccumuloSecurityException | TableNotFoundException e) {
        log.error("Failed to scan metadata table", e);
        throw new IllegalArgumentException(e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Text(org.apache.hadoop.io.Text) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Value(org.apache.accumulo.core.data.Value) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ReplicationTableOfflineException(org.apache.accumulo.core.replication.ReplicationTableOfflineException) UUID(java.util.UUID) Key(org.apache.accumulo.core.data.Key)

Example 9 with TableNotFoundException

use of org.apache.accumulo.core.client.TableNotFoundException in project accumulo by apache.

the class CloseWriteAheadLogReferences method updateReplicationEntries.

/**
 * Given the set of WALs which have references in the metadata table, close any status messages with reference that WAL.
 *
 * @param conn
 *          Connector
 * @param closedWals
 *          {@link Set} of paths to WALs that marked as closed or unreferenced in zookeeper
 */
protected long updateReplicationEntries(Connector conn, Set<String> closedWals) {
    BatchScanner bs = null;
    BatchWriter bw = null;
    long recordsClosed = 0;
    try {
        bw = conn.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig());
        bs = conn.createBatchScanner(MetadataTable.NAME, Authorizations.EMPTY, 4);
        bs.setRanges(Collections.singleton(Range.prefix(ReplicationSection.getRowPrefix())));
        bs.fetchColumnFamily(ReplicationSection.COLF);
        Text replFileText = new Text();
        for (Entry<Key, Value> entry : bs) {
            Status status;
            try {
                status = Status.parseFrom(entry.getValue().get());
            } catch (InvalidProtocolBufferException e) {
                log.error("Could not parse Status protobuf for {}", entry.getKey(), e);
                continue;
            }
            // Ignore things that aren't completely replicated as we can't delete those anyways
            MetadataSchema.ReplicationSection.getFile(entry.getKey(), replFileText);
            String replFile = replFileText.toString();
            boolean isClosed = closedWals.contains(replFile);
            // metadata doesn't have a reference to the given WAL
            if (!status.getClosed() && !replFile.endsWith(RFILE_SUFFIX) && isClosed) {
                try {
                    closeWal(bw, entry.getKey());
                    recordsClosed++;
                } catch (MutationsRejectedException e) {
                    log.error("Failed to submit delete mutation for {}", entry.getKey());
                    continue;
                }
            }
        }
    } catch (TableNotFoundException e) {
        log.error("Replication table was deleted", e);
    } finally {
        if (null != bs) {
            bs.close();
        }
        if (null != bw) {
            try {
                bw.close();
            } catch (MutationsRejectedException e) {
                log.error("Failed to write delete mutations for replication table", e);
            }
        }
    }
    return recordsClosed;
}
Also used : Status(org.apache.accumulo.server.replication.proto.Replication.Status) BatchScanner(org.apache.accumulo.core.client.BatchScanner) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Text(org.apache.hadoop.io.Text) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Key(org.apache.accumulo.core.data.Key) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 10 with TableNotFoundException

use of org.apache.accumulo.core.client.TableNotFoundException 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) {
    }
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) TableExistsException(org.apache.accumulo.core.client.TableExistsException) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) Test(org.junit.Test)

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