Search in sources :

Example 1 with AccumuloReplicationReplayer

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

Aggregations

AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 Table (org.apache.accumulo.core.client.impl.Table)1 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)1 AccumuloReplicationReplayer (org.apache.accumulo.core.replication.AccumuloReplicationReplayer)1 RemoteReplicationException (org.apache.accumulo.core.replication.thrift.RemoteReplicationException)1