/** * Updates range status at given position (will split range into two if necessary). * * @param origIdx Original range index. * @param orig Original range at index. * @param update Range being updated. * @param status New status for range. */ private void updateRangeStatus0(int origIdx, GridGgfsFileAffinityRange orig, GridGgfsFileAffinityRange update, int status) { assert F.eq(orig.affinityKey(), update.affinityKey()); assert ranges.get(origIdx) == orig; if (orig.regionEqual(update)) ranges.set(origIdx, new GridGgfsFileAffinityRange(update, status)); else { // If range was expanded, new one should be larger. assert orig.endOffset() > update.endOffset(); ranges.set(origIdx, new GridGgfsFileAffinityRange(update, status)); ranges.add(origIdx + 1, new GridGgfsFileAffinityRange(update.endOffset() + 1, orig.endOffset(), orig.affinityKey())); } }
if (leftRange.less(blockOff)) return null; if (leftRange.belongs(blockOff)) return leftRange.status() != RANGE_STATUS_MOVED ? leftRange.affinityKey() : includeMoved ? leftRange.affinityKey() : null; if (rightRange.greater(blockOff)) return null; if (rightRange.belongs(blockOff)) return rightRange.status() != RANGE_STATUS_MOVED ? rightRange.affinityKey() : includeMoved ? leftRange.affinityKey() : null; if (midRange.belongs(blockOff)) return midRange.status() != RANGE_STATUS_MOVED ? midRange.affinityKey() : includeMoved ? leftRange.affinityKey() : null; if (midRange.less(blockOff)) rightIdx = midIdx; else { assert midRange.greater(blockOff);
/** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) @Override public GridTcpCommunicationMessageAdapter clone() { GridGgfsFileAffinityRange _clone = new GridGgfsFileAffinityRange(); clone0(_clone); return _clone; }
if (locRange == null || locRange.done()) return new GridGgfsBlockKey(fileInfo.id(), null, fileInfo.evictExclude(), block); if (locRange.less(blockStart)) { GridUuid affKey = fileInfo.fileMap().affinityKey(blockStart, false); ggfsCtx.configuration().getFragmentizerLocalWritesRatio()) { locRange.markDone(); if (!locRange.belongs(blockStart)) locRange.expand(blockStart, fileInfo.blockSize()); return new GridGgfsBlockKey(fileInfo.id(), locRange.affinityKey(), fileInfo.evictExclude(), block);
if (range.less(pos)) { long partEnd = Math.min(end, range.startOffset()); if (range.belongs(pos)) { long partEnd = Math.min(range.endOffset() + 1, end); range.affinityKey());
/** * 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); } }
/** * Adds range to the list of already existing ranges. Added range must be located after * the last range in this map. If added range is adjacent to the last range in the map, * added range will be concatenated to the last one. * * @param range Range to add. */ public void addRange(GridGgfsFileAffinityRange range) { if (range == null || range.empty()) return; // We cannot add range in the middle of the file. if (ranges == null) { ranges = new ArrayList<>(); ranges.add(range); return; } assert !ranges.isEmpty(); GridGgfsFileAffinityRange last = ranges.get(ranges.size() - 1); // Ensure that range being added is located to the right of last range in list. assert last.greater(range.startOffset()) : "Cannot add range to middle of map [last=" + last + ", range=" + range + ']'; // Try to concat last and new range. GridGgfsFileAffinityRange concat = last.concat(range); // Simply add range to the end of the list if they are not adjacent. if (concat == null) ranges.add(range); else ranges.set(ranges.size() - 1, concat); }
/** * Tries to concatenate this range with a given one. If ranges are not adjacent, will return {@code null}. * * @param range Range to concatenate with. * @return Concatenation result or {@code null} if ranges are not adjacent. */ @Nullable public GridGgfsFileAffinityRange concat(GridGgfsFileAffinityRange range) { if (endOff + 1 != range.startOff || !F.eq(affKey, range.affKey) || status != RANGE_STATUS_INITIAL) return null; return new GridGgfsFileAffinityRange(startOff, range.endOff, affKey); }
UUID nodeId = ggfsCtx.data().affinityNode(range.affinityKey()).id(); nodeRanges.addAll(range.split(ggfsCtx.data().groupBlockSize()));
if (!commState.putByte(directType())) return false;
if (locRange == null || locRange.done()) return new GridGgfsBlockKey(fileInfo.id(), null, fileInfo.evictExclude(), block); if (locRange.less(blockStart)) { GridUuid affKey = fileInfo.fileMap().affinityKey(blockStart, false); ggfsCtx.configuration().getFragmentizerLocalWritesRatio()) { locRange.markDone(); if (!locRange.belongs(blockStart)) locRange.expand(blockStart, fileInfo.blockSize()); return new GridGgfsBlockKey(fileInfo.id(), locRange.affinityKey(), fileInfo.evictExclude(), block);
if (range.less(pos)) { long partEnd = Math.min(end, range.startOffset()); if (range.belongs(pos)) { long partEnd = Math.min(range.endOffset() + 1, end); range.affinityKey());
/** * 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); } }
/** * Adds range to the list of already existing ranges. Added range must be located after * the last range in this map. If added range is adjacent to the last range in the map, * added range will be concatenated to the last one. * * @param range Range to add. */ public void addRange(GridGgfsFileAffinityRange range) { if (range == null || range.empty()) return; // We cannot add range in the middle of the file. if (ranges == null) { ranges = new ArrayList<>(); ranges.add(range); return; } assert !ranges.isEmpty(); GridGgfsFileAffinityRange last = ranges.get(ranges.size() - 1); // Ensure that range being added is located to the right of last range in list. assert last.greater(range.startOffset()) : "Cannot add range to middle of map [last=" + last + ", range=" + range + ']'; // Try to concat last and new range. GridGgfsFileAffinityRange concat = last.concat(range); // Simply add range to the end of the list if they are not adjacent. if (concat == null) ranges.add(range); else ranges.set(ranges.size() - 1, concat); }
/** * Tries to concatenate this range with a given one. If ranges are not adjacent, will return {@code null}. * * @param range Range to concatenate with. * @return Concatenation result or {@code null} if ranges are not adjacent. */ @Nullable public GridGgfsFileAffinityRange concat(GridGgfsFileAffinityRange range) { if (endOff + 1 != range.startOff || !F.eq(affKey, range.affKey) || status != RANGE_STATUS_INITIAL) return null; return new GridGgfsFileAffinityRange(startOff, range.endOff, affKey); }
UUID nodeId = ggfsCtx.data().affinityNode(range.affinityKey()).id(); nodeRanges.addAll(range.split(ggfsCtx.data().groupBlockSize()));
if (!commState.putByte(directType())) return false;
if (leftRange.less(blockOff)) return null; if (leftRange.belongs(blockOff)) return leftRange.status() != RANGE_STATUS_MOVED ? leftRange.affinityKey() : includeMoved ? leftRange.affinityKey() : null; if (rightRange.greater(blockOff)) return null; if (rightRange.belongs(blockOff)) return rightRange.status() != RANGE_STATUS_MOVED ? rightRange.affinityKey() : includeMoved ? leftRange.affinityKey() : null; if (midRange.belongs(blockOff)) return midRange.status() != RANGE_STATUS_MOVED ? midRange.affinityKey() : includeMoved ? leftRange.affinityKey() : null; if (midRange.less(blockOff)) rightIdx = midIdx; else { assert midRange.greater(blockOff);
long startIdx = range.startOffset() / fileInfo.blockSize(); long endIdx = range.endOffset() / fileInfo.blockSize(); GridGgfsBlockKey colocatedKey = new GridGgfsBlockKey(fileInfo.id(), range.affinityKey(), fileInfo.evictExclude(), idx);
/** * Updates range status at given position (will split range into two if necessary). * * @param origIdx Original range index. * @param orig Original range at index. * @param update Range being updated. * @param status New status for range. */ private void updateRangeStatus0(int origIdx, GridGgfsFileAffinityRange orig, GridGgfsFileAffinityRange update, int status) { assert F.eq(orig.affinityKey(), update.affinityKey()); assert ranges.get(origIdx) == orig; if (orig.regionEqual(update)) { ranges.set(origIdx, new GridGgfsFileAffinityRange(update, status)); } else { // If range was expanded, new one should be larger. assert orig.endOffset() > update.endOffset(); ranges.set(origIdx, new GridGgfsFileAffinityRange(update, status)); ranges.add(origIdx + 1, new GridGgfsFileAffinityRange(update.endOffset() + 1, orig.endOffset(), orig.affinityKey())); } }