return leftRange.status() != RANGE_STATUS_MOVED ? leftRange.affinityKey() : includeMoved ? leftRange.affinityKey() : null; return rightRange.status() != RANGE_STATUS_MOVED ? rightRange.affinityKey() : includeMoved ? leftRange.affinityKey() : null; return midRange.status() != RANGE_STATUS_MOVED ? midRange.affinityKey() : includeMoved ? leftRange.affinityKey() : null;
/** * 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, IgfsFileAffinityRange orig, IgfsFileAffinityRange update, int status) { assert F.eq(orig.affinityKey(), update.affinityKey()); assert ranges.get(origIdx) == orig; if (orig.regionEqual(update)) ranges.set(origIdx, new IgfsFileAffinityRange(update, status)); else { // If range was expanded, new one should be larger. assert orig.endOffset() > update.endOffset(); ranges.set(origIdx, new IgfsFileAffinityRange(update, status)); ranges.add(origIdx + 1, new IgfsFileAffinityRange(update.endOffset() + 1, orig.endOffset(), orig.affinityKey())); } }
UUID nodeId = igfsCtx.data().affinityNode(range.affinityKey()).id();
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(IgfsEntryInfo fileInfo, IgfsFileAffinityRange 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 (IgniteDataStreamer<IgfsBlockKey, byte[]> ldr = dataStreamer()) { for (long idx = startIdx; idx <= endIdx; idx++) { ldr.removeData(new IgfsBlockKey(fileInfo.id(), range.affinityKey(), fileInfo.evictExclude(), idx)); if (cleanNonColocated) ldr.removeData(new IgfsBlockKey(fileInfo.id(), null, fileInfo.evictExclude(), idx)); } } } catch (IgniteException e) { log.error("Failed to clean up file range [fileInfo=" + fileInfo + ", range=" + range + ']', e); } }
/** * Creates block key based on block ID, file info and local affinity range. * * @param block Block ID. * @param fileInfo File info being written. * @param locRange Local affinity range to update. * @return Block key. */ private IgfsBlockKey createBlockKey( long block, IgfsEntryInfo fileInfo, IgfsFileAffinityRange locRange ) { // If affinityKey is present, return block key as is. if (fileInfo.affinityKey() != null) return new IgfsBlockKey(fileInfo.id(), fileInfo.affinityKey(), fileInfo.evictExclude(), block); // If range is done, no colocated writes are attempted. if (locRange == null) return new IgfsBlockKey(fileInfo.id(), null, fileInfo.evictExclude(), block); long blockStart = block * fileInfo.blockSize(); // If block does not belong to new range, return old affinity key. if (locRange.less(blockStart)) { IgniteUuid affKey = fileInfo.fileMap().affinityKey(blockStart, false); return new IgfsBlockKey(fileInfo.id(), affKey, fileInfo.evictExclude(), block); } if (!locRange.belongs(blockStart)) locRange.expand(blockStart, fileInfo.blockSize()); return new IgfsBlockKey(fileInfo.id(), locRange.affinityKey(), fileInfo.evictExclude(), block); }
IgfsBlockKey colocatedKey = new IgfsBlockKey(fileInfo.id(), range.affinityKey(), fileInfo.evictExclude(), idx);
return leftRange.status() != RANGE_STATUS_MOVED ? leftRange.affinityKey() : includeMoved ? leftRange.affinityKey() : null; return rightRange.status() != RANGE_STATUS_MOVED ? rightRange.affinityKey() : includeMoved ? leftRange.affinityKey() : null; return midRange.status() != RANGE_STATUS_MOVED ? midRange.affinityKey() : includeMoved ? leftRange.affinityKey() : null;
/** * 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, IgfsFileAffinityRange orig, IgfsFileAffinityRange update, int status) { assert F.eq(orig.affinityKey(), update.affinityKey()); assert ranges.get(origIdx) == orig; if (orig.regionEqual(update)) ranges.set(origIdx, new IgfsFileAffinityRange(update, status)); else { // If range was expanded, new one should be larger. assert orig.endOffset() > update.endOffset(); ranges.set(origIdx, new IgfsFileAffinityRange(update, status)); ranges.add(origIdx + 1, new IgfsFileAffinityRange(update.endOffset() + 1, orig.endOffset(), orig.affinityKey())); } }
UUID nodeId = igfsCtx.data().affinityNode(range.affinityKey()).id();
/** * 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(IgfsEntryInfo fileInfo, IgfsFileAffinityRange 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 (IgniteDataStreamer<IgfsBlockKey, byte[]> ldr = dataStreamer()) { for (long idx = startIdx; idx <= endIdx; idx++) { ldr.removeData(new IgfsBlockKey(fileInfo.id(), range.affinityKey(), fileInfo.evictExclude(), idx)); if (cleanNonColocated) ldr.removeData(new IgfsBlockKey(fileInfo.id(), null, fileInfo.evictExclude(), idx)); } } } catch (IgniteException e) { log.error("Failed to clean up file range [fileInfo=" + fileInfo + ", range=" + range + ']', e); } }
/** * Creates block key based on block ID, file info and local affinity range. * * @param block Block ID. * @param fileInfo File info being written. * @param locRange Local affinity range to update. * @return Block key. */ private IgfsBlockKey createBlockKey( long block, IgfsEntryInfo fileInfo, IgfsFileAffinityRange locRange ) { // If affinityKey is present, return block key as is. if (fileInfo.affinityKey() != null) return new IgfsBlockKey(fileInfo.id(), fileInfo.affinityKey(), fileInfo.evictExclude(), block); // If range is done, no colocated writes are attempted. if (locRange == null) return new IgfsBlockKey(fileInfo.id(), null, fileInfo.evictExclude(), block); long blockStart = block * fileInfo.blockSize(); // If block does not belong to new range, return old affinity key. if (locRange.less(blockStart)) { IgniteUuid affKey = fileInfo.fileMap().affinityKey(blockStart, false); return new IgfsBlockKey(fileInfo.id(), affKey, fileInfo.evictExclude(), block); } if (!locRange.belongs(blockStart)) locRange.expand(blockStart, fileInfo.blockSize()); return new IgfsBlockKey(fileInfo.id(), locRange.affinityKey(), fileInfo.evictExclude(), block); }
IgfsBlockKey colocatedKey = new IgfsBlockKey(fileInfo.id(), range.affinityKey(), fileInfo.evictExclude(), idx);