/** {@inheritDoc} */ @Override public synchronized int available() throws IOException { long l = fileInfo.length() - pos; if (l < 0) return 0; if (l > Integer.MAX_VALUE) return Integer.MAX_VALUE; return (int)l; }
/** {@inheritDoc} */ @Override public synchronized int available() throws IOException { long l = fileInfo.length() - pos; if (l < 0) return 0; if (l > Integer.MAX_VALUE) return Integer.MAX_VALUE; return (int)l; }
/** {@inheritDoc} */ @Override public long length() { return fileInfo().length(); }
/** {@inheritDoc} */ @Override public long length() { return fileInfo().length(); }
/** {@inheritDoc} */ @Override protected synchronized void storeDataBlock(ByteBuffer block) throws GridException, IOException { int writeLen = block.remaining(); preStoreDataBlocks(null, writeLen); int blockSize = fileInfo.blockSize(); // If data length is not enough to fill full block, fill the remainder and return. if (remainderDataLen + writeLen < blockSize) { if (remainder == null) remainder = new byte[blockSize]; else if (remainder.length != blockSize) { assert remainderDataLen == remainder.length; byte[] allocated = new byte[blockSize]; U.arrayCopy(remainder, 0, allocated, 0, remainder.length); remainder = allocated; } block.get(remainder, remainderDataLen, writeLen); remainderDataLen += writeLen; } else { remainder = data.storeDataBlocks(fileInfo, fileInfo.length() + space, remainder, remainderDataLen, block, false, streamRange, batch); remainderDataLen = remainder == null ? 0 : remainder.length; } }
/** * Constructs directory info. * * @param path Path. */ public GridGgfsFileImpl(GridGgfsPath path, GridGgfsFileInfo info, long globalGrpBlockSize) { A.notNull(path, "path"); A.notNull(info, "info"); this.path = path; fileId = info.id(); 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(); }
/** * Constructs directory info. * * @param path Path. */ public GridGgfsFileImpl(GridGgfsPath path, GridGgfsFileInfo info, long globalGrpBlockSize) { A.notNull(path, "path"); A.notNull(info, "info"); this.path = path; fileId = info.id(); 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(); }
/** {@inheritDoc} */ @Override protected synchronized void storeDataBlocks(DataInput in, int len) throws GridException, IOException { preStoreDataBlocks(in, len); int blockSize = fileInfo.blockSize(); // If data length is not enough to fill full block, fill the remainder and return. if (remainderDataLen + len < blockSize) { if (remainder == null) remainder = new byte[blockSize]; else if (remainder.length != blockSize) { assert remainderDataLen == remainder.length; byte[] allocated = new byte[blockSize]; U.arrayCopy(remainder, 0, allocated, 0, remainder.length); remainder = allocated; } in.readFully(remainder, remainderDataLen, len); remainderDataLen += len; } else { remainder = data.storeDataBlocks(fileInfo, fileInfo.length() + space, remainder, remainderDataLen, in, len, false, streamRange, batch); remainderDataLen = remainder == null ? 0 : remainder.length; } }
/** {@inheritDoc} */ @Override protected synchronized void storeDataBlocks(DataInput in, int len) throws GridException, IOException { preStoreDataBlocks(in, len); int blockSize = fileInfo.blockSize(); // If data length is not enough to fill full block, fill the remainder and return. if (remainderDataLen + len < blockSize) { if (remainder == null) remainder = new byte[blockSize]; else if (remainder.length != blockSize) { assert remainderDataLen == remainder.length; byte[] allocated = new byte[blockSize]; U.arrayCopy(remainder, 0, allocated, 0, remainder.length); remainder = allocated; } in.readFully(remainder, remainderDataLen, len); remainderDataLen += len; } else { remainder = data.storeDataBlocks(fileInfo, fileInfo.length() + space, remainder, remainderDataLen, in, len, false, streamRange, batch); remainderDataLen = remainder == null ? 0 : remainder.length; } }
/** {@inheritDoc} */ @Override public GridGgfsFileInfo apply(GridGgfsFileInfo oldInfo) { GridGgfsFileMap oldMap = oldInfo.fileMap(); GridGgfsFileMap newMap = new GridGgfsFileMap(oldMap); newMap.addRange(range); // Update file length. GridGgfsFileInfo updated = new GridGgfsFileInfo(oldInfo, oldInfo.length() + space); updated.fileMap(newMap); return updated; }
/** {@inheritDoc} */ @Override public GridGgfsFileInfo apply(GridGgfsFileInfo oldInfo) { GridGgfsFileMap oldMap = oldInfo.fileMap(); GridGgfsFileMap newMap = new GridGgfsFileMap(oldMap); newMap.addRange(range); // Update file length. GridGgfsFileInfo updated = new GridGgfsFileInfo(oldInfo, oldInfo.length() + space); updated.fileMap(newMap); return updated; }
/** * 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 GridGgfsFileAffinityRange initialStreamRange(GridGgfsFileInfo fileInfo) { if (!ggfsCtx.configuration().isFragmentizerEnabled()) return null; if (!Boolean.parseBoolean(fileInfo.properties().get(GridGgfs.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; GridGgfsFileMap map = fileInfo.fileMap(); GridUuid prevAffKey = map == null ? null : map.affinityKey(lastBlockOff, false); GridUuid affKey = data.nextAffinityKey(prevAffKey); return affKey == null ? null : new GridGgfsFileAffinityRange(off, off, affKey); }
/** * @param fileInfo File info to construct listing entry from. */ public GridGgfsListingEntry(GridGgfsFileInfo fileInfo) { fileId = fileInfo.id(); affKey = fileInfo.affinityKey(); if (fileInfo.isFile()) { blockSize = fileInfo.blockSize(); len = fileInfo.length(); } props = fileInfo.properties(); accessTime = fileInfo.accessTime(); modificationTime = fileInfo.modificationTime(); }
/** * @param fileInfo File info to construct listing entry from. */ public GridGgfsListingEntry(GridGgfsFileInfo fileInfo) { fileId = fileInfo.id(); affKey = fileInfo.affinityKey(); if (fileInfo.isFile()) { blockSize = fileInfo.blockSize(); len = fileInfo.length(); } props = fileInfo.properties(); accessTime = fileInfo.accessTime(); modificationTime = fileInfo.modificationTime(); }
@Override public GridGgfsFileInfo applyx(GridGgfsFileInfo info) throws GridException { GridGgfsFileMap map = new GridGgfsFileMap(info.fileMap()); map.deleteRange(range); if (log.isDebugEnabled()) log.debug("Deleted range from file map [fileId=" + info.id() + ", range=" + range + ", oldMap=" + info.fileMap() + ", newMap=" + map + ']'); GridGgfsFileInfo updated = new GridGgfsFileInfo(info, info.length()); updated.fileMap(map); return updated; } };
@Override public GridGgfsFileInfo applyx(GridGgfsFileInfo info) throws GridException { GridGgfsFileMap map = new GridGgfsFileMap(info.fileMap()); map.updateRangeStatus(range, status); if (log.isDebugEnabled()) log.debug("Updated file map for range [fileId=" + info.id() + ", range=" + range + ", status=" + status + ", oldMap=" + info.fileMap() + ", newMap=" + map + ']'); GridGgfsFileInfo updated = new GridGgfsFileInfo(info, info.length()); updated.fileMap(map); return updated; } };
@Override public GridGgfsFileInfo applyx(GridGgfsFileInfo info) throws GridException { GridGgfsFileMap map = new GridGgfsFileMap(info.fileMap()); map.deleteRange(range); if (log.isDebugEnabled()) log.debug("Deleted range from file map [fileId=" + info.id() + ", range=" + range + ", oldMap=" + info.fileMap() + ", newMap=" + map + ']'); GridGgfsFileInfo updated = new GridGgfsFileInfo(info, info.length()); updated.fileMap(map); return updated; } };
@Override public GridGgfsFileInfo applyx(GridGgfsFileInfo info) throws GridException { GridGgfsFileMap map = new GridGgfsFileMap(info.fileMap()); map.updateRangeStatus(range, status); if (log.isDebugEnabled()) log.debug("Updated file map for range [fileId=" + info.id() + ", range=" + range + ", status=" + status + ", oldMap=" + info.fileMap() + ", newMap=" + map + ']'); GridGgfsFileInfo updated = new GridGgfsFileInfo(info, info.length()); updated.fileMap(map); return updated; } };
/** * Calculates size of directory or file for given ID. * * @param fileId File ID. * @param sum Summary object that will collect information. * @throws GridException If failed. */ private void summary0(GridUuid fileId, GridGgfsPathSummary sum) throws GridException { assert sum != null; GridGgfsFileInfo info = meta.info(fileId); if (info != null) { if (info.isDirectory()) { if (!ROOT_ID.equals(info.id())) sum.directoriesCount(sum.directoriesCount() + 1); for (GridGgfsListingEntry entry : info.listing().values()) summary0(entry.fileId(), sum); } else { sum.filesCount(sum.filesCount() + 1); sum.totalLength(sum.totalLength() + info.length()); } } }
/** * Calculates size of directory or file for given ID. * * @param fileId File ID. * @param sum Summary object that will collect information. * @throws GridException If failed. */ private void summary0(GridUuid fileId, GridGgfsPathSummary sum) throws GridException { assert sum != null; GridGgfsFileInfo info = meta.info(fileId); if (info != null) { if (info.isDirectory()) { if (!ROOT_ID.equals(info.id())) sum.directoriesCount(sum.directoriesCount() + 1); for (GridGgfsListingEntry entry : info.listing().values()) summary0(entry.fileId(), sum); } else { sum.filesCount(sum.filesCount() + 1); sum.totalLength(sum.totalLength() + info.length()); } } }