Skip to content

Commit

Permalink
HDFS-12481. Ozone: Corona: Support for variable key length in offline…
Browse files Browse the repository at this point in the history
… mode. Contributed by Nandakumar.
  • Loading branch information
anuengineer authored and omalley committed Apr 26, 2018
1 parent d9c3d9a commit b984e90
Showing 1 changed file with 24 additions and 6 deletions.
Expand Up @@ -91,6 +91,7 @@ public final class Corona extends Configured implements Tool {
private static final String NUM_OF_VOLUMES = "numOfVolumes"; private static final String NUM_OF_VOLUMES = "numOfVolumes";
private static final String NUM_OF_BUCKETS = "numOfBuckets"; private static final String NUM_OF_BUCKETS = "numOfBuckets";
private static final String NUM_OF_KEYS = "numOfKeys"; private static final String NUM_OF_KEYS = "numOfKeys";
private static final String KEY_SIZE = "keySize";


private static final String MODE_DEFAULT = "offline"; private static final String MODE_DEFAULT = "offline";
private static final String SOURCE_DEFAULT = private static final String SOURCE_DEFAULT =
Expand All @@ -101,6 +102,8 @@ public final class Corona extends Configured implements Tool {
private static final String NUM_OF_BUCKETS_DEFAULT = "1000"; private static final String NUM_OF_BUCKETS_DEFAULT = "1000";
private static final String NUM_OF_KEYS_DEFAULT = "500000"; private static final String NUM_OF_KEYS_DEFAULT = "500000";


private static final int KEY_SIZE_DEFAULT = 10240;

private static final Logger LOG = private static final Logger LOG =
LoggerFactory.getLogger(Corona.class); LoggerFactory.getLogger(Corona.class);


Expand All @@ -115,6 +118,8 @@ public final class Corona extends Configured implements Tool {
private String numOfBuckets; private String numOfBuckets;
private String numOfKeys; private String numOfKeys;


private int keySize;

private boolean validateWrites; private boolean validateWrites;


private OzoneClient ozoneClient; private OzoneClient ozoneClient;
Expand Down Expand Up @@ -157,8 +162,8 @@ public final class Corona extends Configured implements Tool {
@Override @Override
public int run(String[] args) throws Exception { public int run(String[] args) throws Exception {
GenericOptionsParser parser = new GenericOptionsParser(getConf(), GenericOptionsParser parser = new GenericOptionsParser(getConf(),
getOzonePetaGenOptions(), args); getOptions(), args);
parseOzonePetaGenOptions(parser.getCommandLine()); parseOptions(parser.getCommandLine());
if(printUsage) { if(printUsage) {
usage(); usage();
return 0; return 0;
Expand All @@ -174,6 +179,7 @@ public int run(String[] args) throws Exception {
LOG.info("Number of Volumes: {}.", numOfVolumes); LOG.info("Number of Volumes: {}.", numOfVolumes);
LOG.info("Number of Buckets per Volume: {}.", numOfBuckets); LOG.info("Number of Buckets per Volume: {}.", numOfBuckets);
LOG.info("Number of Keys per Bucket: {}.", numOfKeys); LOG.info("Number of Keys per Bucket: {}.", numOfKeys);
LOG.info("Key size: {} bytes", keySize);
for (int i = 0; i < Integer.parseInt(numOfVolumes); i++) { for (int i = 0; i < Integer.parseInt(numOfVolumes); i++) {
String volume = "vol-" + i + "-" + String volume = "vol-" + i + "-" +
RandomStringUtils.randomNumeric(5); RandomStringUtils.randomNumeric(5);
Expand Down Expand Up @@ -205,7 +211,7 @@ public int run(String[] args) throws Exception {
return 0; return 0;
} }


private Options getOzonePetaGenOptions() { private Options getOptions() {
Options options = new Options(); Options options = new Options();


OptionBuilder.withDescription("prints usage."); OptionBuilder.withDescription("prints usage.");
Expand Down Expand Up @@ -251,6 +257,12 @@ private Options getOzonePetaGenOptions() {
"created per Bucket in offline mode"); "created per Bucket in offline mode");
Option optNumOfKeys = OptionBuilder.create(NUM_OF_KEYS); Option optNumOfKeys = OptionBuilder.create(NUM_OF_KEYS);


OptionBuilder.withArgName("value");
OptionBuilder.hasArg();
OptionBuilder.withDescription("specifies the size of Key in bytes to be " +
"created in offline mode");
Option optKeySize = OptionBuilder.create(KEY_SIZE);

options.addOption(optHelp); options.addOption(optHelp);
options.addOption(optMode); options.addOption(optMode);
options.addOption(optSource); options.addOption(optSource);
Expand All @@ -259,10 +271,11 @@ private Options getOzonePetaGenOptions() {
options.addOption(optNumOfVolumes); options.addOption(optNumOfVolumes);
options.addOption(optNumOfBuckets); options.addOption(optNumOfBuckets);
options.addOption(optNumOfKeys); options.addOption(optNumOfKeys);
options.addOption(optKeySize);
return options; return options;
} }


private void parseOzonePetaGenOptions(CommandLine cmdLine) { private void parseOptions(CommandLine cmdLine) {
printUsage = cmdLine.hasOption(HELP); printUsage = cmdLine.hasOption(HELP);


mode = cmdLine.hasOption(MODE) ? mode = cmdLine.hasOption(MODE) ?
Expand All @@ -284,6 +297,10 @@ private void parseOzonePetaGenOptions(CommandLine cmdLine) {


numOfKeys = cmdLine.hasOption(NUM_OF_KEYS) ? numOfKeys = cmdLine.hasOption(NUM_OF_KEYS) ?
cmdLine.getOptionValue(NUM_OF_KEYS) : NUM_OF_KEYS_DEFAULT; cmdLine.getOptionValue(NUM_OF_KEYS) : NUM_OF_KEYS_DEFAULT;

keySize = cmdLine.hasOption(KEY_SIZE) ?
Integer.parseInt(cmdLine.getOptionValue(KEY_SIZE)) : KEY_SIZE_DEFAULT;

} }


private void usage() { private void usage() {
Expand All @@ -306,6 +323,8 @@ private void usage() {
System.out.println("-numOfKeys <value> " System.out.println("-numOfKeys <value> "
+ "specifies number of Keys to be created per Bucket " + + "specifies number of Keys to be created per Bucket " +
"in offline mode"); "in offline mode");
System.out.println("-keySize <value> "
+ "specifies the size of Key in bytes to be created in offline mode");
System.out.println("-help " System.out.println("-help "
+ "prints usage."); + "prints usage.");
System.out.println(); System.out.println();
Expand Down Expand Up @@ -343,8 +362,7 @@ public void run() {
String key = "key-" + k + "-" + String key = "key-" + k + "-" +
RandomStringUtils.randomNumeric(5); RandomStringUtils.randomNumeric(5);
byte[] value = DFSUtil.string2Bytes( byte[] value = DFSUtil.string2Bytes(
RandomStringUtils.randomAscii(10240)); RandomStringUtils.randomAscii(keySize));

try { try {
LOG.trace("Adding key: {} in bucket: {} of volume: {}", LOG.trace("Adding key: {} in bucket: {} of volume: {}",
key, bucket, volume); key, bucket, volume);
Expand Down

0 comments on commit b984e90

Please sign in to comment.