HBASE-24340 PerformanceEvaluation options should not mandate any specific order

Signed-off-by Anoop Sam John <anoopsamjohn@apache.org>
This commit is contained in:
Sambit Mohapatra 2020-06-08 23:02:39 -07:00 committed by GitHub
parent 3d50e73871
commit c718fa2365
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 95 additions and 23 deletions

View File

@ -2616,29 +2616,18 @@ public class PerformanceEvaluation extends Configured implements Tool {
final String autoFlush = "--autoFlush="; final String autoFlush = "--autoFlush=";
if (cmd.startsWith(autoFlush)) { if (cmd.startsWith(autoFlush)) {
opts.autoFlush = Boolean.parseBoolean(cmd.substring(autoFlush.length())); opts.autoFlush = Boolean.parseBoolean(cmd.substring(autoFlush.length()));
if (!opts.autoFlush && opts.multiPut > 0) {
throw new IllegalArgumentException("autoFlush must be true when multiPut is more than 0");
}
continue; continue;
} }
final String onceCon = "--oneCon="; final String onceCon = "--oneCon=";
if (cmd.startsWith(onceCon)) { if (cmd.startsWith(onceCon)) {
opts.oneCon = Boolean.parseBoolean(cmd.substring(onceCon.length())); opts.oneCon = Boolean.parseBoolean(cmd.substring(onceCon.length()));
if (opts.oneCon && opts.connCount > 1) {
throw new IllegalArgumentException("oneCon is set to true, "
+ "connCount should not bigger than 1");
}
continue; continue;
} }
final String connCount = "--connCount="; final String connCount = "--connCount=";
if (cmd.startsWith(connCount)) { if (cmd.startsWith(connCount)) {
opts.connCount = Integer.parseInt(cmd.substring(connCount.length())); opts.connCount = Integer.parseInt(cmd.substring(connCount.length()));
if (opts.oneCon && opts.connCount > 1) {
throw new IllegalArgumentException("oneCon is set to true, "
+ "connCount should not bigger than 1");
}
continue; continue;
} }
@ -2657,9 +2646,6 @@ public class PerformanceEvaluation extends Configured implements Tool {
final String multiPut = "--multiPut="; final String multiPut = "--multiPut=";
if (cmd.startsWith(multiPut)) { if (cmd.startsWith(multiPut)) {
opts.multiPut = Integer.parseInt(cmd.substring(multiPut.length())); opts.multiPut = Integer.parseInt(cmd.substring(multiPut.length()));
if (!opts.autoFlush && opts.multiPut > 0) {
throw new IllegalArgumentException("autoFlush must be true when multiPut is more than 0");
}
continue; continue;
} }
@ -2733,18 +2719,12 @@ public class PerformanceEvaluation extends Configured implements Tool {
final String valueRandom = "--valueRandom"; final String valueRandom = "--valueRandom";
if (cmd.startsWith(valueRandom)) { if (cmd.startsWith(valueRandom)) {
opts.valueRandom = true; opts.valueRandom = true;
if (opts.valueZipf) {
throw new IllegalStateException("Either valueZipf or valueRandom but not both");
}
continue; continue;
} }
final String valueZipf = "--valueZipf"; final String valueZipf = "--valueZipf";
if (cmd.startsWith(valueZipf)) { if (cmd.startsWith(valueZipf)) {
opts.valueZipf = true; opts.valueZipf = true;
if (opts.valueRandom) {
throw new IllegalStateException("Either valueZipf or valueRandom but not both");
}
continue; continue;
} }
@ -2810,6 +2790,8 @@ public class PerformanceEvaluation extends Configured implements Tool {
continue; continue;
} }
validateParsedOpts(opts);
if (isCommandClass(cmd)) { if (isCommandClass(cmd)) {
opts.cmdName = cmd; opts.cmdName = cmd;
try { try {
@ -2831,6 +2813,25 @@ public class PerformanceEvaluation extends Configured implements Tool {
return opts; return opts;
} }
/**
* Validates opts after all the opts are parsed, so that caller need not to maintain order of opts
*/
private static void validateParsedOpts(TestOptions opts) {
if (!opts.autoFlush && opts.multiPut > 0) {
throw new IllegalArgumentException("autoFlush must be true when multiPut is more than 0");
}
if (opts.oneCon && opts.connCount > 1) {
throw new IllegalArgumentException("oneCon is set to true, "
+ "connCount should not bigger than 1");
}
if (opts.valueZipf && opts.valueRandom) {
throw new IllegalStateException("Either valueZipf or valueRandom but not both");
}
}
static TestOptions calculateRowsAndSize(final TestOptions opts) { static TestOptions calculateRowsAndSize(final TestOptions opts) {
int rowsPerGB = getRowsPerGB(opts); int rowsPerGB = getRowsPerGB(opts);
if ((opts.getCmdName() != null if ((opts.getCmdName() != null

View File

@ -257,8 +257,14 @@ public class TestPerformanceEvaluation {
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
System.out.println(e.getMessage()); System.out.println(e.getMessage());
} }
((LinkedList<String>) opts).offerFirst("--multiPut=10");
((LinkedList<String>) opts).offerFirst("--autoFlush=true"); //Re-create options
opts = new LinkedList<>();
opts.offer("--autoFlush=true");
opts.offer("--multiPut=10");
opts.offer(cmdName);
opts.offer("64");
options = PerformanceEvaluation.parseOpts(opts); options = PerformanceEvaluation.parseOpts(opts);
assertNotNull(options); assertNotNull(options);
assertNotNull(options.getCmdName()); assertNotNull(options.getCmdName());
@ -266,6 +272,36 @@ public class TestPerformanceEvaluation {
assertEquals(10, options.getMultiPut()); assertEquals(10, options.getMultiPut());
} }
@Test
public void testParseOptsMultiPutsAndAutoFlushOrder() {
Queue<String> opts = new LinkedList<>();
String cmdName = "sequentialWrite";
String cmdMultiPut = "--multiPut=10";
String cmdAutoFlush = "--autoFlush=true";
opts.offer(cmdAutoFlush);
opts.offer(cmdMultiPut);
opts.offer(cmdName);
opts.offer("64");
PerformanceEvaluation.TestOptions options = null;
options = PerformanceEvaluation.parseOpts(opts);
assertNotNull(options);
assertEquals(true, options.autoFlush);
assertEquals(10, options.getMultiPut());
// Change the order of AutoFlush and Multiput
opts = new LinkedList<>();
opts.offer(cmdMultiPut);
opts.offer(cmdAutoFlush);
opts.offer(cmdName);
opts.offer("64");
options = null;
options = PerformanceEvaluation.parseOpts(opts);
assertNotNull(options);
assertEquals(10, options.getMultiPut());
assertEquals(true, options.autoFlush);
}
@Test @Test
public void testParseOptsConnCount() { public void testParseOptsConnCount() {
Queue<String> opts = new LinkedList<>(); Queue<String> opts = new LinkedList<>();
@ -281,11 +317,46 @@ public class TestPerformanceEvaluation {
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
System.out.println(e.getMessage()); System.out.println(e.getMessage());
} }
((LinkedList<String>) opts).offerFirst("--connCount=10");
opts = new LinkedList<>();
opts.offer("--connCount=10");
opts.offer(cmdName);
opts.offer("64");
options = PerformanceEvaluation.parseOpts(opts); options = PerformanceEvaluation.parseOpts(opts);
assertNotNull(options); assertNotNull(options);
assertNotNull(options.getCmdName()); assertNotNull(options.getCmdName());
assertEquals(cmdName, options.getCmdName()); assertEquals(cmdName, options.getCmdName());
assertEquals(10, options.getConnCount()); assertEquals(10, options.getConnCount());
} }
@Test
public void testParseOptsValueRandom() {
Queue<String> opts = new LinkedList<>();
String cmdName = "sequentialWrite";
opts.offer("--valueRandom");
opts.offer("--valueZipf");
opts.offer(cmdName);
opts.offer("64");
PerformanceEvaluation.TestOptions options = null;
try {
options = PerformanceEvaluation.parseOpts(opts);
fail("should fail");
} catch (IllegalStateException e) {
System.out.println(e.getMessage());
}
opts = new LinkedList<>();
opts.offer("--valueRandom");
opts.offer(cmdName);
opts.offer("64");
options = PerformanceEvaluation.parseOpts(opts);
assertNotNull(options);
assertNotNull(options.getCmdName());
assertEquals(cmdName, options.getCmdName());
assertEquals(true, options.valueRandom);
}
} }