Search in sources :

Example 1 with GetRegisterLeasePResponse

use of alluxio.grpc.GetRegisterLeasePResponse in project alluxio by Alluxio.

the class BlockMasterClient method acquireRegisterLeaseWithBackoff.

/**
 * Acquires a {@link alluxio.wire.RegisterLease} from the master with
 * the {@link RetryPolicy} specified.
 * If all the retry attempts have been exhaused, a {@link FailedToAcquireRegisterLeaseException}
 * will be thrown.
 *
 * @param workerId the worker ID
 * @param estimatedBlockCount the number of blocks this worker currently holds
 *    There is a gap between acquiring a lease and generating the {@link RegisterWorkerPRequest}
 *    so the real block count may be different. But this is a good hint for the master to
 *    guess how much resource the registration will take.
 * @param retry a retry policy
 */
public void acquireRegisterLeaseWithBackoff(final long workerId, final int estimatedBlockCount, final RetryPolicy retry) throws IOException, FailedToAcquireRegisterLeaseException {
    boolean leaseAcquired = false;
    GetRegisterLeasePResponse response = null;
    while (!leaseAcquired && retry.attempt()) {
        LOG.debug("Worker {} attempting to grant registration lease from the master, iter {}", workerId, retry.getAttemptCount());
        response = acquireRegisterLease(workerId, estimatedBlockCount);
        LOG.debug("Worker {} lease response: {}", workerId, response);
        leaseAcquired = response.getAllowed();
    }
    if (response == null || !response.getAllowed()) {
        throw new FailedToAcquireRegisterLeaseException(String.format("Failed to acquire a register lease from master after %d attempts", retry.getAttemptCount()));
    }
    LOG.info("Worker {} acquired lease after {} attempts: {}", workerId, retry.getAttemptCount(), response);
}
Also used : GetRegisterLeasePResponse(alluxio.grpc.GetRegisterLeasePResponse) FailedToAcquireRegisterLeaseException(alluxio.exception.FailedToAcquireRegisterLeaseException)

Aggregations

FailedToAcquireRegisterLeaseException (alluxio.exception.FailedToAcquireRegisterLeaseException)1 GetRegisterLeasePResponse (alluxio.grpc.GetRegisterLeasePResponse)1