Search in sources :

Example 86 with TTransportException

use of org.apache.thrift.transport.TTransportException in project scale7-pelops by s7.

the class CommonsBackedPool method getConnectionExcept.

@Override
public IPooledConnection getConnectionExcept(Set<String> avoidNodes) throws NoConnectionsAvailableException {
    PooledNode node = null;
    IPooledConnection connection = null;
    long timeout = -1;
    while (connection == null) {
        if (timeout == -1) {
            // first run through calc the timeout for the next loop
            // (this makes debugging easier)
            int maxWait = getPolicy().getMaxWaitForConnection();
            timeout = maxWait > 0 ? System.currentTimeMillis() + maxWait : Long.MAX_VALUE;
        } else if (timeout < System.currentTimeMillis()) {
            logger.debug("Max wait time for connection exceeded");
            break;
        }
        node = nodeSelectionStrategy.select(this, nodes.keySet(), avoidNodes);
        // if the strategy was unable to choose a node (all suspended?) then sleep for a bit and loop
        if (node == null) {
            logger.debug("The node selection strategy was unable to choose a node, sleeping before trying again...");
            try {
                Thread.sleep(DEFAULT_WAIT_PERIOD);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
            continue;
        }
        try {
            logger.debug("Attempting to borrow free connection for node '{}'", node.getAddress());
            // note that if no connections are currently available for this node then the pool will sleep for
            // DEFAULT_WAIT_PERIOD milliseconds
            connection = pool.borrowObject(node.getAddress());
        } catch (IllegalStateException e) {
            throw new PelopsException("The pool has been shutdown", e);
        } catch (Exception e) {
            if (e instanceof NoSuchElementException) {
                logger.debug("No free connections available for node '{}'.  Trying another node...", node.getAddress());
            } else if (e instanceof TTransportException) {
                logger.warn(String.format("A TTransportException was thrown while attempting to create a connection to '%s'.  " + "This node will be suspended for %sms.  Trying another node...", node.getAddress(), this.policy.getNodeDownSuspensionMillis()));
                node.suspendForMillis(this.policy.getNodeDownSuspensionMillis());
            } else
                logger.warn(String.format("An exception was thrown while attempting to create a connection to '%s'.  " + "Trying another node...", node.getAddress()), e);
            // try and avoid this node on the next trip through the loop
            if (avoidNodes == null)
                avoidNodes = new HashSet<String>(10);
            avoidNodes.add(node.getAddress());
        }
    }
    if (node == null) {
        logger.error("Failed to get a connection within the configured wait time because there are no available nodes. " + "This possibly indicates that either the suspension strategy is too aggressive or that your " + "cluster is in a bad way.");
        throw new NoConnectionsAvailableException("Failed to get a connection within the configured max wait time.");
    }
    if (connection == null) {
        logger.error("Failed to get a connection within the maximum allowed wait time.  " + "Try increasing the either the number of allowed connections or the max wait time.");
        throw new NoConnectionsAvailableException("Failed to get a connection within the configured max wait time.");
    }
    logger.debug("Borrowing connection '{}'", connection);
    statistics.connectionsActive.incrementAndGet();
    reportConnectionBorrowed(connection.getNode().getAddress());
    return connection;
}
Also used : NoConnectionsAvailableException(org.scale7.cassandra.pelops.exceptions.NoConnectionsAvailableException) TTransportException(org.apache.thrift.transport.TTransportException) PelopsException(org.scale7.cassandra.pelops.exceptions.PelopsException) TTransportException(org.apache.thrift.transport.TTransportException) NoConnectionsAvailableException(org.scale7.cassandra.pelops.exceptions.NoConnectionsAvailableException) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) SocketException(java.net.SocketException) NoSuchElementException(java.util.NoSuchElementException) TException(org.apache.thrift.TException) PelopsException(org.scale7.cassandra.pelops.exceptions.PelopsException) NoSuchElementException(java.util.NoSuchElementException)

Example 87 with TTransportException

use of org.apache.thrift.transport.TTransportException in project eiger by wlloyd.

the class TCustomServerSocket method acceptImpl.

@Override
protected TCustomSocket acceptImpl() throws TTransportException {
    if (serverSocket_ == null)
        throw new TTransportException(TTransportException.NOT_OPEN, "No underlying server socket.");
    TCustomSocket tsocket = null;
    Socket socket = null;
    try {
        socket = serverSocket_.accept();
        tsocket = new TCustomSocket(socket);
        tsocket.setTimeout(0);
    } catch (IOException iox) {
        throw new TTransportException(iox);
    }
    try {
        socket.setKeepAlive(this.keepAlive);
    } catch (SocketException se) {
        logger.warn("Failed to set keep-alive on Thrift socket.", se);
    }
    if (this.sendBufferSize != null) {
        try {
            socket.setSendBufferSize(this.sendBufferSize.intValue());
        } catch (SocketException se) {
            logger.warn("Failed to set send buffer size on Thrift socket.", se);
        }
    }
    if (this.recvBufferSize != null) {
        try {
            socket.setReceiveBufferSize(this.recvBufferSize.intValue());
        } catch (SocketException se) {
            logger.warn("Failed to set receive buffer size on Thrift socket.", se);
        }
    }
    return tsocket;
}
Also used : SocketException(java.net.SocketException) TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException) ServerSocket(java.net.ServerSocket) TServerSocket(org.apache.thrift.transport.TServerSocket) Socket(java.net.Socket) TSocket(org.apache.thrift.transport.TSocket)

Example 88 with TTransportException

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

the class RemoteInterpreterEventServer method start.

public void start() throws IOException {
    Thread startingThread = new Thread() {

        @Override
        public void run() {
            try (TServerSocket tSocket = new TServerSocket(RemoteInterpreterUtils.findAvailablePort(portRange))) {
                port = tSocket.getServerSocket().getLocalPort();
                host = RemoteInterpreterUtils.findAvailableHostAddress();
                LOGGER.info("InterpreterEventServer is starting at {}:{}", host, port);
                RemoteInterpreterEventService.Processor<RemoteInterpreterEventServer> processor = new RemoteInterpreterEventService.Processor<>(RemoteInterpreterEventServer.this);
                thriftServer = new TThreadPoolServer(new TThreadPoolServer.Args(tSocket).processor(processor));
                thriftServer.serve();
            } catch (IOException | TTransportException e) {
                throw new RuntimeException("Fail to create TServerSocket", e);
            }
            LOGGER.info("ThriftServer-Thread finished");
        }
    };
    startingThread.start();
    long start = System.currentTimeMillis();
    while ((System.currentTimeMillis() - start) < 30 * 1000) {
        if (thriftServer != null && thriftServer.isServing()) {
            break;
        }
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            throw new IOException(e);
        }
    }
    if (thriftServer != null && !thriftServer.isServing()) {
        throw new IOException("Fail to start InterpreterEventServer in 30 seconds.");
    }
    LOGGER.info("RemoteInterpreterEventServer is started");
    runner = new AppendOutputRunner(listener);
    appendFuture = appendService.scheduleWithFixedDelay(runner, 0, AppendOutputRunner.BUFFER_TIME_MS, TimeUnit.MILLISECONDS);
}
Also used : RemoteInterpreterEventService(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterEventService) TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException) TServerSocket(org.apache.thrift.transport.TServerSocket) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer) AppendOutputRunner(org.apache.zeppelin.interpreter.remote.AppendOutputRunner)

Example 89 with TTransportException

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

the class ClusterMockTest method startCluster.

public static void startCluster() throws IOException, InterruptedException {
    LOGGER.info("startCluster >>>");
    zconf = ZeppelinConfiguration.create();
    // Set the cluster IP and port
    zServerHost = RemoteInterpreterUtils.findAvailableHostAddress();
    zServerPort = RemoteInterpreterUtils.findRandomAvailablePortOnAllLocalInterfaces();
    zconf.setClusterAddress(zServerHost + ":" + zServerPort);
    // mock cluster manager server
    clusterServer = ClusterManagerServer.getInstance(zconf);
    clusterServer.start();
    // mock cluster manager client
    clusterClient = ClusterManagerClient.getInstance(zconf);
    clusterClient.start(metaKey);
    // Waiting for cluster startup
    int wait = 0;
    while (wait++ < 100) {
        if (clusterServer.isClusterLeader() && clusterServer.raftInitialized() && clusterClient.raftInitialized()) {
            LOGGER.info("wait {}(ms) found cluster leader", wait * 3000);
            break;
        }
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    assertEquals(true, clusterServer.isClusterLeader());
    try {
        tSocket = new TServerSocket(0);
    } catch (TTransportException e) {
        throw new IOException("Fail to create TServerSocket", e);
    }
    LOGGER.info("startCluster <<<");
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException)

Example 90 with TTransportException

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

the class TSubjectAssumingTransport method open.

@Override
public void open() throws TTransportException {
    try {
        AccessControlContext context = AccessController.getContext();
        Subject subject = Subject.getSubject(context);
        Subject.doAs(subject, new PrivilegedExceptionAction<Void>() {

            public Void run() {
                try {
                    wrapped.open();
                } catch (TTransportException tte) {
                    // more time in our catch clause to get back the TTE. (ugh)
                    throw new RuntimeException(tte);
                }
                return null;
            }
        });
    } catch (PrivilegedActionException ioe) {
        throw new RuntimeException("Received an ioe we never threw!", ioe);
    } catch (RuntimeException rte) {
        if (rte.getCause() instanceof TTransportException) {
            throw (TTransportException) rte.getCause();
        } else {
            throw rte;
        }
    }
}
Also used : AccessControlContext(java.security.AccessControlContext) PrivilegedActionException(java.security.PrivilegedActionException) TTransportException(org.apache.thrift.transport.TTransportException) Subject(javax.security.auth.Subject)

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