Permalink
Browse files

Better Entropy Detection + New JMX hook in SchedulerService

  • Loading branch information...
1 parent c3f448c commit 5adf557129fbd1cce3b3f3078ea7719548f7e6aa @rsumbaly rsumbaly committed with afeinberg Jan 11, 2011
@@ -68,6 +68,7 @@
import voldemort.store.slop.Slop;
import voldemort.store.slop.Slop.Operation;
import voldemort.store.socket.SocketDestination;
+import voldemort.store.views.ViewStorageConfiguration;
import voldemort.utils.ByteArray;
import voldemort.utils.ByteUtils;
import voldemort.utils.NetworkClassLoader;
@@ -117,7 +118,8 @@
private final AdminClientConfig adminClientConfig;
public final static List<String> restoreStoreEngineBlackList = Arrays.asList(MysqlStorageConfiguration.TYPE_NAME,
- ReadOnlyStorageConfiguration.TYPE_NAME);
+ ReadOnlyStorageConfiguration.TYPE_NAME,
+ ViewStorageConfiguration.TYPE_NAME);
private Cluster currentCluster;
@@ -17,6 +17,7 @@
package voldemort.server.scheduler;
import java.util.Date;
+import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
@@ -27,13 +28,16 @@
import org.apache.log4j.Logger;
+import voldemort.annotations.jmx.JmxGetter;
import voldemort.annotations.jmx.JmxManaged;
import voldemort.annotations.jmx.JmxOperation;
import voldemort.server.AbstractService;
import voldemort.server.ServiceType;
import voldemort.server.VoldemortService;
import voldemort.utils.Time;
+import com.google.common.collect.Lists;
+
/**
* The voldemort scheduler
*
@@ -125,6 +129,11 @@ public void enable(String id) {
}
}
+ @JmxGetter(name = "getScheduledJobs", description = "Returns names of jobs in the scheduler")
+ public List<String> getScheduledJobs() {
+ return Lists.newArrayList(scheduledJobResults.keySet());
+ }
+
public void scheduleNow(Runnable runnable) {
scheduler.execute(runnable);
}
@@ -1,25 +1,24 @@
package voldemort.utils;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
-import voldemort.client.protocol.RequestFormatType;
+import voldemort.client.ClientConfig;
+import voldemort.client.SocketStoreClientFactory;
+import voldemort.client.StoreClient;
import voldemort.client.protocol.admin.AdminClient;
import voldemort.client.protocol.admin.AdminClientConfig;
import voldemort.cluster.Cluster;
-import voldemort.cluster.Node;
-import voldemort.routing.RoutingStrategy;
-import voldemort.routing.RoutingStrategyFactory;
-import voldemort.server.RequestRoutingType;
-import voldemort.store.Store;
+import voldemort.serialization.DefaultSerializerFactory;
+import voldemort.serialization.Serializer;
import voldemort.store.StoreDefinition;
-import voldemort.store.socket.SocketStoreFactory;
-import voldemort.store.socket.clientrequest.ClientRequestExecutorPool;
import voldemort.versioning.Versioned;
import com.google.common.base.Joiner;
@@ -33,21 +32,18 @@ public static void main(String args[]) throws IOException {
.withRequiredArg()
.describedAs("bootstrap-url")
.ofType(String.class);
- parser.accepts("first-id", "[REQUIRED] node id for first node")
+ parser.accepts("output-dir", "[REQUIRED] The output directory where we'll store the keys")
.withRequiredArg()
- .describedAs("node-id")
- .ofType(Integer.class);
- parser.accepts("second-id", "[REQUIRED] node id for second node")
- .withRequiredArg()
- .describedAs("node-id")
- .ofType(Integer.class);
- parser.accepts("store-name", "[REQUIRED] name of the store")
- .withRequiredArg()
- .describedAs("store-name")
+ .describedAs("output-dir")
.ofType(String.class);
- parser.accepts("skip-records", "number of records to skip [default: 0 i.e. none]")
+ parser.accepts("op", "Operation type (0 - gets keys [default], 1 - checks the keys")
.withRequiredArg()
+ .describedAs("op")
.ofType(Integer.class);
+ parser.accepts("num-keys", "Number of keys per store [ Default: 100 ]")
+ .withRequiredArg()
+ .describedAs("keys")
+ .ofType(Long.class);
OptionSet options = parser.parse(args);
@@ -56,11 +52,7 @@ public static void main(String args[]) throws IOException {
System.exit(0);
}
- Set<String> missing = CmdUtils.missing(options,
- "url",
- "first-id",
- "second-id",
- "store-name");
+ Set<String> missing = CmdUtils.missing(options, "url", "output-dir");
if(missing.size() > 0) {
System.err.println("Missing required arguments: " + Joiner.on(", ").join(missing));
parser.printHelpOn(System.err);
@@ -69,101 +61,113 @@ public static void main(String args[]) throws IOException {
// compulsory params
String url = (String) options.valueOf("url");
- Integer firstId = (Integer) options.valueOf("first-id");
- Integer secondId = (Integer) options.valueOf("second-id");
- String storeName = (String) options.valueOf("store-name");
-
- // optional params
- Integer skipRecords = CmdUtils.valueOf(options, "skip-records", 0);
+ String outputDirPath = (String) options.valueOf("output-dir");
+ int opType = CmdUtils.valueOf(options, "op", 0);
+ long numKeys = CmdUtils.valueOf(options, "num-keys", 100L);
- // Use admin client to get cluster / store definition
- AdminClient client = new AdminClient(url, new AdminClientConfig());
+ File outputDir = new File(outputDirPath);
- List<StoreDefinition> storeDefs = client.getRemoteStoreDefList(firstId).getValue();
- StoreDefinition storeDef = null;
- for(StoreDefinition def: storeDefs) {
- if(def.getName().compareTo(storeName) == 0) {
- storeDef = def;
- }
- }
-
- if(storeDef == null) {
- System.err.println("Store name mentioned not found");
+ if(!outputDir.exists()) {
+ outputDir.mkdirs();
+ } else if(!(outputDir.isDirectory() && outputDir.canWrite())) {
+ System.err.println("Cannot write to output directory " + outputDirPath);
parser.printHelpOn(System.err);
System.exit(1);
}
- // Find partitions which are replicated over to the other node
- Cluster cluster = client.getAdminClientCluster();
- Node firstNode = cluster.getNodeById(firstId), secondNode = cluster.getNodeById(secondId);
-
- RoutingStrategy strategy = new RoutingStrategyFactory().updateRoutingStrategy(storeDef,
- cluster);
-
- List<Integer> firstNodePartitionIds = firstNode.getPartitionIds();
- List<Integer> secondNodePartitionIds = secondNode.getPartitionIds();
-
- // This is list of partitions which we need to retrieve
- List<Integer> finalPartitionIds = new ArrayList<Integer>();
-
- for(Integer firstNodePartition: firstNodePartitionIds) {
- List<Integer> replicatingPartitionIds = strategy.getReplicatingPartitionList(firstNodePartition);
-
- // Check if replicating partition id is one of the partition ids
- for(Integer replicatingPartitionId: replicatingPartitionIds) {
- if(secondNodePartitionIds.contains(replicatingPartitionId)) {
- finalPartitionIds.add(firstNodePartition);
- break;
- }
- }
- }
-
- if(finalPartitionIds.size() == 0) {
- System.out.println("No partition found whose replica is on the other node");
- System.exit(0);
- }
- Iterator<Pair<ByteArray, Versioned<byte[]>>> iterator = client.fetchEntries(firstId,
- storeName,
- finalPartitionIds,
- null,
- false,
- skipRecords);
-
- // Get Socket store for other node
- SocketStoreFactory storeFactory = new ClientRequestExecutorPool(10, 10000, 10000, 64 * 1024);
- Store<ByteArray, byte[], byte[]> secondStore = null;
+ AdminClient adminClient = null;
try {
- secondStore = storeFactory.create(storeName,
- secondNode.getHost(),
- secondNode.getSocketPort(),
- RequestFormatType.VOLDEMORT_V3,
- RequestRoutingType.NORMAL);
-
- long totalKeyValues = 0, totalCorrect = 0;
- while(iterator.hasNext()) {
- Pair<ByteArray, Versioned<byte[]>> entry = iterator.next();
- List<Versioned<byte[]>> otherValues = secondStore.get(entry.getFirst(), null);
-
- totalKeyValues++;
- for(Versioned<byte[]> value: otherValues) {
- if(ByteUtils.compare(value.getValue(), entry.getSecond().getValue()) == 0) {
- totalCorrect++;
+ adminClient = new AdminClient(url, new AdminClientConfig().setMaxThreads(10));
+
+ // Get store definition meta-data from node 0
+ List<StoreDefinition> storeDefs = adminClient.getRemoteStoreDefList(0).getValue();
+ Cluster cluster = adminClient.getAdminClientCluster();
+
+ for(StoreDefinition storeDef: storeDefs) {
+ File storesKeyFile = new File(outputDir, storeDef.getName());
+ if(AdminClient.restoreStoreEngineBlackList.contains(storeDef.getType())) {
+ System.out.println("Ignoring store " + storeDef.getName());
+ continue;
+ } else {
+ System.out.println("Working on store " + storeDef.getName());
+ }
+ switch(opType) {
+ case 0:
+ default:
+ if(storesKeyFile.exists()) {
+ System.err.println("Key files for " + storeDef.getName()
+ + " already exists");
+ continue;
+ }
+ FileOutputStream writer = null;
+ try {
+ writer = new FileOutputStream(storesKeyFile);
+ Iterator<ByteArray> keys = adminClient.fetchKeys(0,
+ storeDef.getName(),
+ cluster.getNodeById(0)
+ .getPartitionIds(),
+ null,
+ false);
+ for(long keyId = 0; keyId < numKeys && keys.hasNext(); keyId++) {
+ ByteArray key = keys.next();
+ writer.write(key.length());
+ writer.write(key.get());
+ }
+
+ } finally {
+ if(writer != null)
+ writer.close();
+ }
+ break;
+ case 1:
+ if(!(storesKeyFile.exists() && storesKeyFile.canRead())) {
+ System.err.println("Could not find " + storeDef.getName()
+ + " file to check");
+ continue;
+ }
+ FileInputStream reader = null;
+ SocketStoreClientFactory socketFactory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(url));
+ StoreClient storeClient = socketFactory.getStoreClient(storeDef.getName());
+
+ DefaultSerializerFactory factory = new DefaultSerializerFactory();
+ Serializer<?> keySerializer = factory.getSerializer(storeDef.getKeySerializer());
+ long foundKeys = 0L;
+ long totalKeys = 0L;
+ try {
+ reader = new FileInputStream(storesKeyFile);
+ while(reader.available() != 0) {
+ int size = reader.read();
+
+ if(size <= 0) {
+ break;
+ }
+
+ // Read the key
+ byte[] key = new byte[size];
+ reader.read(key);
+
+ Versioned<Object> value = storeClient.get(keySerializer.toObject(key));
+ if(value != null) {
+ foundKeys++;
+ }
+ totalKeys++;
+
+ }
+ System.out.println("Found = " + foundKeys + " Total = " + totalKeys);
+ if(foundKeys > 0 && totalKeys > 0) {
+ System.out.println("%age found - " + (double) 100
+ * (foundKeys / totalKeys));
+ }
+ } finally {
+ if(reader != null)
+ reader.close();
+ }
break;
- }
}
-
- if(totalKeyValues % 1000 == 0)
- System.out.println("Final => Percent correct = "
- + (double) (totalCorrect / totalKeyValues) * 100);
}
- if(totalKeyValues > 0)
- System.out.println("Final => Percent correct = "
- + (double) (totalCorrect / totalKeyValues) * 100);
- else
- System.out.println("Final => Percent correct = 0");
} finally {
- if(secondStore != null)
- secondStore.close();
+ if(adminClient != null)
+ adminClient.stop();
}
}
}
@@ -38,6 +38,7 @@
import voldemort.server.VoldemortConfig;
import voldemort.store.StoreDefinition;
import voldemort.store.mysql.MysqlStorageConfiguration;
+import voldemort.store.views.ViewStorageConfiguration;
import voldemort.versioning.Occured;
import voldemort.versioning.VectorClock;
import voldemort.versioning.Versioned;
@@ -55,7 +56,8 @@
private static Logger logger = Logger.getLogger(RebalanceUtils.class);
- public final static List<String> rebalancingStoreEngineBlackList = Arrays.asList(MysqlStorageConfiguration.TYPE_NAME);
+ public final static List<String> rebalancingStoreEngineBlackList = Arrays.asList(MysqlStorageConfiguration.TYPE_NAME,
+ ViewStorageConfiguration.TYPE_NAME);
public static boolean containsNode(Cluster cluster, int nodeId) {
try {

0 comments on commit 5adf557

Please sign in to comment.