/** * Returns the number of blocks the file has. * * @return the number of blocks * @throws IOException if the underlying file does not exist or its metadata is corrupted */ public int getNumberOfBlocks() throws IOException { return getUnCachedFileStatus().getBlockIds().size(); }
public UiFileInfo(FileInfo fileInfo) { mId = fileInfo.getFileId(); mName = fileInfo.getName(); mAbsolutePath = fileInfo.getPath(); mBlockSizeBytes = fileInfo.getBlockSizeBytes(); mSize = fileInfo.getLength(); mCreationTimeMs = fileInfo.getCreationTimeMs(); mLastModificationTimeMs = fileInfo.getLastModificationTimeMs(); mInMemory = (100 == fileInfo.inMemoryPercentage); mInMemoryPercent = fileInfo.getInMemoryPercentage(); mIsDirectory = fileInfo.isFolder; mIsPinned = fileInfo.isPinned; mFileLocations = new ArrayList<String>(); for (int i = 0; i < StorageLevelAlias.SIZE; i ++) { mBlocksOnTier.add(new ArrayList<UiBlockInfo>()); } }
/** * Creates a new file input stream. * * @param info the file information * @param options the client options */ public FileInStream(FileInfo info, InStreamOptions options) { mFileInfo = info; mBlockSize = info.getBlockSizeBytes(); mFileLength = info.getLength(); mContext = FileSystemContext.INSTANCE; mTachyonStorageType = options.getTachyonStorageType(); mShouldCacheCurrentBlock = mTachyonStorageType.isStore(); mClosed = false; }
/** * Displays information for all directories and files directly under the path specified in argv. * * @param path The TachyonURI path as the input of the command * @return 0 if command is successful, -1 if an error occurred * @throws IOException */ public int ls(TachyonURI path) throws IOException { List<FileInfo> files = listStatusSortedByIncreasingCreationTime(path); String format = "%-10s%-25s%-15s%-5s%n"; for (FileInfo file : files) { String inMemory = ""; if (!file.isFolder) { if (100 == file.inMemoryPercentage) { inMemory = "In Memory"; } else { inMemory = "Not In Memory"; } } System.out.format(format, FormatUtils.getSizeFromBytes(file.getLength()), convertMsToDate(file.getCreationTimeMs()), inMemory, file.getPath()); } return 0; }
@Override public FileStatus[] listStatus(Path path) throws IOException { TachyonURI tPath = new TachyonURI(Utils.getPathWithoutScheme(path)); Path hdfsPath = Utils.getHDFSPath(tPath, mUnderFSAddress); LOG.info("listStatus(" + path + "): HDFS Path: " + hdfsPath); if (mStatistics != null) { mStatistics.incrementReadOps(1); } if (!mTFS.exist(tPath)) { throw new FileNotFoundException("File does not exist: " + path); } List<FileInfo> files = mTFS.listStatus(tPath); FileStatus[] ret = new FileStatus[files.size()]; for (int k = 0; k < files.size(); k ++) { FileInfo info = files.get(k); // TODO(hy): Replicate 3 with the number of disk replications. ret[k] = new FileStatus(info.getLength(), info.isFolder, 3, info.getBlockSizeBytes(), info.getCreationTimeMs(), info.getCreationTimeMs(), null, null, null, new Path( mTachyonHeader + info.getPath())); } return ret; }
/** * Returns the path of this file in the Tachyon file system. * * @return the path * @throws IOException if the underlying file does not exist or its metadata is corrupted */ public String getPath() throws IOException { return getUnCachedFileStatus().getPath(); }
/** * Calculates the size of a path (file or folder) specified by a TachyonURI. * * @param tachyonFS A TachyonFileSystem * @param path A TachyonURI denoting the path * @return total size of the specified path in byte * @throws IOException */ private long getFileOrFolderSize(TachyonFileSystem tachyonFS, TachyonURI path) throws IOException { long sizeInBytes = 0; List<FileInfo> files; try { TachyonFile inputFile = tachyonFS.open(path); files = tachyonFS.listStatus(inputFile); } catch (TachyonException e) { throw new IOException(e.getMessage()); } for (FileInfo file : files) { if (file.isFolder) { TachyonURI subFolder = new TachyonURI(file.getPath()); sizeInBytes += getFileOrFolderSize(tachyonFS, subFolder); } else { sizeInBytes += file.getLength(); } } return sizeInBytes; }
Collections.sort(files); for (FileInfo file : files) { TachyonURI newPath = new TachyonURI(file.getPath()); if (loadPath(tachyonClient, newPath) == -1) { return -1; if (fInfo.getInMemoryPercentage() == 100) {
/** * @return the file size in bytes * @throws IOException if the underlying file does not exist or its metadata is corrupted */ public long length() throws IOException { return getUnCachedFileStatus().getLength(); }
/** * Returns the block size of this file. * * @return the block size in bytes * @throws IOException if the underlying file does not exist or its metadata is corrupted */ public long getBlockSizeByte() throws IOException { return getCachedFileStatus().getBlockSizeBytes(); }
/** * Return whether the file is in memory or not. Note that a file may be partly in memory. This * value is true only if the file is fully in memory. * * @return true if the file is fully in memory, false otherwise * @throws IOException if the underlying file does not exist or its metadata is corrupted */ public boolean isInMemory() throws IOException { return getUnCachedFileStatus().getInMemoryPercentage() == 100; }
new UnderStoreFileInStream(blockStart, mBlockSize, mFileInfo.getUfsPath()); mShouldCacheCurrentBlock = mTachyonStorageType.isStore();
/** * Returns the creation time of this file * * @return the creation time, in milliseconds * @throws IOException if the underlying file does not exist or its metadata is corrupted */ public long getCreationTimeMs() throws IOException { return getCachedFileStatus().getCreationTimeMs(); }
/** * Get file id by the path. It will check if the path exists. * * @param path the path in Tachyon file system * @return the file id if exists, INVALID_FILE_ID otherwise */ public synchronized long getFileId(TachyonURI path) { try { FileInfo fileInfo = getFileStatus(IdUtils.INVALID_FILE_ID, path, false); return fileInfo == null ? -IdUtils.INVALID_FILE_ID : fileInfo.getFileId(); } catch (IOException e) { return IdUtils.INVALID_FILE_ID; } }
/** * Displays information for all directories and files under the path specified in argv * recursively. * * @param path The TachyonURI path as the input of the command * @return 0 if command is successful, -1 if an error occurred * @throws IOException */ public int lsr(TachyonURI path) throws IOException { List<FileInfo> files = listStatusSortedByIncreasingCreationTime(path); String format = "%-10s%-25s%-15s%-5s%n"; for (FileInfo file : files) { String inMemory = ""; if (!file.isFolder) { if (100 == file.inMemoryPercentage) { inMemory = "In Memory"; } else { inMemory = "Not In Memory"; } } System.out.format(format, FormatUtils.getSizeFromBytes(file.getLength()), convertMsToDate(file.getCreationTimeMs()), inMemory, file.getPath()); if (file.isFolder) { lsr(new TachyonURI(path.getScheme(), path.getAuthority(), file.getPath())); } } return 0; }
throw new IOException(e); path = info.getPath();
private boolean readFile(TachyonFileSystem tachyonClient) throws IOException, TachyonException { boolean pass = true; for (int i = 0; i < mNumFiles; i ++) { TachyonURI filePath = new TachyonURI(mFileFolder + "/part-" + i); LOG.debug("Reading data from {}", filePath); TachyonFile file = tachyonClient.open(filePath); FileInStream is = tachyonClient.getInStream(file); FileInfo info = tachyonClient.getInfo(file); ByteBuffer buf = ByteBuffer.allocate((int) info.getBlockSizeBytes()); is.read(buf.array()); buf.order(ByteOrder.nativeOrder()); for (int k = 0; k < mNumFiles; k ++) { pass = pass && (buf.getInt() == k); } is.close(); } return pass; }