Search in sources :

Example 91 with AccumuloConfiguration

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();
    }
}
Also used : WalEdits(org.apache.accumulo.core.replication.thrift.WalEdits) LogFileValue(org.apache.accumulo.tserver.logger.LogFileValue) ReplicationClient(org.apache.accumulo.core.clientImpl.ReplicationClient) TTransportException(org.apache.thrift.transport.TTransportException) LoggerFactory(org.slf4j.LoggerFactory) Status(org.apache.accumulo.server.replication.proto.Replication.Status) Mutation(org.apache.accumulo.core.data.Mutation) ByteBuffer(java.nio.ByteBuffer) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) DataOutputStream(java.io.DataOutputStream) ReplicationServicer(org.apache.accumulo.core.replication.thrift.ReplicationServicer) Map(java.util.Map) Path(org.apache.hadoop.fs.Path) ReplicaSystemHelper(org.apache.accumulo.server.replication.ReplicaSystemHelper) DfsLogger(org.apache.accumulo.tserver.log.DfsLogger) Property(org.apache.accumulo.core.conf.Property) ReplicationTarget(org.apache.accumulo.core.replication.ReplicationTarget) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) StatusUtil(org.apache.accumulo.server.replication.StatusUtil) Span(io.opentelemetry.api.trace.Span) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) Client(org.apache.accumulo.core.replication.thrift.ReplicationServicer.Client) ClientInfo(org.apache.accumulo.core.clientImpl.ClientInfo) Set(java.util.Set) LogHeaderIncompleteException(org.apache.accumulo.tserver.log.DfsLogger.LogHeaderIncompleteException) LogFileKey(org.apache.accumulo.tserver.logger.LogFileKey) TCredentials(org.apache.accumulo.core.securityImpl.thrift.TCredentials) PrivilegedAction(java.security.PrivilegedAction) EOFException(java.io.EOFException) KerberosToken(org.apache.accumulo.core.client.security.tokens.KerberosToken) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) ClientExecReturn(org.apache.accumulo.core.clientImpl.ClientExecReturn) ReplicaSystem(org.apache.accumulo.server.replication.ReplicaSystem) UtilWaitThread.sleepUninterruptibly(org.apache.accumulo.fate.util.UtilWaitThread.sleepUninterruptibly) TraceUtil(org.apache.accumulo.core.trace.TraceUtil) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) DataInputStream(java.io.DataInputStream) HostAndPort(org.apache.accumulo.core.util.HostAndPort) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ProtobufUtil(org.apache.accumulo.core.protobuf.ProtobufUtil) SingletonReservation(org.apache.accumulo.core.singletons.SingletonReservation) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Objects.requireNonNull(java.util.Objects.requireNonNull) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Properties(java.util.Properties) Logger(org.slf4j.Logger) Scope(io.opentelemetry.context.Scope) ServerContext(org.apache.accumulo.server.ServerContext) IOException(java.io.IOException) File(java.io.File) AccumuloException(org.apache.accumulo.core.client.AccumuloException) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) TimeUnit(java.util.concurrent.TimeUnit) RFile(org.apache.accumulo.core.file.rfile.RFile) ClientProperty(org.apache.accumulo.core.conf.ClientProperty) Status(org.apache.accumulo.server.replication.proto.Replication.Status) AccumuloException(org.apache.accumulo.core.client.AccumuloException) TTransportException(org.apache.thrift.transport.TTransportException) Span(io.opentelemetry.api.trace.Span) TTransportException(org.apache.thrift.transport.TTransportException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) LogHeaderIncompleteException(org.apache.accumulo.tserver.log.DfsLogger.LogHeaderIncompleteException) EOFException(java.io.EOFException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) HostAndPort(org.apache.accumulo.core.util.HostAndPort) Scope(io.opentelemetry.context.Scope) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException)

Example 92 with AccumuloConfiguration

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;
}
Also used : TableId(org.apache.accumulo.core.data.TableId) AccumuloException(org.apache.accumulo.core.client.AccumuloException) 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)

Example 93 with AccumuloConfiguration

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;
}
Also used : Authenticator(org.apache.accumulo.server.security.handler.Authenticator) ZKAuthenticator(org.apache.accumulo.server.security.handler.ZKAuthenticator) KerberosAuthenticator(org.apache.accumulo.server.security.handler.KerberosAuthenticator) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration)

Example 94 with AccumuloConfiguration

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;
}
Also used : Authorizor(org.apache.accumulo.server.security.handler.Authorizor) ZKAuthorizor(org.apache.accumulo.server.security.handler.ZKAuthorizor) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration)

Example 95 with AccumuloConfiguration

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));
}
Also used : AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration)

Aggregations

AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)164 Test (org.junit.Test)51 Path (org.apache.hadoop.fs.Path)44 IOException (java.io.IOException)31 ConfigurationCopy (org.apache.accumulo.core.conf.ConfigurationCopy)31 Configuration (org.apache.hadoop.conf.Configuration)27 HashMap (java.util.HashMap)24 ArrayList (java.util.ArrayList)23 Key (org.apache.accumulo.core.data.Key)23 FileSystem (org.apache.hadoop.fs.FileSystem)22 Value (org.apache.accumulo.core.data.Value)21 ServerContext (org.apache.accumulo.server.ServerContext)18 Property (org.apache.accumulo.core.conf.Property)16 DefaultConfiguration (org.apache.accumulo.core.conf.DefaultConfiguration)15 HostAndPort (org.apache.accumulo.core.util.HostAndPort)15 Map (java.util.Map)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 DataInputStream (java.io.DataInputStream)11 SamplerConfiguration (org.apache.accumulo.core.client.sample.SamplerConfiguration)11 SamplerConfigurationImpl (org.apache.accumulo.core.sample.impl.SamplerConfigurationImpl)11