use of org.apache.accumulo.core.conf.AccumuloConfiguration in project accumulo by apache.
the class AccumuloReplicaSystem method _replicate.
/**
* Perform replication, making a few attempts when an exception is returned.
*
* @param p
* Path of WAL to replicate
* @param status
* Current status for the WAL
* @param target
* Where we're replicating to
* @param helper
* A helper for replication
* @param localConf
* The local instance's configuration
* @param peerContext
* The ClientContext to connect to the peer
* @return The new (or unchanged) Status for the WAL
*/
private Status _replicate(final Path p, final Status status, final ReplicationTarget target, final ReplicaSystemHelper helper, final AccumuloConfiguration localConf, final ClientContext peerContext, final UserGroupInformation accumuloUgi) {
Span span = TraceUtil.startSpan(this.getClass(), "_replicate");
try (Scope replicaScope = span.makeCurrent()) {
// Remote identifier is an integer (table id) in this case.
final String remoteTableId = target.getRemoteIdentifier();
// Attempt the replication of this status a number of times before giving up and
// trying to replicate it again later some other time.
int numAttempts = localConf.getCount(Property.REPLICATION_WORK_ATTEMPTS);
for (int i = 0; i < numAttempts; i++) {
log.debug("Attempt {}", i);
String peerTserverStr;
log.debug("Fetching peer tserver address");
Span span2 = TraceUtil.startSpan(this.getClass(), "_replicate::Fetch peer tserver");
try (Scope scope = span2.makeCurrent()) {
// Ask the manager on the remote what TServer we should talk with to replicate the data
peerTserverStr = ReplicationClient.executeCoordinatorWithReturn(peerContext, client -> client.getServicerAddress(remoteTableId, peerContext.rpcCreds()));
} catch (AccumuloException | AccumuloSecurityException e) {
// No progress is made
log.error("Could not connect to manager at {}, cannot proceed with replication. Will retry", target, e);
TraceUtil.setException(span2, e, false);
continue;
} catch (Exception e) {
TraceUtil.setException(span2, e, true);
throw e;
} finally {
span2.end();
}
if (peerTserverStr == null) {
// Something went wrong, and we didn't get a valid tserver from the remote for some reason
log.warn("Did not receive tserver from manager at {}, cannot proceed" + " with replication. Will retry.", target);
continue;
}
final HostAndPort peerTserver = HostAndPort.fromString(peerTserverStr);
final long timeout = localConf.getTimeInMillis(Property.REPLICATION_RPC_TIMEOUT);
// We have a tserver on the remote -- send the data its way.
Status finalStatus;
final long sizeLimit = conf.getAsBytes(Property.REPLICATION_MAX_UNIT_SIZE);
try {
if (p.getName().endsWith(RFILE_SUFFIX)) {
Span span3 = TraceUtil.startSpan(this.getClass(), "_replicate::RFile replication");
try (Scope scope = span3.makeCurrent()) {
finalStatus = replicateRFiles(peerContext, peerTserver, target, p, status, timeout);
} catch (Exception e) {
TraceUtil.setException(span3, e, true);
throw e;
} finally {
span3.end();
}
} else {
Span span4 = TraceUtil.startSpan(this.getClass(), "_replicate::WAL replication");
try (Scope scope = span4.makeCurrent()) {
finalStatus = replicateLogs(peerContext, peerTserver, target, p, status, sizeLimit, remoteTableId, peerContext.rpcCreds(), helper, accumuloUgi, timeout);
} catch (Exception e) {
TraceUtil.setException(span4, e, true);
throw e;
} finally {
span4.end();
}
}
log.debug("New status for {} after replicating to {} is {}", p, peerContext.getInstanceName(), ProtobufUtil.toString(finalStatus));
return finalStatus;
} catch (TTransportException | AccumuloException | AccumuloSecurityException e) {
log.warn("Could not connect to remote server {}, will retry", peerTserverStr, e);
TraceUtil.setException(span, e, false);
sleepUninterruptibly(1, TimeUnit.SECONDS);
}
}
log.info("No progress was made after {} attempts to replicate {}," + " returning so file can be re-queued", numAttempts, p);
// We made no status, punt on it for now, and let it re-queue itself for work
return status;
} catch (Exception e) {
TraceUtil.setException(span, e, true);
throw e;
} finally {
span.end();
}
}
use of org.apache.accumulo.core.conf.AccumuloConfiguration in project accumulo by apache.
the class ReplicationServicerHandler method replicateLog.
@Override
public long replicateLog(String tableIdStr, WalEdits data, TCredentials tcreds) throws TException {
TableId tableId = TableId.of(tableIdStr);
log.debug("Got replication request to tableID {} with {} edits", tableId, data.getEditsSize());
tabletServer.getSecurityOperation().authenticateUser(tabletServer.getContext().rpcCreds(), tcreds);
String tableName;
try {
tableName = tabletServer.getContext().getTableName(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 (handlerClassForTable == null) {
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.getDeclaredConstructor().newInstance();
} catch (ReflectiveOperationException 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.getContext(), tableName, data);
} catch (AccumuloException | AccumuloSecurityException e) {
log.error("Could not get connection", e);
throw new RemoteReplicationException(RemoteReplicationErrorCode.CANNOT_AUTHENTICATE, "Cannot get connection as " + tabletServer.getContext().getCredentials().getPrincipal());
}
log.debug("Replicated {} mutations to {}", entriesReplicated, tableName);
return entriesReplicated;
}
use of org.apache.accumulo.core.conf.AccumuloConfiguration in project accumulo by apache.
the class SecurityOperation method getAuthenticator.
protected static Authenticator getAuthenticator(String instanceId, boolean initialize) {
AccumuloConfiguration conf = SiteConfiguration.getInstance();
Authenticator toRet = Property.createInstanceFromPropertyName(conf, Property.INSTANCE_SECURITY_AUTHENTICATOR, Authenticator.class, ZKAuthenticator.getInstance());
toRet.initialize(instanceId, initialize);
return toRet;
}
use of org.apache.accumulo.core.conf.AccumuloConfiguration in project accumulo by apache.
the class SecurityOperation method getAuthorizor.
protected static Authorizor getAuthorizor(String instanceId, boolean initialize) {
AccumuloConfiguration conf = SiteConfiguration.getInstance();
Authorizor toRet = Property.createInstanceFromPropertyName(conf, Property.INSTANCE_SECURITY_AUTHORIZOR, Authorizor.class, ZKAuthorizor.getInstance());
toRet.initialize(instanceId, initialize);
return toRet;
}
use of org.apache.accumulo.core.conf.AccumuloConfiguration in project accumulo by apache.
the class SystemCredentials method get.
public static SystemCredentials get(Instance instance) {
String principal = SYSTEM_PRINCIPAL;
AccumuloConfiguration conf = SiteConfiguration.getInstance();
if (conf.getBoolean(Property.INSTANCE_RPC_SASL_ENABLED)) {
// Use the server's kerberos principal as the Accumulo principal. We could also unwrap the principal server-side, but the principal for SystemCredentials
// isnt' actually used anywhere, so it really doesn't matter. We can't include the kerberos principal in the SystemToken as it would break equality when
// different Accumulo servers are using different kerberos principals are their accumulo principal
principal = SecurityUtil.getServerPrincipal(conf.get(Property.GENERAL_KERBEROS_PRINCIPAL));
}
return new SystemCredentials(instance, principal, SystemToken.get(instance));
}
Aggregations