/** * 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."); }
/** * 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."); } }