use of alluxio.WorkerStorageTierAssoc in project alluxio by Alluxio.
the class AlluxioWorkerRestServiceHandler method getTierAliasComparator.
private Comparator<String> getTierAliasComparator() {
return new Comparator<String>() {
private WorkerStorageTierAssoc mTierAssoc = new WorkerStorageTierAssoc();
@Override
public int compare(String tier1, String tier2) {
int ordinal1 = mTierAssoc.getOrdinal(tier1);
int ordinal2 = mTierAssoc.getOrdinal(tier2);
if (ordinal1 < ordinal2) {
return -1;
}
if (ordinal1 == ordinal2) {
return 0;
}
return 1;
}
};
}
use of alluxio.WorkerStorageTierAssoc 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.
*
* @throws IOException when workerId cannot be found
* @throws ConnectionFailedException if network connection failed
*/
private void registerWithMaster() throws IOException, ConnectionFailedException {
BlockStoreMeta storeMeta = mBlockWorker.getStoreMetaFull();
try {
StorageTierAssoc storageTierAssoc = new WorkerStorageTierAssoc();
mMasterClient.register(mWorkerId.get(), storageTierAssoc.getOrderedStorageAliases(), storeMeta.getCapacityBytesOnTiers(), storeMeta.getUsedBytesOnTiers(), storeMeta.getBlockList());
} catch (IOException e) {
LOG.error("Failed to register with master.", e);
throw e;
} catch (AlluxioException e) {
LOG.error("Failed to register with master.", e);
throw new IOException(e);
}
}
use of alluxio.WorkerStorageTierAssoc in project alluxio by Alluxio.
the class WebInterfaceWorkerBlockInfoServlet method doGet.
/**
* Populates attributes before redirecting to a jsp.
*
* @param request the {@link HttpServletRequest} object
* @param response the {@link HttpServletResponse} object
* @throws ServletException if the target resource throws this exception
* @throws IOException if the target resource throws this exception
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setAttribute("fatalError", "");
String filePath = request.getParameter("path");
if (!(filePath == null || filePath.isEmpty())) {
// Display file block info
try {
UIFileInfo uiFileInfo = getUiFileInfo(new AlluxioURI(filePath));
List<ImmutablePair<String, List<UIFileBlockInfo>>> fileBlocksOnTier = new ArrayList<>();
for (Entry<String, List<UIFileBlockInfo>> e : uiFileInfo.getBlocksOnTier().entrySet()) {
fileBlocksOnTier.add(new ImmutablePair<>(e.getKey(), e.getValue()));
}
request.setAttribute("fileBlocksOnTier", fileBlocksOnTier);
request.setAttribute("blockSizeBytes", uiFileInfo.getBlockSizeBytes());
request.setAttribute("path", filePath);
getServletContext().getRequestDispatcher("/worker/viewFileBlocks.jsp").forward(request, response);
return;
} catch (FileDoesNotExistException e) {
request.setAttribute("fatalError", "Error: Invalid Path " + e.getMessage());
getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
return;
} catch (IOException e) {
request.setAttribute("invalidPathError", "Error: File " + filePath + " is not available " + e.getMessage());
getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
return;
} catch (BlockDoesNotExistException e) {
request.setAttribute("fatalError", "Error: block not found. " + e.getMessage());
getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
return;
} catch (AlluxioException e) {
request.setAttribute("fatalError", "Error: alluxio exception. " + e.getMessage());
getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
return;
}
}
List<Long> fileIds = getSortedFileIds();
request.setAttribute("nTotalFile", fileIds.size());
request.setAttribute("orderedTierAliases", new WorkerStorageTierAssoc().getOrderedStorageAliases());
// URL can not determine offset and limit, let javascript in jsp determine and redirect
if (request.getParameter("offset") == null && request.getParameter("limit") == null) {
getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
return;
}
try {
int offset = Integer.parseInt(request.getParameter("offset"));
int limit = Integer.parseInt(request.getParameter("limit"));
List<Long> subFileIds = fileIds.subList(offset, offset + limit);
List<UIFileInfo> uiFileInfos = new ArrayList<>(subFileIds.size());
for (long fileId : subFileIds) {
try {
uiFileInfos.add(getUiFileInfo(fileId));
} catch (IOException e) {
// The file might have been deleted, log a warning and ignore this file.
LOG.warn("Unable to get file info for fileId {}. {}", fileId, e.getMessage());
}
}
request.setAttribute("fileInfos", uiFileInfos);
} catch (FileDoesNotExistException e) {
request.setAttribute("fatalError", "Error: Invalid FileId " + e.getMessage());
getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
return;
} catch (NumberFormatException e) {
request.setAttribute("fatalError", "Error: offset or limit parse error, " + e.getLocalizedMessage());
getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
return;
} catch (IndexOutOfBoundsException e) {
request.setAttribute("fatalError", "Error: offset or offset + limit is out of bound, " + e.getLocalizedMessage());
getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
return;
} catch (IllegalArgumentException | AlluxioException e) {
request.setAttribute("fatalError", e.getLocalizedMessage());
getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
return;
}
getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
}
use of alluxio.WorkerStorageTierAssoc in project alluxio by Alluxio.
the class MasterWorkerInfo method register.
/**
* Marks the worker as registered, while updating all of its metadata.
*
* @param globalStorageTierAssoc global mapping between storage aliases and ordinal position
* @param storageTierAliases list of storage tier aliases in order of their position in the
* hierarchy
* @param totalBytesOnTiers mapping from storage tier alias to total bytes
* @param usedBytesOnTiers mapping from storage tier alias to used byes
* @param blocks set of block ids on this worker
* @return A Set of blocks removed (or lost) from this worker
*/
public Set<Long> register(final StorageTierAssoc globalStorageTierAssoc, final List<String> storageTierAliases, final Map<String, Long> totalBytesOnTiers, final Map<String, Long> usedBytesOnTiers, final Set<Long> blocks) {
// ordering, throw an error
for (int i = 0; i < storageTierAliases.size() - 1; i++) {
if (globalStorageTierAssoc.getOrdinal(storageTierAliases.get(i)) >= globalStorageTierAssoc.getOrdinal(storageTierAliases.get(i + 1))) {
throw new IllegalArgumentException("Worker cannot place storage tier " + storageTierAliases.get(i) + " above " + storageTierAliases.get(i + 1) + " in the hierarchy");
}
}
mStorageTierAssoc = new WorkerStorageTierAssoc(storageTierAliases);
// validate the number of tiers
if (mStorageTierAssoc.size() != totalBytesOnTiers.size() || mStorageTierAssoc.size() != usedBytesOnTiers.size()) {
throw new IllegalArgumentException("totalBytesOnTiers and usedBytesOnTiers should have the same number of tiers as " + "storageTierAliases, but storageTierAliases has " + mStorageTierAssoc.size() + " tiers, while totalBytesOnTiers has " + totalBytesOnTiers.size() + " tiers and usedBytesOnTiers has " + usedBytesOnTiers.size() + " tiers");
}
// defensive copy
mTotalBytesOnTiers = new HashMap<>(totalBytesOnTiers);
mUsedBytesOnTiers = new HashMap<>(usedBytesOnTiers);
mCapacityBytes = 0;
for (long bytes : mTotalBytesOnTiers.values()) {
mCapacityBytes += bytes;
}
mUsedBytes = 0;
for (long bytes : mUsedBytesOnTiers.values()) {
mUsedBytes += bytes;
}
Set<Long> removedBlocks;
if (mIsRegistered) {
// This is a re-register of an existing worker. Assume the new block ownership data is more
// up-to-date and update the existing block information.
LOG.info("re-registering an existing workerId: {}", mId);
// Compute the difference between the existing block data, and the new data.
removedBlocks = Sets.difference(mBlocks, blocks);
} else {
removedBlocks = Collections.emptySet();
}
// Set the new block information.
mBlocks = new HashSet<>(blocks);
mIsRegistered = true;
return removedBlocks;
}
Aggregations