Skip to content

Commit

Permalink
Streamlined error handling in TFsShell
Browse files Browse the repository at this point in the history
All the TFsShell methods were supposed to return 0 on success and -1 on
failure, but they could also throw IOExceptions in certain cases.
Furthermore, the command runner would catch any IOExceptions and return
-1 anyways, so there was no clear distinction between returning -1 and
throwing an IOException.

Now all the TFsShell methods only throw IOExceptions in case of error,
and the runner will catch any exception, print it, and return -1.

Made copyFromLocal, copyToLocal, and touch shell operations more atomic

These two shell operations create files in Tachyon, then do more
TachyonFS operations on the created files. If the subsequent TachyonFS
operations fail, we could throw an exception, but the file we created
would still be lying around. This adds some clean up code to those
functions which tries to delete the created file if subsequent
operations failed.

Note that other methods didn't need to be modified because they either
don't create files in Tachyon, or they accomplish everything with a
single TachyonFS call.
  • Loading branch information
manugoyal committed Oct 23, 2015
1 parent 1a56737 commit c3c78c2
Show file tree
Hide file tree
Showing 7 changed files with 423 additions and 453 deletions.
Expand Up @@ -216,19 +216,8 @@ public boolean mount(TachyonURI tachyonPath, TachyonURI ufsPath, MountOptions op
}
}

/**
* Resolves a {@link TachyonURI} to a {@link TachyonFile} which is used as the file handler for
* non-create operations.
*
* @param path the path of the file, this should be in Tachyon space
* @param openOptions method options
* @return a TachyonFile which acts as a file handler for the path
* @throws IOException if a non-Tachyon exception occurs
* @throws InvalidPathException if there is no file at the given path
* @throws TachyonException if an unexpected tachyon exception is thrown
*/
public TachyonFile open(TachyonURI path, OpenOptions openOptions)
throws IOException, InvalidPathException, TachyonException {
public TachyonFile open(TachyonURI path, OpenOptions openOptions) throws IOException,
InvalidPathException, TachyonException {
TachyonFile f = openIfExists(path, openOptions);
if (f == null) {
throw new InvalidPathException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(path));
Expand Down
Expand Up @@ -284,7 +284,7 @@ private FileInfo getFileInfo() throws IOException {
FileSystemMasterClient client = mContext.acquireMasterClient();
try {
return client.getFileInfo(mFileId);
} catch (TachyonException e) {
} catch (TachyonException e) {
throw new IOException(e.getMessage());
} finally {
mContext.releaseMasterClient(client);
Expand Down
Expand Up @@ -166,8 +166,16 @@ public FileOutStream getOutStream(TachyonURI path, OutStreamOptions options)
.setUnderStorageType(options.getUnderStorageType())
.build();
TachyonFile tFile = create(path, createOptions);
long fileId = tFile.getFileId();
return new FileOutStream(fileId, options);
try {
return new FileOutStream(tFile.getFileId(), options);
} catch (IOException e) {
// Delete the file if it still exists
TachyonFile file = openIfExists(path);
if (file != null) {
delete(file);
}
throw e;
}
}

/**
Expand Down
Expand Up @@ -76,10 +76,9 @@ public static boolean waitCompleted(TachyonFileSystemCore tfs, TachyonURI uri)
* while it is waited upon. In such cases the method will throw the a {@link TachyonException}
* with the appropriate {@link tachyon.exception.TachyonExceptionType}
*
* <i>IMPLEMENTATION NOTES</i> This method is implemented
* by periodically polling the master about the file status. The
* polling period is controlled by the {@link Constants#USER_FILE_WAITCOMPLETED_POLL_MS}
* java property and defaults to a generous 1 second.
* <i>IMPLEMENTATION NOTES</i> This method is implemented by periodically polling the master about
* the file status. The polling period is controlled by the
* {@link Constants#USER_WAITCOMPLETED_POLL} java property and defaults to a generous 1 second.
*
* @param tfs an instance of {@link TachyonFileSystemCore}
* @param uri the URI of the file whose completion status is to be watied for.
Expand Down
5 changes: 5 additions & 0 deletions common/src/main/java/tachyon/exception/ExceptionMessage.java
Expand Up @@ -27,6 +27,7 @@
public enum ExceptionMessage {
// general
PATH_DOES_NOT_EXIST("Path {0} does not exist"),
PATH_MUST_BE_FILE("Path {0} must be a file"),

// general block
BLOCK_NOT_LOCALLY_AVAILABLE("Block {0} is not available on local machine"),
Expand Down Expand Up @@ -93,6 +94,10 @@ public enum ExceptionMessage {
RAW_TABLE_METADATA_OVERSIZED("Size of raw table metadata {0} should be smaller than {1}"),
RAW_TABLE_PATH_DOES_NOT_EXIST("Raw table with path {0} does not exist"),

// shell
DESTINATION_FILE_CANNOT_EXIST_WITH_WILDCARD_SOURCE(
"The destination cannot be an existent file when the src contains wildcards."),

// lineage
LINEAGE_INPUT_FILE_NOT_EXIST("The lineage input file {0} does not exist"),
LINEAGE_OUTPUT_FILE_NOT_EXIST("No lineage has output file {0}"),
Expand Down

0 comments on commit c3c78c2

Please sign in to comment.