Search in sources :

Example 26 with TableNotFoundException

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

the class AccumuloUpdateExecution method createBatchWriter.

private BatchWriter createBatchWriter(Table table, Connector connector) throws TranslatorException, TableNotFoundException {
    String tableName = SQLStringVisitor.getRecordName(table);
    BatchWriter writer;
    try {
        writer = connector.createBatchWriter(tableName, new BatchWriterConfig());
    } catch (TableNotFoundException e) {
        try {
            connector.tableOperations().create(tableName, true, TimeType.LOGICAL);
        } catch (AccumuloException e1) {
            throw new TranslatorException(e1);
        } catch (AccumuloSecurityException e1) {
            throw new TranslatorException(e1);
        } catch (TableExistsException e1) {
            throw new TranslatorException(e1);
        }
        writer = connector.createBatchWriter(tableName, new BatchWriterConfig());
    }
    return writer;
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) TranslatorException(org.teiid.translator.TranslatorException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) BatchWriter(org.apache.accumulo.core.client.BatchWriter)

Example 27 with TableNotFoundException

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

the class AccumuloQueryExecution method execute.

@Override
public void execute() throws TranslatorException {
    try {
        Connector connector = this.connection.getInstance();
        List<Range> ranges = this.visitor.getRanges();
        Table scanTable = this.visitor.getScanTable();
        List<IteratorSetting> scanIterators = visitor.scanIterators();
        this.results = runQuery(this.aef, connector, this.connection.getAuthorizations(), ranges, scanTable, scanIterators);
    } catch (TableNotFoundException e) {
        // Teiid will not let the query come this far with out validating metadata for given table
        // so table in user's mind exists, it may be not be in the Accumulo, which should be treated as
        // now rows.
        this.results = null;
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Table(org.teiid.metadata.Table) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Range(org.apache.accumulo.core.data.Range)

Example 28 with TableNotFoundException

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

the class AccumuloReplicaSystem method replicateLogs.

protected Status replicateLogs(ClientContext peerContext, final HostAndPort peerTserver, final ReplicationTarget target, final Path p, final Status status, final long sizeLimit, final String remoteTableId, final TCredentials tcreds, final ReplicaSystemHelper helper, final UserGroupInformation accumuloUgi, long timeout) throws TTransportException, AccumuloException, AccumuloSecurityException {
    log.debug("Replication WAL to peer tserver");
    final Set<Integer> tids;
    try (final FSDataInputStream fsinput = fs.open(p);
        final DataInputStream input = getWalStream(p, fsinput)) {
        log.debug("Skipping unwanted data in WAL");
        Span span = Trace.start("Consume WAL prefix");
        span.data("file", p.toString());
        try {
            // We want to read all records in the WAL up to the "begin" offset contained in the Status message,
            // building a Set of tids from DEFINE_TABLET events which correspond to table ids for future mutations
            tids = consumeWalPrefix(target, input, p, status, sizeLimit);
        } catch (IOException e) {
            log.warn("Unexpected error consuming file.");
            return status;
        } finally {
            span.stop();
        }
        log.debug("Sending batches of data to peer tserver");
        Status lastStatus = status, currentStatus = status;
        final AtomicReference<Exception> exceptionRef = new AtomicReference<>();
        while (true) {
            // Set some trace info
            span = Trace.start("Replicate WAL batch");
            span.data("Batch size (bytes)", Long.toString(sizeLimit));
            span.data("File", p.toString());
            span.data("Peer instance name", peerContext.getInstance().getInstanceName());
            span.data("Peer tserver", peerTserver.toString());
            span.data("Remote table ID", remoteTableId);
            ReplicationStats replResult;
            try {
                // Read and send a batch of mutations
                replResult = ReplicationClient.executeServicerWithReturn(peerContext, peerTserver, new WalClientExecReturn(target, input, p, currentStatus, sizeLimit, remoteTableId, tcreds, tids), timeout);
            } catch (Exception e) {
                log.error("Caught exception replicating data to {} at {}", peerContext.getInstance().getInstanceName(), peerTserver, e);
                throw e;
            } finally {
                span.stop();
            }
            // Catch the overflow
            long newBegin = currentStatus.getBegin() + replResult.entriesConsumed;
            if (newBegin < 0) {
                newBegin = Long.MAX_VALUE;
            }
            currentStatus = Status.newBuilder(currentStatus).setBegin(newBegin).build();
            log.debug("Sent batch for replication of {} to {}, with new Status {}", p, target, ProtobufUtil.toString(currentStatus));
            // If we got a different status
            if (!currentStatus.equals(lastStatus)) {
                span = Trace.start("Update replication table");
                try {
                    if (null != accumuloUgi) {
                        final Status copy = currentStatus;
                        accumuloUgi.doAs(new PrivilegedAction<Void>() {

                            @Override
                            public Void run() {
                                try {
                                    helper.recordNewStatus(p, copy, target);
                                } catch (Exception e) {
                                    exceptionRef.set(e);
                                }
                                return null;
                            }
                        });
                        Exception e = exceptionRef.get();
                        if (null != e) {
                            if (e instanceof TableNotFoundException) {
                                throw (TableNotFoundException) e;
                            } else if (e instanceof AccumuloSecurityException) {
                                throw (AccumuloSecurityException) e;
                            } else if (e instanceof AccumuloException) {
                                throw (AccumuloException) e;
                            } else {
                                throw new RuntimeException("Received unexpected exception", e);
                            }
                        }
                    } else {
                        helper.recordNewStatus(p, currentStatus, target);
                    }
                } catch (TableNotFoundException e) {
                    log.error("Tried to update status in replication table for {} as {}, but the table did not exist", p, ProtobufUtil.toString(currentStatus), e);
                    throw new RuntimeException("Replication table did not exist, will retry", e);
                } finally {
                    span.stop();
                }
                log.debug("Recorded updated status for {}: {}", p, ProtobufUtil.toString(currentStatus));
                // If we don't have any more work, just quit
                if (!StatusUtil.isWorkRequired(currentStatus)) {
                    return currentStatus;
                } else {
                    // Otherwise, let it loop and replicate some more data
                    lastStatus = currentStatus;
                }
            } else {
                log.debug("Did not replicate any new data for {} to {}, (state was {})", p, target, ProtobufUtil.toString(lastStatus));
                // we can just not record any updates, and it will be picked up again by the work assigner
                return status;
            }
        }
    } catch (LogHeaderIncompleteException e) {
        log.warn("Could not read header from {}, assuming that there is no data present in the WAL, therefore replication is complete", p);
        Status newStatus;
        // Bump up the begin to the (infinite) end, trying to be accurate
        if (status.getInfiniteEnd()) {
            newStatus = Status.newBuilder(status).setBegin(Long.MAX_VALUE).build();
        } else {
            newStatus = Status.newBuilder(status).setBegin(status.getEnd()).build();
        }
        Span span = Trace.start("Update replication table");
        try {
            helper.recordNewStatus(p, newStatus, target);
        } catch (TableNotFoundException tnfe) {
            log.error("Tried to update status in replication table for {} as {}, but the table did not exist", p, ProtobufUtil.toString(newStatus), e);
            throw new RuntimeException("Replication table did not exist, will retry", e);
        } finally {
            span.stop();
        }
        return newStatus;
    } catch (IOException e) {
        log.error("Could not create stream for WAL", e);
        // No data sent (bytes nor records) and no progress made
        return status;
    }
}
Also used : Status(org.apache.accumulo.server.replication.proto.Replication.Status) AccumuloException(org.apache.accumulo.core.client.AccumuloException) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) DataInputStream(java.io.DataInputStream) Span(org.apache.accumulo.core.trace.Span) LogHeaderIncompleteException(org.apache.accumulo.tserver.log.DfsLogger.LogHeaderIncompleteException) TTransportException(org.apache.thrift.transport.TTransportException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) LogHeaderIncompleteException(org.apache.accumulo.tserver.log.DfsLogger.LogHeaderIncompleteException) EOFException(java.io.EOFException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException)

Example 29 with TableNotFoundException

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

the class ReplicationServicerHandler method replicateLog.

@Override
public long replicateLog(String tableIdStr, WalEdits data, TCredentials tcreds) throws RemoteReplicationException, TException {
    Table.ID tableId = Table.ID.of(tableIdStr);
    log.debug("Got replication request to tableID {} with {} edits", tableId, data.getEditsSize());
    tabletServer.getSecurityOperation().authenticateUser(tabletServer.rpcCreds(), tcreds);
    String tableName;
    try {
        tableName = Tables.getTableName(tabletServer.getInstance(), tableId);
    } catch (TableNotFoundException e) {
        log.error("Could not find table with id {}", tableId);
        throw new RemoteReplicationException(RemoteReplicationErrorCode.TABLE_DOES_NOT_EXIST, "Table with id " + tableId + " does not exist");
    }
    AccumuloConfiguration conf = tabletServer.getConfiguration();
    Map<String, String> replicationHandlers = conf.getAllPropertiesWithPrefix(Property.TSERV_REPLICATION_REPLAYERS);
    String propertyForHandlerTable = Property.TSERV_REPLICATION_REPLAYERS.getKey() + tableId;
    String handlerClassForTable = replicationHandlers.get(propertyForHandlerTable);
    if (null == handlerClassForTable) {
        if (!replicationHandlers.isEmpty()) {
            log.debug("Could not find replication replayer for {}", tableId);
        }
        handlerClassForTable = conf.get(Property.TSERV_REPLICATION_DEFAULT_HANDLER);
    }
    log.debug("Using {} replication replayer for table {}", handlerClassForTable, tableId);
    // Get class for replayer
    Class<? extends AccumuloReplicationReplayer> clz;
    try {
        Class<?> untypedClz = Class.forName(handlerClassForTable);
        clz = untypedClz.asSubclass(AccumuloReplicationReplayer.class);
    } catch (ClassNotFoundException e) {
        log.error("Could not instantiate replayer class {}", handlerClassForTable, e);
        throw new RemoteReplicationException(RemoteReplicationErrorCode.CANNOT_INSTANTIATE_REPLAYER, "Could not instantiate replayer class " + handlerClassForTable);
    }
    // Create an instance
    AccumuloReplicationReplayer replayer;
    try {
        replayer = clz.newInstance();
    } catch (InstantiationException | IllegalAccessException e1) {
        log.error("Could not instantiate replayer class {}", clz.getName());
        throw new RemoteReplicationException(RemoteReplicationErrorCode.CANNOT_INSTANTIATE_REPLAYER, "Could not instantiate replayer class" + clz.getName());
    }
    long entriesReplicated;
    try {
        entriesReplicated = replayer.replicateLog(tabletServer, tableName, data);
    } catch (AccumuloException | AccumuloSecurityException e) {
        log.error("Could not get connection", e);
        throw new RemoteReplicationException(RemoteReplicationErrorCode.CANNOT_AUTHENTICATE, "Cannot get connector as " + tabletServer.getCredentials().getPrincipal());
    }
    log.debug("Replicated {} mutations to {}", entriesReplicated, tableName);
    return entriesReplicated;
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) Table(org.apache.accumulo.core.client.impl.Table) RemoteReplicationException(org.apache.accumulo.core.replication.thrift.RemoteReplicationException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) AccumuloReplicationReplayer(org.apache.accumulo.core.replication.AccumuloReplicationReplayer) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration)

Example 30 with TableNotFoundException

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

the class ReplicationUtil method getPendingReplications.

public Map<ReplicationTarget, Long> getPendingReplications() {
    final Map<ReplicationTarget, Long> counts = new HashMap<>();
    // Read over the queued work
    BatchScanner bs;
    try {
        bs = context.getConnector().createBatchScanner(ReplicationTable.NAME, Authorizations.EMPTY, 4);
    } catch (TableNotFoundException | AccumuloException | AccumuloSecurityException e) {
        log.debug("No replication table exists", e);
        return counts;
    }
    bs.setRanges(Collections.singleton(new Range()));
    WorkSection.limit(bs);
    try {
        Text buffer = new Text();
        for (Entry<Key, Value> entry : bs) {
            Key k = entry.getKey();
            k.getColumnQualifier(buffer);
            ReplicationTarget target = ReplicationTarget.from(buffer);
            // TODO ACCUMULO-2835 once explicit lengths are tracked, we can give size-based estimates instead of just file-based
            Long count = counts.get(target);
            if (null == count) {
                counts.put(target, 1l);
            } else {
                counts.put(target, count + 1);
            }
        }
    } finally {
        bs.close();
    }
    return counts;
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) HashMap(java.util.HashMap) BatchScanner(org.apache.accumulo.core.client.BatchScanner) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ReplicationTarget(org.apache.accumulo.core.replication.ReplicationTarget) Value(org.apache.accumulo.core.data.Value) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Key(org.apache.accumulo.core.data.Key)

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