/** * @return Length of file. */ private long length() { return fileInfo.length(); }
/** {@inheritDoc} */ @Override protected int optimizeBufferSize(int bufSize) { assert bufSize > 0; if (fileInfo == null) return bufSize; int blockSize = fileInfo.blockSize(); if (blockSize <= 0) return bufSize; if (bufSize <= blockSize) // Optimize minimum buffer size to be equal file's block size. return blockSize; int maxBufSize = blockSize * MAX_BLOCKS_CNT; if (bufSize > maxBufSize) // There is no profit or optimization from larger buffers. return maxBufSize; if (fileInfo.length() == 0) // Make buffer size multiple of block size (optimized for new files). return bufSize / blockSize * blockSize; return bufSize; }
/** {@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; }
@Override public Object call() throws Exception { IgfsFileAffinityRange range = new IgfsFileAffinityRange(); mgr.storeDataBlocks(reserved, reserved.length(), null, 0, ByteBuffer.wrap(data), false, range, null); return null; } }, IgfsException.class, msg);
/** * Constructs directory info. * * @param path Path. * @param info Entry info. * @param globalGrpBlockSize Global group block size. */ public IgfsFileImpl(IgfsPath path, IgfsEntryInfo info, long globalGrpBlockSize) { A.notNull(path, "path"); A.notNull(info, "info"); this.path = path; fileId = info.id(); flags = IgfsUtils.flags(info.isDirectory(), info.isFile()); if (info.isFile()) { blockSize = info.blockSize(); len = info.length(); grpBlockSize = info.affinityKey() == null ? globalGrpBlockSize : info.length() == 0 ? globalGrpBlockSize : info.length(); } props = info.properties(); if (props == null) props = Collections.emptyMap(); accessTime = info.accessTime(); modificationTime = info.modificationTime(); }
/** * Gets initial affinity range. This range will have 0 length and will start from first * non-occupied file block. * * @param fileInfo File info to build initial range for. * @return Affinity range. */ private IgfsFileAffinityRange initialStreamRange(IgfsEntryInfo fileInfo) { if (!igfsCtx.configuration().isFragmentizerEnabled()) return null; if (!Boolean.parseBoolean(fileInfo.properties().get(IgfsUtils.PROP_PREFER_LOCAL_WRITES))) return null; int blockSize = fileInfo.blockSize(); // Find first non-occupied block offset. long off = ((fileInfo.length() + blockSize - 1) / blockSize) * blockSize; // Need to get last affinity key and reuse it if we are on the same node. long lastBlockOff = off - fileInfo.blockSize(); if (lastBlockOff < 0) lastBlockOff = 0; IgfsFileMap map = fileInfo.fileMap(); IgniteUuid prevAffKey = map == null ? null : map.affinityKey(lastBlockOff, false); IgniteUuid affKey = igfsCtx.data().nextAffinityKey(prevAffKey); return affKey == null ? null : new IgfsFileAffinityRange(off, off, affKey); }
/** @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); }
long len = info.length(); int blockSize = info.blockSize();
info = info.length(info.length() + data.length + remainder.length); byte[] left = mgr.storeDataBlocks(info, info.length(), remainder, remainder.length, ByteBuffer.wrap(data), false, range, null); info = info.length(info.length() + remainder2.length); byte[] left2 = mgr.storeDataBlocks(info, info.length(), left, left.length, ByteBuffer.wrap(remainder2), false, range, null); for (int pos = 0, block = 0; pos < info.length(); block++) { byte[] stored = mgr.dataBlock(info, path, block, null).get();
info = info.length(info.length() + data.length - 3); info = info.length(info.length() + 3); byte[] remainder = mgr.storeDataBlocks(info, info.length(), null, 0, ByteBuffer.wrap(data), true, range, null); for (int pos = 0, block = 0; pos < info.length(); block++) { byte[] stored = mgr.dataBlock(info, path, block, null).get();
/** @throws Exception If failed. */ @Test public void testAffinity2() 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); Collection<IgfsBlockLocation> affinity = mgr.affinity(info, 0, info.length()); for (IgfsBlockLocation loc : affinity) { info("Going to check IGFS block location: " + loc); int block = (int)(loc.start() / blockSize); int endPos; do { IgfsBlockKey key = new IgfsBlockKey(info.id(), null, false, block); ClusterNode affNode = grid(0).affinity(grid(0).igfsx("igfs").configuration() .getDataCacheConfiguration().getName()).mapKeyToNode(key); assertTrue("Failed to find node in affinity [dataMgr=" + loc.nodeIds() + ", nodeId=" + affNode.id() + ", block=" + block + ']', loc.nodeIds().contains(affNode.id())); endPos = (block + 1) * blockSize; block++; } while (endPos < loc.start() + loc.length()); } }
/** * @return Length of file. */ private long length() { return fileInfo.length(); }
/** {@inheritDoc} */ @Override protected int optimizeBufferSize(int bufSize) { assert bufSize > 0; if (fileInfo == null) return bufSize; int blockSize = fileInfo.blockSize(); if (blockSize <= 0) return bufSize; if (bufSize <= blockSize) // Optimize minimum buffer size to be equal file's block size. return blockSize; int maxBufSize = blockSize * MAX_BLOCKS_CNT; if (bufSize > maxBufSize) // There is no profit or optimization from larger buffers. return maxBufSize; if (fileInfo.length() == 0) // Make buffer size multiple of block size (optimized for new files). return bufSize / blockSize * blockSize; return bufSize; }
/** {@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; }
/** * Constructs directory info. * * @param path Path. * @param info Entry info. * @param globalGrpBlockSize Global group block size. */ public IgfsFileImpl(IgfsPath path, IgfsEntryInfo info, long globalGrpBlockSize) { A.notNull(path, "path"); A.notNull(info, "info"); this.path = path; fileId = info.id(); flags = IgfsUtils.flags(info.isDirectory(), info.isFile()); if (info.isFile()) { blockSize = info.blockSize(); len = info.length(); grpBlockSize = info.affinityKey() == null ? globalGrpBlockSize : info.length() == 0 ? globalGrpBlockSize : info.length(); } props = info.properties(); if (props == null) props = Collections.emptyMap(); accessTime = info.accessTime(); modificationTime = info.modificationTime(); }
/** * Gets initial affinity range. This range will have 0 length and will start from first * non-occupied file block. * * @param fileInfo File info to build initial range for. * @return Affinity range. */ private IgfsFileAffinityRange initialStreamRange(IgfsEntryInfo fileInfo) { if (!igfsCtx.configuration().isFragmentizerEnabled()) return null; if (!Boolean.parseBoolean(fileInfo.properties().get(IgfsUtils.PROP_PREFER_LOCAL_WRITES))) return null; int blockSize = fileInfo.blockSize(); // Find first non-occupied block offset. long off = ((fileInfo.length() + blockSize - 1) / blockSize) * blockSize; // Need to get last affinity key and reuse it if we are on the same node. long lastBlockOff = off - fileInfo.blockSize(); if (lastBlockOff < 0) lastBlockOff = 0; IgfsFileMap map = fileInfo.fileMap(); IgniteUuid prevAffKey = map == null ? null : map.affinityKey(lastBlockOff, false); IgniteUuid affKey = igfsCtx.data().nextAffinityKey(prevAffKey); return affKey == null ? null : new IgfsFileAffinityRange(off, off, affKey); }