use of org.apache.accumulo.core.replication.thrift.RemoteReplicationException 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.replication.thrift.RemoteReplicationException in project accumulo by apache.
the class BatchWriterReplicationReplayer method replicateLog.
@Override
public long replicateLog(ClientContext context, String tableName, WalEdits data) throws RemoteReplicationException, AccumuloException, AccumuloSecurityException {
final LogFileKey key = new LogFileKey();
final LogFileValue value = new LogFileValue();
final long memoryInBytes = context.getConfiguration().getAsBytes(Property.TSERV_REPLICATION_BW_REPLAYER_MEMORY);
BatchWriter bw = null;
long mutationsApplied = 0l;
try {
for (ByteBuffer edit : data.getEdits()) {
DataInputStream dis = new DataInputStream(ByteBufferUtil.toByteArrayInputStream(edit));
try {
key.readFields(dis);
// TODO this is brittle because AccumuloReplicaSystem isn't actually calling LogFileValue.write, but we're expecting
// what we receive to be readable by the LogFileValue.
value.readFields(dis);
} catch (IOException e) {
log.error("Could not deserialize edit from stream", e);
throw new RemoteReplicationException(RemoteReplicationErrorCode.COULD_NOT_DESERIALIZE, "Could not deserialize edit from stream");
}
// Create the batchScanner if we don't already have one.
if (null == bw) {
BatchWriterConfig bwConfig = new BatchWriterConfig();
bwConfig.setMaxMemory(memoryInBytes);
try {
bw = context.getConnector().createBatchWriter(tableName, bwConfig);
} catch (TableNotFoundException e) {
throw new RemoteReplicationException(RemoteReplicationErrorCode.TABLE_DOES_NOT_EXIST, "Table " + tableName + " does not exist");
}
}
log.info("Applying {} mutations to table {} as part of batch", value.mutations.size(), tableName);
// If we got a ServerMutation, we have to make sure that we preserve the systemTimestamp otherwise
// the local system will assign a new timestamp.
List<Mutation> mutationsCopy = new ArrayList<>(value.mutations.size());
long mutationsCopied = 0l;
for (Mutation orig : value.mutations) {
if (orig instanceof ServerMutation) {
mutationsCopied++;
ServerMutation origServer = (ServerMutation) orig;
Mutation copy = new Mutation(orig.getRow());
for (ColumnUpdate update : orig.getUpdates()) {
long timestamp;
// If the update doesn't have a timestamp, pull it from the ServerMutation
if (!update.hasTimestamp()) {
timestamp = origServer.getSystemTimestamp();
} else {
timestamp = update.getTimestamp();
}
// TODO ACCUMULO-2937 cache the CVs
if (update.isDeleted()) {
copy.putDelete(update.getColumnFamily(), update.getColumnQualifier(), new ColumnVisibility(update.getColumnVisibility()), timestamp);
} else {
copy.put(update.getColumnFamily(), update.getColumnQualifier(), new ColumnVisibility(update.getColumnVisibility()), timestamp, update.getValue());
}
}
// We also need to preserve the replicationSource information to prevent cycles
Set<String> replicationSources = orig.getReplicationSources();
if (null != replicationSources && !replicationSources.isEmpty()) {
for (String replicationSource : replicationSources) {
copy.addReplicationSource(replicationSource);
}
}
mutationsCopy.add(copy);
} else {
mutationsCopy.add(orig);
}
}
log.debug("Copied {} mutations to ensure server-assigned timestamps are propagated", mutationsCopied);
try {
bw.addMutations(mutationsCopy);
} catch (MutationsRejectedException e) {
log.error("Could not apply mutations to {}", tableName);
throw new RemoteReplicationException(RemoteReplicationErrorCode.COULD_NOT_APPLY, "Could not apply mutations to " + tableName);
}
log.debug("{} mutations added to the BatchScanner", mutationsCopy.size());
mutationsApplied += mutationsCopy.size();
}
} finally {
if (null != bw) {
try {
bw.close();
} catch (MutationsRejectedException e) {
log.error("Could not apply mutations to {}", tableName);
throw new RemoteReplicationException(RemoteReplicationErrorCode.COULD_NOT_APPLY, "Could not apply mutations to " + tableName);
}
}
}
log.info("Applied {} mutations in total to {}", mutationsApplied, tableName);
return mutationsApplied;
}
Aggregations