use of org.apache.accumulo.core.replication.AccumuloReplicationReplayer 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;
}
Aggregations