/** * Gets <code>ClientFileInfo</code> object based on fileId. * * @param fileId the file id of the file or folder. * @param useCachedMetadata if true use the local cached meta data * @return the FileInfo of the file. null if the file does not exist * @throws IOException if the underlying master RPC fails */ public synchronized FileInfo getFileStatus(long fileId, boolean useCachedMetadata) throws IOException { return getFileStatus(fileId, TachyonURI.EMPTY_URI, useCachedMetadata); }
@Override public FileInfo getFileStatus(long fileId, TachyonURI path) throws IOException { return getFileStatus(fileId, path, false); }
private FileInfo getUnCachedFileStatus() throws IOException { return mTachyonFS.getFileStatus(mFileId, false); }
private FileInfo getCachedFileStatus() throws IOException { return mTachyonFS.getFileStatus(mFileId, true); }
/** * Returns whether the file exists or not. * * @param path the file's path in Tachyon file system * @return true if it exists, false otherwise * @throws IOException if the underlying master RPC fails */ // TODO(calvin): Consider making an exists function. public synchronized boolean exist(TachyonURI path) throws IOException { try { FileInfo info = getFileStatus(IdUtils.INVALID_FILE_ID, path, false); return info != null; } catch (IOException ioe) { return false; } }
/** * 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; } }
/** * Gets <code>TachyonFile</code> based on the file id. If useCachedMetadata, this will not see * changes to the file's pin setting, or other dynamic properties. * * @param fid the file id * @param useCachedMetadata whether to use cached metadata * @return TachyonFile of the file id, or null if the file does not exist * @throws IOException if the underlying master RPC fails */ public synchronized TachyonFile getFile(long fid, boolean useCachedMetadata) throws IOException { FileInfo fileInfo = getFileStatus(fid, TachyonURI.EMPTY_URI, useCachedMetadata); if (fileInfo == null) { return null; } return new TachyonFile(this, fid, mTachyonConf); }
/** * Get the block id by the file id and block index. it will check whether the file and the block * exist. * * @param fileId the file id * @param blockIndex The index of the block in the file. * @return the block id if exists * @throws IOException if the file does not exist, or connection issue was encountered */ public synchronized long getBlockId(long fileId, int blockIndex) throws IOException { FileInfo info = getFileStatus(fileId, true); if (info == null) { throw new IOException("File " + fileId + " does not exist."); } if (info.blockIds.size() > blockIndex) { return info.blockIds.get(blockIndex); } try { return mFSMasterClient.getFileBlockInfo(fileId, blockIndex).blockInfo.getBlockId(); } catch (TachyonException e) { throw new IOException(e); } }
/** * If the <code>path</code> is a directory, returns all the direct entries in it. If the * <code>path</code> is a file, returns its ClientFileInfo. * * @param path the target directory/file path * @return A list of FileInfo, null if the file or folder does not exist * @throws IOException when the underlying master RPC fails */ @Override public synchronized List<FileInfo> listStatus(TachyonURI path) throws IOException { validateUri(path); try { return mFSMasterClient.getFileInfoList( getFileStatus(IdUtils.INVALID_FILE_ID, path).getFileId()); } catch (TachyonException e) { throw new IOException(e); } }
/** * Advanced API. * * Gets the FileInfo object that represents the fileId, or the path if fileId is INVALID_FILE_ID. * * @param fileId the file id of the file or folder. * @param path the path of the file or folder. valid iff fileId is INVALID_FILE_ID. * @param useCachedMetadata if true use the local cached meta data * @return the FileInfo of the file. null if the file does not exist * @throws IOException if the underlying master RPC fails */ public synchronized FileInfo getFileStatus(long fileId, TachyonURI path, boolean useCachedMetadata) throws IOException { fileId = getValidFileId(fileId, path.getPath()); return getFileStatus(mIdToClientFileInfo, fileId, fileId, TachyonURI.EMPTY_URI.getPath(), useCachedMetadata); }
/** * Gets <code>TachyonFile</code> based on the path. If useCachedMetadata is true, this will not * see changes to the file's pin setting, or other dynamic properties. * * @param path file path. * @param useCachedMetadata whether to use the file metadata cache * @return TachyonFile of the path, or null if the file does not exist * @throws IOException if the underlying master RPC fails */ public synchronized TachyonFile getFile(TachyonURI path, boolean useCachedMetadata) throws IOException { validateUri(path); FileInfo fileInfo = getFileStatus(IdUtils.INVALID_FILE_ID, path, useCachedMetadata); if (fileInfo == null) { return null; } return new TachyonFile(this, fileInfo.getFileId(), mTachyonConf); }
@Override public boolean rename(Path src, Path dst) throws IOException { LOG.info("rename(" + src + ", " + dst + ")"); if (mStatistics != null) { mStatistics.incrementWriteOps(1); } TachyonURI srcPath = new TachyonURI(Utils.getPathWithoutScheme(src)); TachyonURI dstPath = new TachyonURI(Utils.getPathWithoutScheme(dst)); FileInfo info; try { info = mTFS.getFileStatus(-1, dstPath); } catch (IOException ioe) { info = null; } // If the destination is an existing folder, try to move the src into the folder if (info != null && info.isFolder) { dstPath = dstPath.join(srcPath.getName()); } try { return mTFS.rename(srcPath, dstPath); } catch (IOException ioe) { LOG.error("Failed to rename {} to {}", src, dst, ioe); return false; } }
if (overwrite && !mTFS.getFileStatus(-1, path).isFolder) { if (!mTFS.delete(path, false)) { throw new IOException("Failed to delete existing data " + cPath);