/** * Resolve affinity nodes for specified part of file. * * @param info File info to resolve affinity nodes for. * @param start Start position in the file. * @param len File part length to get affinity for. * @return Affinity blocks locations. * @throws GridException If failed. */ public Collection<GridGgfsBlockLocation> affinity(GridGgfsFileInfo info, long start, long len) throws GridException { return affinity(info, start, len, 0); }
/** * Get data block for specified block index. * * @param fileInfo File info. * @param blockIdx Block index. * @return Requested data block or {@code null} if nothing found. * @throws GridException If failed. */ @Nullable protected GridFuture<byte[]> dataBlock(GridGgfsFileInfo fileInfo, long blockIdx) throws GridException { return data.dataBlock(fileInfo, path, blockIdx, secReader); }
data.delete(fileInfo);
assert validTxState(false); assert info.isFile() : "Failed to get affinity (not a file): " + info; assert start >= 0 : "Start position should not be negative: " + start; Collection<GridGgfsBlockLocation> res = new LinkedList<>(); splitBlocks(start, len, maxLen, dataCache.affinity().mapKeyToPrimaryAndBackups( new GridGgfsBlockKey(info.id(), info.affinityKey(), info.evictExclude(), 0)), res); affinity0(info, start, len, maxLen, res); long partEnd = Math.min(end, range.startOffset()); affinity0(info, pos, partEnd - pos, maxLen, res); ", affNodes=" + F.nodeIds(affNodes) + ']'); if (last != null && equal(last.nodeIds(), F.viewReadOnly(affNodes, F.node2id()))) { splitBlocks(last.start(), last.length() + partEnd - pos, maxLen, affNodes, res); splitBlocks(pos, partEnd - pos, maxLen, affNodes, res); affinity0(info, pos, end, maxLen, res);
UUID nodeId = ggfsCtx.data().affinityNode(range.affinityKey()).id(); nodeRanges.addAll(range.split(ggfsCtx.data().groupBlockSize()));
ggfsCtx.data().cleanBlocks(fileInfo, range, true); ggfsCtx.data().spreadBlocks(fileInfo, range); ggfsCtx.data().cleanBlocks(fileInfo, range, true); ggfsCtx.data().cleanBlocks(fileInfo, range, false); ggfsCtx.data().cleanBlocks(fileInfo, range, true);
data.writeClose(fileInfo); data.delete(fileInfo); // Safety to ensure that all data blocks are deleted. data.delete(fileInfo);
/** * Tries to remove blocks affected by fragmentizer. If {@code cleanNonColocated} is {@code true}, will remove * non-colocated blocks as well. * * @param fileInfo File info to clean up. * @param range Range to clean up. * @param cleanNonColocated {@code True} if all blocks should be cleaned. */ public void cleanBlocks(GridGgfsFileInfo fileInfo, GridGgfsFileAffinityRange range, boolean cleanNonColocated) { long startIdx = range.startOffset() / fileInfo.blockSize(); long endIdx = range.endOffset() / fileInfo.blockSize(); if (log.isDebugEnabled()) log.debug("Cleaning blocks [fileInfo=" + fileInfo + ", range=" + range + ", cleanNonColocated=" + cleanNonColocated + ", startIdx=" + startIdx + ", endIdx=" + endIdx + ']'); try { try (GridDataLoader<GridGgfsBlockKey, byte[]> ldr = dataLoader()) { for (long idx = startIdx; idx <= endIdx; idx++) { ldr.removeData(new GridGgfsBlockKey(fileInfo.id(), range.affinityKey(), fileInfo.evictExclude(), idx)); if (cleanNonColocated) ldr.removeData(new GridGgfsBlockKey(fileInfo.id(), null, fileInfo.evictExclude(), idx)); } } } catch (GridException e) { log.error("Failed to clean up file range [fileInfo=" + fileInfo + ", range=" + range + ']', e); } }
final GridGgfsBlocksMessage msg = new GridGgfsBlocksMessage(fileId, batchId, blocks); callGgfsLocalSafe(new GridPlainCallable<Object>() { @Override @Nullable public Object call() throws Exception { try { callGgfsLocalSafe(new GridPlainCallable<Object>() { @Override @Nullable public Object call() throws Exception { storeBlocksAsync(blocks).listenAsync(new CI1<GridFuture<?>>() {
new GridGgfsConfiguration(cfg), new GridGgfsMetaManager(), new GridGgfsDataManager(), new GridGgfsServerManager(), new GridGgfsFragmentizerManager());
final GridGgfsBlockKey key = blockKey(blockIdx, fileInfo);
assert validTxState(false); assert info.isFile() : "Failed to get affinity (not a file): " + info; assert start >= 0 : "Start position should not be negative: " + start; Collection<GridGgfsBlockLocation> res = new LinkedList<>(); splitBlocks(start, len, maxLen, dataCache.affinity().mapKeyToPrimaryAndBackups( new GridGgfsBlockKey(info.id(), info.affinityKey(), info.evictExclude(), 0)), res); affinity0(info, start, len, maxLen, res); long partEnd = Math.min(end, range.startOffset()); affinity0(info, pos, partEnd - pos, maxLen, res); ", affNodes=" + F.nodeIds(affNodes) + ']'); if (last != null && equal(last.nodeIds(), F.viewReadOnly(affNodes, F.node2id()))) { splitBlocks(last.start(), last.length() + partEnd - pos, maxLen, affNodes, res); splitBlocks(pos, partEnd - pos, maxLen, affNodes, res); affinity0(info, pos, end, maxLen, res);
UUID nodeId = ggfsCtx.data().affinityNode(range.affinityKey()).id(); nodeRanges.addAll(range.split(ggfsCtx.data().groupBlockSize()));
ggfsCtx.data().cleanBlocks(fileInfo, range, true); ggfsCtx.data().spreadBlocks(fileInfo, range); ggfsCtx.data().cleanBlocks(fileInfo, range, true); ggfsCtx.data().cleanBlocks(fileInfo, range, false); ggfsCtx.data().cleanBlocks(fileInfo, range, true);
data.writeClose(fileInfo); data.delete(fileInfo); // Safety to ensure that all data blocks are deleted. data.delete(fileInfo);
/** * Tries to remove blocks affected by fragmentizer. If {@code cleanNonColocated} is {@code true}, will remove * non-colocated blocks as well. * * @param fileInfo File info to clean up. * @param range Range to clean up. * @param cleanNonColocated {@code True} if all blocks should be cleaned. */ public void cleanBlocks(GridGgfsFileInfo fileInfo, GridGgfsFileAffinityRange range, boolean cleanNonColocated) { long startIdx = range.startOffset() / fileInfo.blockSize(); long endIdx = range.endOffset() / fileInfo.blockSize(); if (log.isDebugEnabled()) log.debug("Cleaning blocks [fileInfo=" + fileInfo + ", range=" + range + ", cleanNonColocated=" + cleanNonColocated + ", startIdx=" + startIdx + ", endIdx=" + endIdx + ']'); try { try (GridDataLoader<GridGgfsBlockKey, byte[]> ldr = dataLoader()) { for (long idx = startIdx; idx <= endIdx; idx++) { ldr.removeData(new GridGgfsBlockKey(fileInfo.id(), range.affinityKey(), fileInfo.evictExclude(), idx)); if (cleanNonColocated) ldr.removeData(new GridGgfsBlockKey(fileInfo.id(), null, fileInfo.evictExclude(), idx)); } } } catch (GridException e) { log.error("Failed to clean up file range [fileInfo=" + fileInfo + ", range=" + range + ']', e); } }
final GridGgfsBlocksMessage msg = new GridGgfsBlocksMessage(fileId, batchId, blocks); callGgfsLocalSafe(new GridPlainCallable<Object>() { @Override @Nullable public Object call() throws Exception { try { callGgfsLocalSafe(new GridPlainCallable<Object>() { @Override @Nullable public Object call() throws Exception { storeBlocksAsync(blocks).listenAsync(new CI1<GridFuture<?>>() {
new GridGgfsConfiguration(cfg), new GridGgfsMetaManager(), new GridGgfsDataManager(), new GridGgfsServerManager(), new GridGgfsFragmentizerManager());
final GridGgfsBlockKey key = blockKey(blockIdx, fileInfo);
data.delete(fileInfo);