Skip to content

Commit

Permalink
Cleaned up code# Please enter the commit message for your changes. Li…
Browse files Browse the repository at this point in the history
…nes starting
  • Loading branch information
abh1nay committed Apr 23, 2013
1 parent b245e3b commit ff2d58f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
39 changes: 24 additions & 15 deletions src/java/voldemort/utils/ClusterForkLiftTool.java
Expand Up @@ -108,6 +108,18 @@
*/
public class ClusterForkLiftTool implements Runnable {

/*
* different modes available with the forklift tool
*/
enum ForkLiftTaskMode {
global_resolution, /* Fetch data from all partitions and do resolution */
primary_resolution, /*
* Fetch data from primary partition and do
* resolution
*/
no_resolution /* fetch data from primary parition and do no resolution */
}

private static Logger logger = Logger.getLogger(ClusterForkLiftTool.class);
private static final int DEFAULT_MAX_PUTS_PER_SEC = 500;
private static final int DEFAULT_PROGRESS_PERIOD_OPS = 100000;
Expand Down Expand Up @@ -201,12 +213,6 @@ private HashMap<String, StoreDefinition> checkStoresOnBothSides() {
return srcStoreDefMap;
}

enum ForkLiftTaskMode {
global_resolution,
primary_resolution,
no_resolution
}

/**
* TODO this base class can potentially provide some framework of execution
* for the subclasses, to yield a better objected oriented design (progress
Expand Down Expand Up @@ -421,7 +427,7 @@ public void run() {

/**
* Simply fetches the data for the partition from the primary replica and
* writes it into the destination cluster without resolving any of he
* writes it into the destination cluster without resolving any of the
* conflicting values
*
*/
Expand Down Expand Up @@ -587,10 +593,10 @@ private static OptionParser getParser() {
.withRequiredArg()
.describedAs("partitionParallelism")
.ofType(Integer.class);
parser.accepts("global-resolution",
"Determines if a thorough global resolution needs to be done, by comparing all replicas. [Default: Fetch from primary alone ]");
parser.accepts("bypass-resolution",
"Does no resolution writes all the versioned values. [Default: Fetch from primary alone ]");
parser.accepts("mode",
"Determines if a thorough global resolution needs to be done, by comparing all replicas. [Default: "
+ ForkLiftTaskMode.primary_resolution.toString()
+ " Fetch from primary alone ]");
return parser;
}

Expand Down Expand Up @@ -645,11 +651,13 @@ public static void main(String[] args) throws Exception {
}

ForkLiftTaskMode mode;
mode = options.has("global-resolution") ? ForkLiftTaskMode.global_resolution
: ForkLiftTaskMode.primary_resolution;
mode = ForkLiftTaskMode.primary_resolution;
if(options.has("mode")) {
mode = Utils.getEnumFromString(ForkLiftTaskMode.class, (String) options.valueOf("mode"));
if(mode == null)
mode = ForkLiftTaskMode.primary_resolution;

mode = options.has("bypass-resolution") ? ForkLiftTaskMode.no_resolution
: ForkLiftTaskMode.primary_resolution;
}

ClusterForkLiftTool forkLiftTool = new ClusterForkLiftTool(srcBootstrapUrl,
dstBootstrapUrl,
Expand All @@ -663,4 +671,5 @@ public static void main(String[] args) throws Exception {
// TODO cleanly shut down the hanging threadpool
System.exit(0);
}

}
17 changes: 17 additions & 0 deletions src/java/voldemort/utils/Utils.java
Expand Up @@ -586,4 +586,21 @@ public static int getDayOfTheWeekFromNow(int nDays) {
cal.add(Calendar.DAY_OF_YEAR, nDays);
return cal.get(Calendar.DAY_OF_WEEK);
}

/**
* A common method for all enums since they can't have another base class
*
* @param <T> Enum type
* @param c enum type. All enums must be all caps.
* @param string case insensitive
* @return corresponding enum, or null
*/
public static <T extends Enum<T>> T getEnumFromString(Class<T> c, String string) {
if(c != null && string != null) {
try {
return Enum.valueOf(c, string.trim().toUpperCase());
} catch(IllegalArgumentException ex) {}
}
return null;
}
}
2 changes: 1 addition & 1 deletion test/unit/voldemort/utils/ClusterForkLiftToolTest.java
Expand Up @@ -331,7 +331,7 @@ public void testNoresolutionForkLift() throws Exception {

for(Node node: dstAdminClient.getAdminClientCluster().getNodes()) {

Iterator<Pair<ByteArray, Versioned<byte[]>>> entryItr = srcAdminClient.bulkFetchOps.fetchEntries(node.getId(),
Iterator<Pair<ByteArray, Versioned<byte[]>>> entryItr = dstAdminClient.bulkFetchOps.fetchEntries(node.getId(),
MULTIPLE_VERSIONS_STORE_NAME,
node.getPartitionIds(),
null,
Expand Down

0 comments on commit ff2d58f

Please sign in to comment.