-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log file fix, MasterLogReader fix, test cases #24
Changes from all commits
3580e3a
f3af086
3216d0c
e9b33f3
a0c3e7d
ec01217
86f68dc
f5e1ea7
7059fc5
049f8c0
879850e
c90eee7
fef6127
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,46 +2,55 @@ | |
|
||
import java.net.InetSocketAddress; | ||
|
||
import tachyon.Constants; | ||
import tachyon.thrift.InvalidPathException; | ||
|
||
/** | ||
* Class for convenience methods used by TFsShell. | ||
*/ | ||
public class Utils { | ||
private static final String HEADER = "tachyon://"; | ||
|
||
/** | ||
* Validates the path, verifying that it contains the header and a hostname:port specified. | ||
* @param path The path to be verified. | ||
* @throws InvalidPathException | ||
*/ | ||
public static void validateTachyonPath(String path) { | ||
if (!path.startsWith(HEADER)) { | ||
System.out.println("The path format is " + HEADER + "<MASTERHOST>:<PORT>/<PATH_NAME>"); | ||
System.exit(-1); | ||
} | ||
path = path.substring(HEADER.length()); | ||
if (!path.contains(":") || !path.contains("/")) { | ||
System.out.println("The path format is " + HEADER + "<MASTERHOST>:<PORT>/<PATH_NAME>"); | ||
System.exit(-1); | ||
public static String validateTachyonPath(String path) throws InvalidPathException { | ||
if (path.startsWith(HEADER)) { | ||
if (!path.contains(":")) { | ||
throw new InvalidPathException( | ||
"Invalid Path: " + path + "\n Use tachyon://host:port/ or /file"); | ||
} else { | ||
return path; | ||
} | ||
} else { | ||
String HOSTNAME = System.getProperty("tachyon.master.hostname", "localhost"); | ||
String PORT = System.getProperty("tachyon.master.port", "" + Constants.DEFAULT_MASTER_PORT); | ||
return HEADER + HOSTNAME + ":" + PORT + path; | ||
} | ||
} | ||
|
||
/** | ||
* Removes header and hostname:port information from a path, leaving only the local file path. | ||
* @param path The path to obtain the local path from | ||
* @return The local path in string format | ||
* @throws InvalidPathException | ||
*/ | ||
public static String getFilePath(String path) { | ||
validateTachyonPath(path); | ||
public static String getFilePath(String path) throws InvalidPathException { | ||
path = validateTachyonPath(path); | ||
path = path.substring(HEADER.length()); | ||
return path.substring(path.indexOf("/")); | ||
String ret = path.substring(path.indexOf("/")); | ||
return ret; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this, you can use CommonUtils.cleanPath(). But why do this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's because of what I did above, I can remove both if its unnecessary to support that kind of path |
||
} | ||
|
||
/** | ||
* Obtains the InetSocketAddress from a path by parsing the hostname:port portion of the path. | ||
* @param path The path to obtain the InetSocketAddress from. | ||
* @return The InetSocketAddress of the master node. | ||
* @throws InvalidPathException | ||
*/ | ||
public static InetSocketAddress getTachyonMasterAddress(String path) { | ||
validateTachyonPath(path); | ||
public static InetSocketAddress getTachyonMasterAddress(String path) throws InvalidPathException { | ||
path = validateTachyonPath(path); | ||
path = path.substring(HEADER.length()); | ||
String masterAddress = path.substring(0, path.indexOf("/")); | ||
String masterHost = masterAddress.split(":")[0]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,4 +95,47 @@ public void appendAndFlushCheckpointTest() throws IOException { | |
Assert.assertEquals(checkpointInfo, toCheck.getSecond()); | ||
Assert.assertFalse(mMasterLogReader.hasNext()); | ||
} | ||
|
||
@Test | ||
public void largeLogTest() throws IOException { | ||
Inode inode; | ||
CheckpointInfo checkpointInfo; | ||
int numEntries = 100000; | ||
for (int i = 0; i < numEntries; i ++) { | ||
switch (i % 3) { | ||
case 0: | ||
inode = new InodeFile("/testFile" + i, 1 + i, 0); | ||
mMasterLogWriter.append(inode, true); | ||
break; | ||
case 1: | ||
inode = new InodeFolder("/testFolder" + i, 1 + i, 0); | ||
mMasterLogWriter.append(inode, true); | ||
break; | ||
case 2: | ||
checkpointInfo = new CheckpointInfo(i); | ||
mMasterLogWriter.appendAndFlush(checkpointInfo); | ||
break; | ||
} | ||
} | ||
mMasterLogReader = new MasterLogReader(mLogFile); | ||
for (int i = 0; i < numEntries; i ++) { | ||
switch (i % 3) { | ||
case 0: | ||
inode = new InodeFile("/testFile" + i, 1 + i, 0); | ||
Assert.assertEquals(new Pair<LogType, Object>(LogType.InodeFile, inode), | ||
mMasterLogReader.getNextPair()); | ||
break; | ||
case 1: | ||
inode = new InodeFolder("/testFolder" + i, 1 + i, 0); | ||
Assert.assertEquals(new Pair<LogType, Object>(LogType.InodeFolder, inode), | ||
mMasterLogReader.getNextPair()); | ||
break; | ||
case 2: | ||
checkpointInfo = new CheckpointInfo(i); | ||
Assert.assertEquals(new Pair<LogType, Object>(LogType.CheckpointInfo, checkpointInfo), | ||
mMasterLogReader.getNextPair()); | ||
break; | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How long does this test run? Could we remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I originally had to keep track because of the randomness, but not anymore. It takes around 2 seconds. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has this been tested?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I tested it running from the bin directory and the top level directory