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());
}
}
}
Aggregations