use of alluxio.exception.FailedToAcquireRegisterLeaseException in project alluxio by Alluxio.
the class BlockMasterSync method registerWithMaster.
/**
* Registers with the Alluxio master. This should be called before the
* continuous heartbeat thread begins.
*/
private void registerWithMaster() throws IOException {
BlockStoreMeta storeMeta = mBlockWorker.getStoreMetaFull();
StorageTierAssoc storageTierAssoc = new WorkerStorageTierAssoc();
List<ConfigProperty> configList = ConfigurationUtils.getConfiguration(ServerConfiguration.global(), Scope.WORKER);
if (ACQUIRE_LEASE) {
LOG.info("Acquiring a RegisterLease from the master before registering");
try {
mMasterClient.acquireRegisterLeaseWithBackoff(mWorkerId.get(), storeMeta.getNumberOfBlocks(), getDefaultAcquireLeaseRetryPolicy());
LOG.info("Lease acquired");
} catch (FailedToAcquireRegisterLeaseException e) {
mMasterClient.disconnect();
if (ServerConfiguration.getBoolean(PropertyKey.TEST_MODE)) {
throw new RuntimeException(String.format("Master register lease timeout exceeded: %dms", ACQUIRE_LEASE_WAIT_MAX_DURATION));
}
ProcessUtils.fatalError(LOG, "Master register lease timeout exceeded: %dms", ACQUIRE_LEASE_WAIT_MAX_DURATION);
}
}
if (mUseStreaming) {
mMasterClient.registerWithStream(mWorkerId.get(), storageTierAssoc.getOrderedStorageAliases(), storeMeta.getCapacityBytesOnTiers(), storeMeta.getUsedBytesOnTiers(), storeMeta.getBlockListByStorageLocation(), storeMeta.getLostStorage(), configList);
} else {
mMasterClient.register(mWorkerId.get(), storageTierAssoc.getOrderedStorageAliases(), storeMeta.getCapacityBytesOnTiers(), storeMeta.getUsedBytesOnTiers(), storeMeta.getBlockListByStorageLocation(), storeMeta.getLostStorage(), configList);
}
// If the worker registers with master successfully, the lease will be recycled on the
// master side. No need to manually request for recycle on the worker side.
}
use of alluxio.exception.FailedToAcquireRegisterLeaseException 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);
}
Aggregations