Search in sources :

Example 56 with TTransportException

use of org.apache.thrift.transport.TTransportException in project atlasdb by palantir.

the class CassandraClientFactory method getRawClient.

private static Cassandra.Client getRawClient(InetSocketAddress addr, CassandraKeyValueServiceConfig config) throws TException {
    TSocket thriftSocket = new TSocket(addr.getHostString(), addr.getPort(), config.socketTimeoutMillis());
    thriftSocket.open();
    try {
        thriftSocket.getSocket().setKeepAlive(true);
        thriftSocket.getSocket().setSoTimeout(config.socketQueryTimeoutMillis());
    } catch (SocketException e) {
        log.error("Couldn't set socket keep alive for host {}", SafeArg.of("address", CassandraLogHelper.host(addr)));
    }
    if (config.usingSsl()) {
        boolean success = false;
        try {
            final SSLSocketFactory factory;
            if (config.sslConfiguration().isPresent()) {
                factory = SslSocketFactories.createSslSocketFactory(config.sslConfiguration().get());
            } else {
                factory = sslSocketFactories.getUnchecked(addr);
            }
            SSLSocket socket = (SSLSocket) factory.createSocket(thriftSocket.getSocket(), addr.getHostString(), addr.getPort(), true);
            thriftSocket = new TSocket(socket);
            success = true;
        } catch (IOException e) {
            throw new TTransportException(e);
        } finally {
            if (!success) {
                thriftSocket.close();
            }
        }
    }
    TTransport thriftFramedTransport = new TFramedTransport(thriftSocket, CassandraConstants.CLIENT_MAX_THRIFT_FRAME_SIZE_BYTES);
    TProtocol protocol = new TBinaryProtocol(thriftFramedTransport);
    Cassandra.Client client = new Cassandra.Client(protocol);
    if (config.credentials().isPresent()) {
        try {
            login(client, config.credentials().get());
        } catch (TException e) {
            client.getOutputProtocol().getTransport().close();
            log.error("Exception thrown attempting to authenticate with config provided credentials", e);
            throw e;
        }
    }
    return client;
}
Also used : TException(org.apache.thrift.TException) SocketException(java.net.SocketException) Client(org.apache.cassandra.thrift.Cassandra.Client) SSLSocket(javax.net.ssl.SSLSocket) Cassandra(org.apache.cassandra.thrift.Cassandra) TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransport(org.apache.thrift.transport.TTransport) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) QosClient(com.palantir.atlasdb.qos.QosClient) Client(org.apache.cassandra.thrift.Cassandra.Client) QosCassandraClient(com.palantir.atlasdb.keyvalue.cassandra.qos.QosCassandraClient) TSocket(org.apache.thrift.transport.TSocket)

Example 57 with TTransportException

use of org.apache.thrift.transport.TTransportException in project teiid by teiid.

the class AccumuloConnectionImpl method checkTabletServerExists.

private void checkTabletServerExists(ZooKeeperInstance inst, String userName, String password) throws ResourceException {
    ClientService.Client client = null;
    try {
        Pair<String, Client> pair = ServerClient.getConnection(new ClientContext(inst, new Credentials(userName, new PasswordToken(password)), inst.getConfiguration()), true, 10);
        client = pair.getSecond();
    } catch (TTransportException e) {
        throw new ResourceException(AccumuloManagedConnectionFactory.UTIL.getString("no_tserver"), e);
    } finally {
        if (client != null) {
            ServerClient.close(client);
        }
    }
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) ClientService(org.apache.accumulo.core.client.impl.thrift.ClientService) ClientContext(org.apache.accumulo.core.client.impl.ClientContext) TTransportException(org.apache.thrift.transport.TTransportException) ResourceException(javax.resource.ResourceException) Client(org.apache.accumulo.core.client.impl.thrift.ClientService.Client) Client(org.apache.accumulo.core.client.impl.thrift.ClientService.Client) ServerClient(org.apache.accumulo.core.client.impl.ServerClient) Credentials(org.apache.accumulo.core.client.impl.Credentials)

Example 58 with TTransportException

use of org.apache.thrift.transport.TTransportException in project sw360portal by sw360.

the class ThriftClients method makeProtocol.

/**
 * Creates a Thrift Compact Protocol object linked to the given address
 */
private static TProtocol makeProtocol(String url, String service) {
    THttpClient thriftClient = null;
    final String destinationAddress = url + service;
    try {
        thriftClient = new THttpClient(destinationAddress);
    } catch (TTransportException e) {
        log.error("cannot connect to backend on " + destinationAddress, e);
    }
    return new TCompactProtocol(thriftClient);
}
Also used : THttpClient(org.apache.thrift.transport.THttpClient) TTransportException(org.apache.thrift.transport.TTransportException) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol)

Example 59 with TTransportException

use of org.apache.thrift.transport.TTransportException in project providence by morimekta.

the class TProtocolSerializer method deserialize.

@Nonnull
@Override
public <Message extends PMessage<Message, Field>, Field extends PField> Message deserialize(@Nonnull InputStream input, @Nonnull PMessageDescriptor<Message, Field> descriptor) throws IOException {
    try {
        TTransport transport = new TIOStreamTransport(input);
        TProtocol protocol = protocolFactory.getProtocol(transport);
        return readMessage(protocol, descriptor);
    } catch (TTransportException e) {
        throw new SerializerException(e, "Unable to serialize into transport protocol");
    } catch (TException e) {
        throw new SerializerException(e, "Transport exception in protocol");
    }
}
Also used : TException(org.apache.thrift.TException) TProtocol(org.apache.thrift.protocol.TProtocol) TTransportException(org.apache.thrift.transport.TTransportException) TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) TTransport(org.apache.thrift.transport.TTransport) SerializerException(net.morimekta.providence.serializer.SerializerException) Nonnull(javax.annotation.Nonnull)

Example 60 with TTransportException

use of org.apache.thrift.transport.TTransportException 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) {
    try {
        double tracePercent = localConf.getFraction(Property.REPLICATION_TRACE_PERCENT);
        ProbabilitySampler sampler = new ProbabilitySampler(tracePercent);
        Trace.on("AccumuloReplicaSystem", sampler);
        // 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 span = Trace.start("Fetch peer tserver");
            try {
                // Ask the master on the remote what TServer we should talk with to replicate the data
                peerTserverStr = ReplicationClient.executeCoordinatorWithReturn(peerContext, new ClientExecReturn<String, ReplicationCoordinator.Client>() {

                    @Override
                    public String execute(ReplicationCoordinator.Client client) throws Exception {
                        return client.getServicerAddress(remoteTableId, peerContext.rpcCreds());
                    }
                });
            } catch (AccumuloException | AccumuloSecurityException e) {
                // No progress is made
                log.error("Could not connect to master at {}, cannot proceed with replication. Will retry", target, e);
                continue;
            } finally {
                span.stop();
            }
            if (null == peerTserverStr) {
                // Something went wrong, and we didn't get a valid tserver from the remote for some reason
                log.warn("Did not receive tserver from master 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 = Trace.start("RFile replication");
                    try {
                        finalStatus = replicateRFiles(peerContext, peerTserver, target, p, status, sizeLimit, remoteTableId, peerContext.rpcCreds(), helper, timeout);
                    } finally {
                        span.stop();
                    }
                } else {
                    span = Trace.start("WAL replication");
                    try {
                        finalStatus = replicateLogs(peerContext, peerTserver, target, p, status, sizeLimit, remoteTableId, peerContext.rpcCreds(), helper, accumuloUgi, timeout);
                    } finally {
                        span.stop();
                    }
                }
                log.debug("New status for {} after replicating to {} is {}", p, peerContext.getInstance(), ProtobufUtil.toString(finalStatus));
                return finalStatus;
            } catch (TTransportException | AccumuloException | AccumuloSecurityException e) {
                log.warn("Could not connect to remote server {}, will retry", peerTserverStr, e);
                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;
    } finally {
        Trace.off();
    }
}
Also used : ProbabilitySampler(org.apache.accumulo.core.trace.ProbabilitySampler) Status(org.apache.accumulo.server.replication.proto.Replication.Status) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ClientExecReturn(org.apache.accumulo.core.client.impl.ClientExecReturn) TTransportException(org.apache.thrift.transport.TTransportException) ReplicationCoordinator(org.apache.accumulo.core.replication.thrift.ReplicationCoordinator) Span(org.apache.accumulo.core.trace.Span) HostAndPort(org.apache.accumulo.core.util.HostAndPort) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Client(org.apache.accumulo.core.replication.thrift.ReplicationServicer.Client) ReplicationClient(org.apache.accumulo.core.client.impl.ReplicationClient)

Aggregations

TTransportException (org.apache.thrift.transport.TTransportException)165 TTransport (org.apache.thrift.transport.TTransport)43 TException (org.apache.thrift.TException)42 Test (org.junit.Test)39 IOException (java.io.IOException)38 TSocket (org.apache.thrift.transport.TSocket)38 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)29 TProtocol (org.apache.thrift.protocol.TProtocol)26 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)24 TServerSocket (org.apache.thrift.transport.TServerSocket)15 ArrayList (java.util.ArrayList)13 TFramedTransport (org.apache.thrift.transport.TFramedTransport)13 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)11 HostAndPort (org.apache.accumulo.core.util.HostAndPort)10 InetSocketAddress (java.net.InetSocketAddress)9 AccumuloException (org.apache.accumulo.core.client.AccumuloException)9 Function (org.apache.hadoop.hive.metastore.api.Function)9 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)8 ThriftSecurityException (org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException)8 Partition (org.apache.hadoop.hive.metastore.api.Partition)8