/** * Returns a worker id for a workers net address. * * @param address the net address to get a worker id for * @return a worker id * @throws IOException if an I/O error occurs */ // TODO: rename to workerRegister? public synchronized long getId(NetAddress address) throws IOException { int retry = 0; while (!mClosed && (retry ++) <= RPC_MAX_NUM_RETRY) { connect(); try { return mClient.workerGetWorkerId(address); } catch (TException e) { LOG.error(e.getMessage(), e); mConnected = false; } } throw new IOException("Failed after " + retry + " retries."); }
/** * Registers with {@link BlockMaster} to get a new worker ID. * * @param masterClient the master client to be used for RPC * @param workerAddress current worker address * @throws IOException when fails to get a new worker ID */ public static void registerWithBlockMaster(WorkerBlockMasterClient masterClient, NetAddress workerAddress) throws IOException { sWorkerId.set(masterClient.getId(workerAddress)); }
try { cmdFromMaster = mMasterClient .heartbeat(WorkerIdRegistry.getWorkerId(), storeMeta.getUsedBytesOnTiers(), blockReport.getRemovedBlocks(), blockReport.getAddedBlocks()); lastHeartbeatMs = System.currentTimeMillis(); + cmdFromMaster.toString(), e); mMasterClient.resetConnection(); CommonUtils.sleepMs(LOG, Constants.SECOND_MS); if (System.currentTimeMillis() - lastHeartbeatMs >= mHeartbeatTimeoutMs) {
/** * Registers with the Tachyon master. This should be called before the continuous heartbeat thread * begins. The workerId will be set after this method is successful. * * @throws IOException when workerId cannot be found */ private void registerWithMaster() throws IOException { BlockStoreMeta storeMeta = mBlockDataManager.getStoreMeta(); try { mMasterClient.register(WorkerIdRegistry.getWorkerId(), storeMeta.getCapacityBytesOnTiers(), storeMeta.getUsedBytesOnTiers(), storeMeta.getBlockList()); } catch (IOException ioe) { LOG.error("Failed to register with master.", ioe); throw ioe; } }
BlockStoreMeta storeMeta = mBlockStore.getBlockStoreMeta(); Long bytesUsedOnTier = storeMeta.getUsedBytesOnTiers().get(loc.tierAlias() - 1); mBlockMasterClient.commitBlock(WorkerIdRegistry.getWorkerId(), bytesUsedOnTier, tier, blockId, length); } catch (IOException ioe) {
mPinListSync.stop(); mSessionCleanerThread.stop(); mBlockMasterClient.close(); if (mSpaceReserver != null) { mSpaceReserver.stop();
mBlockMasterClient = new WorkerBlockMasterClient( NetworkAddressUtils.getConnectAddress(ServiceType.MASTER_RPC, mTachyonConf), mTachyonConf);
/** * The method the worker should periodically execute to heartbeat back to the master. * * @param workerId the worker id * @param usedBytesOnTiers a list of used bytes on each tier * @param removedBlocks a list of block removed from this worker * @param addedBlocks the added blocks for each storage dir. It maps storage dir id, to a list of * added block for that storage dir. * @return an optional command for the worker to execute * @throws IOException if an I/O error occurs */ public synchronized Command heartbeat(long workerId, List<Long> usedBytesOnTiers, List<Long> removedBlocks, Map<Long, List<Long>> addedBlocks) throws IOException { int retry = 0; while (!mClosed && (retry ++) <= RPC_MAX_NUM_RETRY) { connect(); try { return mClient.workerHeartbeat(workerId, usedBytesOnTiers, removedBlocks, addedBlocks); } catch (TException e) { LOG.error(e.getMessage(), e); mConnected = false; } } throw new IOException("Failed after " + retry + " retries."); }
/** * Commits a block on a worker. * * @param workerId the worker id committing the block * @param usedBytesOnTier the amount of used bytes on the tier the block is committing to * @param tier the tier the block is being committed to * @param blockId the block id being committed * @param length the length of the block being committed * @throws IOException if an I/O error occurs */ public synchronized void commitBlock(long workerId, long usedBytesOnTier, int tier, long blockId, long length) throws IOException { int retry = 0; while (!mClosed && (retry ++) <= RPC_MAX_NUM_RETRY) { connect(); try { mClient.workerCommitBlock(workerId, usedBytesOnTier, tier, blockId, length); return; } catch (TException e) { LOG.error(e.getMessage(), e); mConnected = false; } } throw new IOException("Failed after " + retry + " retries."); }
/** * The method the worker should execute to register with the block master. * * @param workerId the worker id of the worker registering * @param totalBytesOnTiers list of total bytes on each tier * @param usedBytesOnTiers list of the used byes on each tier * @param currentBlocksOnTiers a mapping of each storage dir, to all the blocks on that storage * dir * @throws IOException if an I/O error occurs or the workerId doesn't exist */ // TODO: rename to workerBlockReport or workerInitialize? public synchronized void register(long workerId, List<Long> totalBytesOnTiers, List<Long> usedBytesOnTiers, Map<Long, List<Long>> currentBlocksOnTiers) throws IOException { int retry = 0; while (!mClosed && (retry ++) <= RPC_MAX_NUM_RETRY) { connect(); try { mClient.workerRegister(workerId, totalBytesOnTiers, usedBytesOnTiers, currentBlocksOnTiers); return; } catch (TException e) { LOG.error(e.getMessage(), e); mConnected = false; } } throw new IOException("Failed after " + retry + " retries."); } }