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;
}
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;
}
}
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;
}
}
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;
}
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;
}
Aggregations