Skip to content

Commit

Permalink
Switch master side methods to take uri.
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinjia committed Jan 14, 2016
1 parent a488156 commit ae684a8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 41 deletions.
65 changes: 34 additions & 31 deletions servers/src/main/java/tachyon/master/file/FileSystemMaster.java
Expand Up @@ -343,6 +343,22 @@ public FileInfo getFileInfo(long fileId) throws FileDoesNotExistException {
} }
} }


/**
* Returns the {@link FileInfo} for a given path. Called via RPC, as well as internal masters.
*
* @param uri the path to get the {@link FileInfo} for
* @return the {@link FileInfo} for the given file id
* @throws FileDoesNotExistException if the file does not exist
*/
public FileInfo getFileInfo(TachyonURI uri)
throws FileDoesNotExistException, InvalidPathException {
MasterContext.getMasterSource().incGetFileInfoOps(1);
synchronized (mInodeTree) {
Inode inode = mInodeTree.getInodeByPath(uri);
return getFileInfoInternal(inode);
}
}

/** /**
* Returns the persistence state of a given file. * Returns the persistence state of a given file.
* *
Expand Down Expand Up @@ -414,24 +430,24 @@ public FileSystemMasterView getFileSystemMasterView() {
/** /**
* Completes a file. After a file is completed, it cannot be written to. Called via RPC. * Completes a file. After a file is completed, it cannot be written to. Called via RPC.
* *
* @param fileId the file id to complete * @param uri the file uri to complete
* @param options the method options * @param options the method options
* @throws BlockInfoException if a block information exception is encountered * @throws BlockInfoException if a block information exception is encountered
* @throws FileDoesNotExistException if the file does not exist * @throws FileDoesNotExistException if the file does not exist
* @throws InvalidPathException if an invalid path is encountered * @throws InvalidPathException if an invalid path is encountered
* @throws InvalidFileSizeException if an invalid file size is encountered * @throws InvalidFileSizeException if an invalid file size is encountered
* @throws FileAlreadyCompletedException if the file is already completed * @throws FileAlreadyCompletedException if the file is already completed
*/ */
public void completeFile(long fileId, CompleteFileOptions options) public void completeFile(TachyonURI uri, CompleteFileOptions options)
throws BlockInfoException, FileDoesNotExistException, InvalidPathException, throws BlockInfoException, FileDoesNotExistException, InvalidPathException,
InvalidFileSizeException, FileAlreadyCompletedException { InvalidFileSizeException, FileAlreadyCompletedException {
MasterContext.getMasterSource().incCompleteFileOps(1); MasterContext.getMasterSource().incCompleteFileOps(1);
synchronized (mInodeTree) { synchronized (mInodeTree) {
long opTimeMs = System.currentTimeMillis(); long opTimeMs = System.currentTimeMillis();
Inode inode = mInodeTree.getInodeById(fileId); Inode inode = mInodeTree.getInodeByPath(uri);
long fileId = inode.getId();
if (!inode.isFile()) { if (!inode.isFile()) {
throw new FileDoesNotExistException( throw new FileDoesNotExistException(ExceptionMessage.PATH_MUST_BE_FILE.getMessage(uri));
ExceptionMessage.FILEID_MUST_BE_FILE.getMessage(fileId));
} }


InodeFile fileInode = (InodeFile) inode; InodeFile fileInode = (InodeFile) inode;
Expand Down Expand Up @@ -585,18 +601,19 @@ private void resetBlockFileFromEntry(ReinitializeFileEntry entry) {
/** /**
* Returns the next block id for a given file id. Called via RPC. * Returns the next block id for a given file id. Called via RPC.
* *
* @param fileId the file id to get the next block id for * @param uri the uri of the file to get the next block id for
* @return the next block id for the file * @return the next block id for the file
* @throws FileDoesNotExistException if the file does not exist * @throws FileDoesNotExistException if the file does not exist
*/ */
public long getNewBlockIdForFile(long fileId) throws FileDoesNotExistException { public long getNewBlockIdForFile(TachyonURI uri)
throws FileDoesNotExistException, InvalidPathException {
MasterContext.getMasterSource().incGetNewBlockOps(1); MasterContext.getMasterSource().incGetNewBlockOps(1);
Inode inode; Inode inode;
synchronized (mInodeTree) { synchronized (mInodeTree) {
inode = mInodeTree.getInodeById(fileId); inode = mInodeTree.getInodeByPath(uri);
} }
if (!inode.isFile()) { if (!inode.isFile()) {
throw new FileDoesNotExistException(ExceptionMessage.FILEID_MUST_BE_FILE.getMessage(fileId)); throw new FileDoesNotExistException(ExceptionMessage.PATH_MUST_BE_FILE.getMessage(uri));
} }
MasterContext.getMasterSource().incNewBlocksGot(1); MasterContext.getMasterSource().incNewBlocksGot(1);
return ((InodeFile) inode).getNewBlockId(); return ((InodeFile) inode).getNewBlockId();
Expand Down Expand Up @@ -791,18 +808,17 @@ public FileBlockInfo getFileBlockInfo(long fileId, int fileBlockIndex)
/** /**
* Returns all the {@link FileBlockInfo} of the given file. Called via RPC, and internal masters. * Returns all the {@link FileBlockInfo} of the given file. Called via RPC, and internal masters.
* *
* @param fileId the file id to get the info for * @param uri the file id to get the info for
* @return a list of {@link FileBlockInfo} for all the blocks of the file * @return a list of {@link FileBlockInfo} for all the blocks of the file
* @throws FileDoesNotExistException if the file does not exist * @throws FileDoesNotExistException if the file does not exist
*/ */
public List<FileBlockInfo> getFileBlockInfoList(long fileId) public List<FileBlockInfo> getFileBlockInfoList(TachyonURI uri)
throws FileDoesNotExistException, InvalidPathException { throws FileDoesNotExistException, InvalidPathException {
MasterContext.getMasterSource().incGetFileBlockInfoOps(1); MasterContext.getMasterSource().incGetFileBlockInfoOps(1);
synchronized (mInodeTree) { synchronized (mInodeTree) {
Inode inode = mInodeTree.getInodeById(fileId); Inode inode = mInodeTree.getInodeByPath(uri);
if (inode.isDirectory()) { if (inode.isDirectory()) {
throw new FileDoesNotExistException( throw new FileDoesNotExistException(ExceptionMessage.PATH_MUST_BE_FILE.getMessage(uri));
ExceptionMessage.FILEID_MUST_BE_FILE.getMessage(fileId));
} }
InodeFile file = (InodeFile) inode; InodeFile file = (InodeFile) inode;
List<BlockInfo> blockInfoList = mBlockMaster.getBlockInfoList(file.getBlockIds()); List<BlockInfo> blockInfoList = mBlockMaster.getBlockInfoList(file.getBlockIds());
Expand All @@ -816,20 +832,6 @@ public List<FileBlockInfo> getFileBlockInfoList(long fileId)
} }
} }


/**
* Returns all the {@link FileBlockInfo} of the given file. Called by web UI.
*
* @param path the path to the file
* @return a list of {@link FileBlockInfo} for all the blocks of the file
* @throws FileDoesNotExistException if the file does not exist
* @throws InvalidPathException if the path is invalid
*/
public List<FileBlockInfo> getFileBlockInfoList(TachyonURI path)
throws FileDoesNotExistException, InvalidPathException {
long fileId = getFileId(path);
return getFileBlockInfoList(fileId);
}

/** /**
* Generates a {@link FileBlockInfo} object from internal metadata. This adds file information to * Generates a {@link FileBlockInfo} object from internal metadata. This adds file information to
* the block, such as the file offset, and additional UFS locations for the block. * the block, such as the file offset, and additional UFS locations for the block.
Expand Down Expand Up @@ -1212,15 +1214,16 @@ private void propagatePersisted(Inode inode, boolean replayed)
* directory, and the 'recursive' flag is enabled, all descendant files will also be freed. Called * directory, and the 'recursive' flag is enabled, all descendant files will also be freed. Called
* via RPC. * via RPC.
* *
* @param fileId the file to free * @param uri the path to free
* @param recursive if true, and the file is a directory, all descendants will be freed * @param recursive if true, and the file is a directory, all descendants will be freed
* @return true if the file was freed * @return true if the file was freed
* @throws FileDoesNotExistException if the file does not exist * @throws FileDoesNotExistException if the file does not exist
*/ */
public boolean free(long fileId, boolean recursive) throws FileDoesNotExistException { public boolean free(TachyonURI uri, boolean recursive)
throws FileDoesNotExistException, InvalidPathException {
MasterContext.getMasterSource().incFreeFileOps(1); MasterContext.getMasterSource().incFreeFileOps(1);
synchronized (mInodeTree) { synchronized (mInodeTree) {
Inode inode = mInodeTree.getInodeById(fileId); Inode inode = mInodeTree.getInodeByPath(uri);


if (inode.isDirectory() && !recursive && ((InodeDirectory) inode).getNumberOfChildren() > 0) { if (inode.isDirectory() && !recursive && ((InodeDirectory) inode).getNumberOfChildren() > 0) {
// inode is nonempty, and we don't want to free a nonempty directory unless recursive is // inode is nonempty, and we don't want to free a nonempty directory unless recursive is
Expand Down
Expand Up @@ -62,8 +62,7 @@ public long getServiceVersion() {
@Override @Override
public void completeFile(String path, CompleteFileTOptions options) throws TachyonTException { public void completeFile(String path, CompleteFileTOptions options) throws TachyonTException {
try { try {
long fileId = mFileSystemMaster.getFileId(new TachyonURI(path)); mFileSystemMaster.completeFile(new TachyonURI(path), new CompleteFileOptions(options));
mFileSystemMaster.completeFile(fileId, new CompleteFileOptions(options));
} catch (TachyonException e) { } catch (TachyonException e) {
throw e.toTachyonTException(); throw e.toTachyonTException();
} }
Expand Down Expand Up @@ -96,8 +95,7 @@ public void createFile(String path, CreateFileTOptions options) throws TachyonTE
@Override @Override
public void free(String path, boolean recursive) throws TachyonTException { public void free(String path, boolean recursive) throws TachyonTException {
try { try {
long fileId = mFileSystemMaster.getFileId(new TachyonURI(path)); mFileSystemMaster.free(new TachyonURI(path), recursive);
mFileSystemMaster.free(fileId, recursive);
} catch (TachyonException e) { } catch (TachyonException e) {
throw e.toTachyonTException(); throw e.toTachyonTException();
} }
Expand All @@ -106,8 +104,7 @@ public void free(String path, boolean recursive) throws TachyonTException {
@Override @Override
public List<FileBlockInfo> getFileBlockInfoList(String path) throws TachyonTException { public List<FileBlockInfo> getFileBlockInfoList(String path) throws TachyonTException {
try { try {
long fileId = mFileSystemMaster.getFileId(new TachyonURI(path)); return mFileSystemMaster.getFileBlockInfoList(new TachyonURI(path));
return mFileSystemMaster.getFileBlockInfoList(fileId);
} catch (TachyonException e) { } catch (TachyonException e) {
throw e.toTachyonTException(); throw e.toTachyonTException();
} }
Expand All @@ -116,8 +113,7 @@ public List<FileBlockInfo> getFileBlockInfoList(String path) throws TachyonTExce
@Override @Override
public long getNewBlockIdForFile(String path) throws TachyonTException { public long getNewBlockIdForFile(String path) throws TachyonTException {
try { try {
long fileId = mFileSystemMaster.getFileId(new TachyonURI(path)); return mFileSystemMaster.getNewBlockIdForFile(new TachyonURI(path));
return mFileSystemMaster.getNewBlockIdForFile(fileId);
} catch (TachyonException e) { } catch (TachyonException e) {
throw e.toTachyonTException(); throw e.toTachyonTException();
} }
Expand All @@ -126,8 +122,7 @@ public long getNewBlockIdForFile(String path) throws TachyonTException {
@Override @Override
public FileInfo getStatus(String path) throws TachyonTException { public FileInfo getStatus(String path) throws TachyonTException {
try { try {
long fileId = mFileSystemMaster.getFileId(new TachyonURI(path)); return mFileSystemMaster.getFileInfo(new TachyonURI(path));
return mFileSystemMaster.getFileInfo(fileId);
} catch (TachyonException e) { } catch (TachyonException e) {
throw e.toTachyonTException(); throw e.toTachyonTException();
} }
Expand Down

0 comments on commit ae684a8

Please sign in to comment.