Search in sources :

Example 1 with GrpcMessagingClient

use of alluxio.master.transport.GrpcMessagingClient in project alluxio by Alluxio.

the class BackupWorkerRole method establishConnectionToLeader.

/**
 * Establishes a connection with the leader backup master.
 */
private void establishConnectionToLeader() {
    // Create unending retry policy for establishing connection with the leader backup master.
    RetryPolicy infiniteRetryPolicy = new ExponentialBackoffRetry((int) mLeaderConnectionIntervalMin, (int) mLeaderConnectionIntervalMax, Integer.MAX_VALUE);
    while (infiniteRetryPolicy.attempt()) {
        // Get leader address.
        InetSocketAddress leaderAddress;
        try {
            // Create inquire client to determine leader address.
            MasterInquireClient inquireClient = MasterClientContext.newBuilder(ClientContext.create(ServerConfiguration.global())).build().getMasterInquireClient();
            leaderAddress = inquireClient.getPrimaryRpcAddress();
        } catch (Throwable t) {
            LOG.warn("Failed to get backup-leader address. {}. Error:{}. Attempt:{}", t.toString(), infiniteRetryPolicy.getAttemptCount());
            continue;
        }
        // InetSocketAddress acquired. Establish messaging connection with the leader.
        try {
            // Create messaging client for backup-leader.
            GrpcMessagingClient messagingClient = new GrpcMessagingClient(ServerConfiguration.global(), mServerUserState, mExecutorService, "BackupWorker");
            // Initiate the connection to backup-leader on catalyst context and wait.
            mLeaderConnection = mGrpcMessagingContext.execute(() -> messagingClient.connect(leaderAddress)).get().get();
            // Activate the connection.
            activateLeaderConnection(mLeaderConnection);
            LOG.info("Established connection to backup-leader: {}", leaderAddress);
            break;
        } catch (Throwable t) {
            LOG.warn("Failed to establish connection to backup-leader: {}. Error:{}. Attempt:{}", leaderAddress, t.toString(), infiniteRetryPolicy.getAttemptCount());
        }
    }
}
Also used : MasterInquireClient(alluxio.master.MasterInquireClient) ExponentialBackoffRetry(alluxio.retry.ExponentialBackoffRetry) InetSocketAddress(java.net.InetSocketAddress) GrpcMessagingClient(alluxio.master.transport.GrpcMessagingClient) RetryPolicy(alluxio.retry.RetryPolicy)

Aggregations

MasterInquireClient (alluxio.master.MasterInquireClient)1 GrpcMessagingClient (alluxio.master.transport.GrpcMessagingClient)1 ExponentialBackoffRetry (alluxio.retry.ExponentialBackoffRetry)1 RetryPolicy (alluxio.retry.RetryPolicy)1 InetSocketAddress (java.net.InetSocketAddress)1