/** * Constructs file info. * * @param id ID or {@code null} to generate it automatically. * @param blockSize Block size. * @param len Size of a file. * @param affKey Affinity key for data blocks. * @param props File properties. * @param fileMap File map. * @param lockId Lock ID. * @param accessTime Last access time. * @param modificationTime Last modification time. * @param evictExclude Evict exclude flag. */ IgfsFileInfo(IgniteUuid id, int blockSize, long len, @Nullable IgniteUuid affKey, @Nullable Map<String, String> props, @Nullable IgfsFileMap fileMap, @Nullable IgniteUuid lockId, long accessTime, long modificationTime, boolean evictExclude) { super(id, props, accessTime, modificationTime); this.len = len; this.blockSize = blockSize; this.affKey = affKey; if (fileMap == null) fileMap = new IgfsFileMap(); this.fileMap = fileMap; this.lockId = lockId; this.evictExclude = evictExclude; }
/** {@inheritDoc} */ @Override public IgfsEntryInfo process(MutableEntry<IgniteUuid, IgfsEntryInfo> entry, Object... args) throws EntryProcessorException { IgfsEntryInfo oldInfo = entry.getValue(); IgfsFileMap newMap = new IgfsFileMap(oldInfo.fileMap()); newMap.updateRangeStatus(range, status); IgfsEntryInfo newInfo = oldInfo.fileMap(newMap); entry.setValue(newInfo); return newInfo; }
/** {@inheritDoc} */ @Override public IgfsEntryInfo process(MutableEntry<IgniteUuid, IgfsEntryInfo> entry, Object... args) throws EntryProcessorException { IgfsEntryInfo oldInfo = entry.getValue(); IgfsFileMap newMap = new IgfsFileMap(oldInfo.fileMap()); newMap.deleteRange(range); IgfsEntryInfo newInfo = oldInfo.fileMap(newMap); entry.setValue(newInfo); return newInfo; }
/** {@inheritDoc} */ @Override public IgfsEntryInfo process(MutableEntry<IgniteUuid, IgfsEntryInfo> entry, Object... args) throws EntryProcessorException { IgfsEntryInfo oldInfo = entry.getValue(); IgfsFileMap newMap = new IgfsFileMap(oldInfo.fileMap()); newMap.addRange(affRange); IgfsEntryInfo newInfo = oldInfo.length(oldInfo.length() + space).fileMap(newMap); entry.setValue(newInfo); return newInfo; }
/** {@inheritDoc} */ @Override public Void process(MutableEntry<IgniteUuid, IgfsEntryInfo> entry, Object... args) throws EntryProcessorException { IgfsEntryInfo oldInfo = entry.getValue(); assert oldInfo != null; IgfsEntryInfo newInfo = oldInfo.unlock(modificationTime); if (updateSpace) { IgfsFileMap newMap = new IgfsFileMap(newInfo.fileMap()); newMap.addRange(affRange); newInfo = newInfo.length(newInfo.length() + space).fileMap(newMap); } entry.setValue(newInfo); return null; }
/** * @throws Exception If failed. */ @Test public void testAddUpdateAdd() throws Exception { IgfsFileMap map = new IgfsFileMap(); IgniteUuid affKey = IgniteUuid.randomUuid(); map.addRange(new IgfsFileAffinityRange(0, 9, affKey)); map.updateRangeStatus(new IgfsFileAffinityRange(0, 9, affKey), RANGE_STATUS_MOVING); map.addRange(new IgfsFileAffinityRange(10, 19, affKey)); List<IgfsFileAffinityRange> ranges = map.ranges(); assertEquals(2, ranges.size()); assertEquals(RANGE_STATUS_MOVING, ranges.get(0).status()); assertTrue(ranges.get(0).regionEqual(new IgfsFileAffinityRange(0, 9, affKey))); assertEquals(RANGE_STATUS_INITIAL, ranges.get(1).status()); assertTrue(ranges.get(1).regionEqual(new IgfsFileAffinityRange(10, 19, affKey))); }
IgfsFileMap map = new IgfsFileMap();
IgfsFileMap map = new IgfsFileMap();
/** * @throws Exception If failed. */ @Test public void testRanges() throws Exception { IgfsFileMap map = new IgfsFileMap(); IgniteUuid[] affKeys = new IgniteUuid[20]; for (int i = 0; i < affKeys.length; i++) affKeys[i] = IgniteUuid.randomUuid(); int numOfRanges = 0; do { for (int i = 0; i < 2 * numOfRanges + 1; i++) { long off1 = i * 10; long off2 = i * 10 + 5; long off3 = i * 10 + 8; IgniteUuid affKey = i % 2 == 0 ? null : affKeys[i / 2]; assertEquals("For i: " + i, affKey, map.affinityKey(off1, false)); assertEquals("For i: " + i, affKey, map.affinityKey(off2, false)); assertEquals("For i: " + i, affKey, map.affinityKey(off3, false)); } map.addRange(new IgfsFileAffinityRange(10 + 20 * numOfRanges, 19 + 20 * numOfRanges, affKeys[numOfRanges])); numOfRanges++; } while (numOfRanges < 20); }
final IgfsFileMap map = new IgfsFileMap();
/** @throws Exception If failed. */ @Test public void testAffinityFileMap() throws Exception { int blockSize = BLOCK_SIZE; long t = System.currentTimeMillis(); IgfsEntryInfo info = IgfsUtils.createFile(IgniteUuid.randomUuid(), blockSize, 1024 * 1024, null, null, false, null, t, t); IgniteUuid affKey = IgniteUuid.randomUuid(); IgfsFileMap map = new IgfsFileMap(); map.addRange(new IgfsFileAffinityRange(3 * BLOCK_SIZE, 5 * BLOCK_SIZE - 1, affKey)); map.addRange(new IgfsFileAffinityRange(13 * BLOCK_SIZE, 17 * BLOCK_SIZE - 1, affKey)); info = info.fileMap(map); Collection<IgfsBlockLocation> affinity = mgr.affinity(info, 0, info.length()); checkAffinity(blockSize, info, affinity); // Check from middle of range. affinity = mgr.affinity(info, 3 * BLOCK_SIZE + BLOCK_SIZE / 2, info.length()); checkAffinity(blockSize, info, affinity); // Check from middle of last range. affinity = mgr.affinity(info, 14 * BLOCK_SIZE, info.length()); checkAffinity(blockSize, info, affinity); // Check inside one range. affinity = mgr.affinity(info, 14 * BLOCK_SIZE, 2 * BLOCK_SIZE); checkAffinity(blockSize, info, affinity); // Check outside last range. affinity = mgr.affinity(info, 18 * BLOCK_SIZE, info.length()); checkAffinity(blockSize, info, affinity); }
/** * Constructs file info. * * @param id ID or {@code null} to generate it automatically. * @param blockSize Block size. * @param len Size of a file. * @param affKey Affinity key for data blocks. * @param props File properties. * @param fileMap File map. * @param lockId Lock ID. * @param accessTime Last access time. * @param modificationTime Last modification time. * @param evictExclude Evict exclude flag. */ IgfsFileInfo(IgniteUuid id, int blockSize, long len, @Nullable IgniteUuid affKey, @Nullable Map<String, String> props, @Nullable IgfsFileMap fileMap, @Nullable IgniteUuid lockId, long accessTime, long modificationTime, boolean evictExclude) { super(id, props, accessTime, modificationTime); this.len = len; this.blockSize = blockSize; this.affKey = affKey; if (fileMap == null) fileMap = new IgfsFileMap(); this.fileMap = fileMap; this.lockId = lockId; this.evictExclude = evictExclude; }
/** {@inheritDoc} */ @Override public IgfsEntryInfo process(MutableEntry<IgniteUuid, IgfsEntryInfo> entry, Object... args) throws EntryProcessorException { IgfsEntryInfo oldInfo = entry.getValue(); IgfsFileMap newMap = new IgfsFileMap(oldInfo.fileMap()); newMap.deleteRange(range); IgfsEntryInfo newInfo = oldInfo.fileMap(newMap); entry.setValue(newInfo); return newInfo; }
/** {@inheritDoc} */ @Override public IgfsEntryInfo process(MutableEntry<IgniteUuid, IgfsEntryInfo> entry, Object... args) throws EntryProcessorException { IgfsEntryInfo oldInfo = entry.getValue(); IgfsFileMap newMap = new IgfsFileMap(oldInfo.fileMap()); newMap.updateRangeStatus(range, status); IgfsEntryInfo newInfo = oldInfo.fileMap(newMap); entry.setValue(newInfo); return newInfo; }
/** {@inheritDoc} */ @Override public IgfsEntryInfo process(MutableEntry<IgniteUuid, IgfsEntryInfo> entry, Object... args) throws EntryProcessorException { IgfsEntryInfo oldInfo = entry.getValue(); IgfsFileMap newMap = new IgfsFileMap(oldInfo.fileMap()); newMap.addRange(affRange); IgfsEntryInfo newInfo = oldInfo.length(oldInfo.length() + space).fileMap(newMap); entry.setValue(newInfo); return newInfo; }
/** {@inheritDoc} */ @Override public Void process(MutableEntry<IgniteUuid, IgfsEntryInfo> entry, Object... args) throws EntryProcessorException { IgfsEntryInfo oldInfo = entry.getValue(); assert oldInfo != null; IgfsEntryInfo newInfo = oldInfo.unlock(modificationTime); if (updateSpace) { IgfsFileMap newMap = new IgfsFileMap(newInfo.fileMap()); newMap.addRange(affRange); newInfo = newInfo.length(newInfo.length() + space).fileMap(newMap); } entry.setValue(newInfo); return null; }