Permalink
Browse files

Code refactor. StoreClient interface resumed to original. Added a Vie…

…wStoreClient and ViewUpdateAction interface for views
  • Loading branch information...
nehanarkhede committed Jun 14, 2010
1 parent 3ebfcc4 commit 05576553db376090e7b6bf6cdb507da2f2050b5e
Showing with 1,060 additions and 305 deletions.
  1. +3 −3 contrib/ec2-testing/test/voldemort/utils/Ec2FailureDetectorTest.java
  2. +4 −4 contrib/mongodb/example/MongoDBClient.java
  3. +1 −1 example/java/voldemort/examples/ClientExample.java
  4. +49 −14 src/java/voldemort/VoldemortClientShell.java
  5. +14 −4 src/java/voldemort/client/AbstractStoreClientFactory.java
  6. +9 −79 src/java/voldemort/client/DefaultStoreClient.java
  7. +330 −0 src/java/voldemort/client/DefaultViewStoreClient.java
  8. +12 −3 src/java/voldemort/client/MockStoreClientFactory.java
  9. +3 −38 src/java/voldemort/client/StoreClient.java
  10. +33 −5 src/java/voldemort/client/StoreClientFactory.java
  11. +2 −2 src/java/voldemort/client/UpdateAction.java
  12. +206 −0 src/java/voldemort/client/ViewStoreClient.java
  13. +44 −0 src/java/voldemort/client/ViewUpdateAction.java
  14. +1 −1 src/java/voldemort/server/http/gui/QueryServlet.java
  15. +16 −3 test/common/voldemort/StaticStoreClientFactory.java
  16. +2 −2 test/integration/voldemort/TestClientShutdown.java
  17. +2 −2 test/integration/voldemort/performance/AbstractLoadTestHarness.java
  18. +2 −3 test/integration/voldemort/performance/LocalDirectLoadTest.java
  19. +2 −3 test/integration/voldemort/performance/LocalRoutedStoreLoadTest.java
  20. +1 −1 test/integration/voldemort/performance/RemoteDataGenerator.java
  21. +1 −1 test/integration/voldemort/performance/RemoteHttpStoreLoadTest.java
  22. +26 −18 test/integration/voldemort/performance/RemoteTest.java
  23. +1 −1 test/integration/voldemort/performance/SemiLocalHttpStoreLoadTest.java
  24. +34 −12 test/integration/voldemort/performance/benchmark/Benchmark.java
  25. +22 −0 test/integration/voldemort/performance/benchmark/DbWrapper.java
  26. +192 −0 test/integration/voldemort/performance/benchmark/VoldemortViewWrapper.java
  27. +19 −73 test/integration/voldemort/performance/benchmark/VoldemortWrapper.java
  28. +8 −8 test/integration/voldemort/performance/benchmark/Workload.java
  29. +2 −2 test/unit/voldemort/client/AbstractStoreClientFactoryTest.java
  30. +1 −1 test/unit/voldemort/client/AdminServiceBasicTest.java
  31. +1 −1 test/unit/voldemort/client/DefaultStoreClientTest.java
  32. +8 −8 test/unit/voldemort/client/rebalance/AbstractRebalanceTest.java
  33. +1 −1 test/unit/voldemort/server/EndToEndTest.java
  34. +1 −1 test/unit/voldemort/store/compress/CompressingStoreTest.java
  35. +7 −10 test/unit/voldemort/store/views/ViewTransformsTest.java
@@ -70,7 +70,7 @@
private static Map<String, Integer> nodeIds;
private FailureDetector failureDetector;
- private StoreClient<String, String, String> store;
+ private StoreClient<String, String> store;
private static final Logger logger = Logger.getLogger(Ec2FailureDetectorTest.class);
@@ -233,11 +233,11 @@ public void run() {
assertEquals(hostNamePairs.size(), failureDetector.getAvailableNodeCount());
}
- private void test(StoreClient<String, String, String> store) {
+ private void test(StoreClient<String, String> store) {
test(store, 1000);
}
- private void test(StoreClient<String, String, String> store, int tests) {
+ private void test(StoreClient<String, String> store, int tests) {
for(int i = 0; i < tests; i++) {
try {
store.get("test_" + i);
@@ -38,7 +38,7 @@ public MongoDBClient(String bootstrapUrl) {
public long multiWriteLarge(int count, String keyRoot) {
- StoreClient<String, Doc, String> client = factory.getStoreClient("test");
+ StoreClient<String, Doc> client = factory.getStoreClient("test");
long start = System.currentTimeMillis();
@@ -58,7 +58,7 @@ public long multiWriteLarge(int count, String keyRoot) {
public long multiWrite(int count, String keyRoot) {
- StoreClient<String, Doc, String> client = factory.getStoreClient("test");
+ StoreClient<String, Doc> client = factory.getStoreClient("test");
long start = System.currentTimeMillis();
@@ -78,7 +78,7 @@ public long multiWrite(int count, String keyRoot) {
public long multiRead(int count, String keyRoot) {
- StoreClient<String, Doc, String> client = factory.getStoreClient("test");
+ StoreClient<String, Doc> client = factory.getStoreClient("test");
long start = System.currentTimeMillis();
@@ -116,7 +116,7 @@ public String getRandomKey(int n) {
public void simple() {
- StoreClient<String, Doc, String> client = factory.getStoreClient("test");
+ StoreClient<String, Doc> client = factory.getStoreClient("test");
Versioned<Doc> v = client.get("key");
@@ -30,7 +30,7 @@ public static void main(String[] args) {
String bootstrapUrl = "tcp://localhost:6666";
StoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
- StoreClient<String, String, String> client = factory.getStoreClient("my_store_name");
+ StoreClient<String, String> client = factory.getStoreClient("my_store_name");
// get the value
Versioned<String> version = client.get("some_key");
@@ -30,6 +30,7 @@
import voldemort.client.ClientConfig;
import voldemort.client.DefaultStoreClient;
+import voldemort.client.DefaultViewStoreClient;
import voldemort.client.SocketStoreClientFactory;
import voldemort.client.StoreClientFactory;
import voldemort.client.protocol.RequestFormatType;
@@ -50,20 +51,31 @@
private static final String PROMPT = "> ";
- private static DefaultStoreClient<Object, Object, Object> client;
+ private static DefaultStoreClient<Object, Object> client;
+ private static DefaultViewStoreClient<Object, Object, Object> viewClient;
+ private static boolean isView = false;
public static void main(String[] args) throws Exception {
if(args.length < 2 || args.length > 3)
- Utils.croak("USAGE: java VoldemortClientShell store_name bootstrap_url [command_file]");
+ Utils.croak("USAGE: java VoldemortClientShell store_name bootstrap_url is_view [command_file]");
String storeName = args[0];
String bootstrapUrl = args[1];
+
+ if(args.length > 2) {
+ String viewString = args[2];
+ if(!(viewString.equalsIgnoreCase("true") || viewString.equalsIgnoreCase("false")))
+ Utils.croak("is_view should be either true or false");
+ if(viewString.equalsIgnoreCase("true"))
+ isView = true;
+ }
+
String commandsFileName = "";
BufferedReader fileReader = null;
BufferedReader inputReader = null;
try {
- if(args.length == 3) {
- commandsFileName = args[2];
+ if(args.length == 4) {
+ commandsFileName = args[3];
fileReader = new BufferedReader(new FileReader(commandsFileName));
}
@@ -77,7 +89,10 @@ public static void main(String[] args) throws Exception {
StoreClientFactory factory = new SocketStoreClientFactory(clientConfig);
try {
- client = (DefaultStoreClient<Object, Object, Object>) factory.getStoreClient(storeName);
+ if(!isView)
+ client = (DefaultStoreClient<Object, Object>) factory.getStoreClient(storeName);
+ else
+ viewClient = (DefaultViewStoreClient<Object, Object, Object>) factory.getViewStoreClient(storeName);
} catch(Exception e) {
Utils.croak("Could not connect to server: " + e.getMessage());
}
@@ -104,10 +119,14 @@ private static void processCommands(StoreClientFactory factory,
JsonReader jsonReader = new JsonReader(new StringReader(line.substring("put".length())));
Object key = tightenNumericTypes(jsonReader.read());
Object value = tightenNumericTypes(jsonReader.read());
- if(jsonReader.hasMore())
- client.put(key, value, tightenNumericTypes(jsonReader.read()));
- else
+ if(isView) {
+ if(jsonReader.hasMore())
+ viewClient.put(key, value, tightenNumericTypes(jsonReader.read()));
+ else
+ viewClient.put(key, value);
+ } else {
client.put(key, value);
+ }
} else if(line.toLowerCase().startsWith("getall")) {
JsonReader jsonReader = new JsonReader(new StringReader(line.substring("getall".length())));
List<Object> keys = new ArrayList<Object>();
@@ -117,7 +136,11 @@ private static void processCommands(StoreClientFactory factory,
} catch(EndOfFileException e) {
// this is okay, just means we are done reading
}
- Map<Object, Versioned<Object>> vals = client.getAll(keys);
+ Map<Object, Versioned<Object>> vals;
+ if(isView)
+ vals = viewClient.getAll(keys);
+ else
+ vals = client.getAll(keys);
if(vals.size() > 0) {
for(Map.Entry<Object, Versioned<Object>> entry: vals.entrySet()) {
System.out.print(entry.getKey());
@@ -130,17 +153,29 @@ private static void processCommands(StoreClientFactory factory,
} else if(line.toLowerCase().startsWith("get")) {
JsonReader jsonReader = new JsonReader(new StringReader(line.substring("get".length())));
Object key = tightenNumericTypes(jsonReader.read());
- if(jsonReader.hasMore())
- printVersioned(client.get(key, tightenNumericTypes(jsonReader.read())));
- else
+ if(isView) {
+ if(jsonReader.hasMore())
+ printVersioned(viewClient.get(key,
+ tightenNumericTypes(jsonReader.read())));
+ else
+ printVersioned(viewClient.get(key));
+ } else {
printVersioned(client.get(key));
+ }
} else if(line.toLowerCase().startsWith("delete")) {
JsonReader jsonReader = new JsonReader(new StringReader(line.substring("delete".length())));
- client.delete(tightenNumericTypes(jsonReader.read()));
+ if(isView)
+ viewClient.delete(tightenNumericTypes(jsonReader.read()));
+ else
+ client.delete(tightenNumericTypes(jsonReader.read()));
} else if(line.startsWith("preflist")) {
JsonReader jsonReader = new JsonReader(new StringReader(line.substring("preflist".length())));
Object key = tightenNumericTypes(jsonReader.read());
- printNodeList(client.getResponsibleNodes(key), factory.getFailureDetector());
+ if(isView)
+ printNodeList(viewClient.getResponsibleNodes(key),
+ factory.getFailureDetector());
+ else
+ printNodeList(client.getResponsibleNodes(key), factory.getFailureDetector());
} else if(line.startsWith("help")) {
System.out.println("Commands:");
System.out.println("put key value -- Associate the given value with the key.");
@@ -116,14 +116,24 @@ public AbstractStoreClientFactory(ClientConfig config) {
}
}
- public <K, V, T> StoreClient<K, V, T> getStoreClient(String storeName) {
+ public <K, V> StoreClient<K, V> getStoreClient(String storeName) {
return getStoreClient(storeName, null);
}
- public <K, V, T> StoreClient<K, V, T> getStoreClient(String storeName,
- InconsistencyResolver<Versioned<V>> resolver) {
+ public <K, V, T> ViewStoreClient<K, V, T> getViewStoreClient(String storeName) {
+ return getViewStoreClient(storeName, null);
+ }
+
+ public <K, V> StoreClient<K, V> getStoreClient(String storeName,
+ InconsistencyResolver<Versioned<V>> resolver) {
+
+ return new DefaultStoreClient<K, V>(storeName, resolver, this, 3);
+ }
+
+ public <K, V, T> ViewStoreClient<K, V, T> getViewStoreClient(String storeName,
+ InconsistencyResolver<Versioned<V>> resolver) {
- return new DefaultStoreClient<K, V, T>(storeName, resolver, this, 3);
+ return new DefaultViewStoreClient<K, V, T>(storeName, resolver, this, 3);
}
@SuppressWarnings("unchecked")
@@ -53,15 +53,15 @@
*/
@Threadsafe
@JmxManaged(description = "A voldemort client")
-public class DefaultStoreClient<K, V, T> implements StoreClient<K, V, T> {
+public class DefaultStoreClient<K, V> implements StoreClient<K, V> {
private final Logger logger = Logger.getLogger(DefaultStoreClient.class);
private final StoreClientFactory storeFactory;
private final int metadataRefreshAttempts;
private final String storeName;
private final InconsistencyResolver<Versioned<V>> resolver;
- private volatile Store<K, V, T> store;
+ private volatile Store<K, V, Object> store;
public DefaultStoreClient(String storeName,
InconsistencyResolver<Versioned<V>> resolver,
@@ -100,15 +100,15 @@ public boolean delete(K key, Version version) {
}
public V getValue(K key, V defaultValue) {
- Versioned<V> versioned = getWithDefaultValue(key, null, null);
+ Versioned<V> versioned = get(key);
if(versioned == null)
return defaultValue;
else
return versioned.getValue();
}
public V getValue(K key) {
- Versioned<V> returned = getWithDefaultValue(key, null, null);
+ Versioned<V> returned = get(key, null);
if(returned == null)
return null;
else
@@ -128,19 +128,6 @@ public V getValue(K key) {
+ " metadata refresh attempts failed.");
}
- private Versioned<V> getWithDefaultValue(K key, Versioned<V> defaultValue, T transforms) {
- for(int attempts = 0; attempts < this.metadataRefreshAttempts; attempts++) {
- try {
- List<Versioned<V>> items = store.get(key, transforms);
- return getItemOrThrow(key, defaultValue, items);
- } catch(InvalidMetadataException e) {
- bootStrap();
- }
- }
- throw new VoldemortException(this.metadataRefreshAttempts
- + " metadata refresh attempts failed.");
- }
-
private List<Version> getVersions(K key) {
for(int attempts = 0; attempts < this.metadataRefreshAttempts; attempts++) {
try {
@@ -163,34 +150,8 @@ else if(items.size() == 1)
+ ") = " + items, items);
}
- public Versioned<V> get(K key, T transforms) {
- return getWithDefaultValue(key, null, transforms);
- }
-
public Versioned<V> get(K key) {
- return getWithDefaultValue(key, null, null);
- }
-
- public Map<K, Versioned<V>> getAll(Iterable<K> keys, Map<K, T> transforms) {
- Map<K, List<Versioned<V>>> items = null;
- for(int attempts = 0;; attempts++) {
- if(attempts >= this.metadataRefreshAttempts)
- throw new VoldemortException(this.metadataRefreshAttempts
- + " metadata refresh attempts failed.");
- try {
- items = store.getAll(keys, transforms);
- break;
- } catch(InvalidMetadataException e) {
- bootStrap();
- }
- }
- Map<K, Versioned<V>> result = Maps.newHashMapWithExpectedSize(items.size());
-
- for(Entry<K, List<Versioned<V>>> mapEntry: items.entrySet()) {
- Versioned<V> value = getItemOrThrow(mapEntry.getKey(), null, mapEntry.getValue());
- result.put(mapEntry.getKey(), value);
- }
- return result;
+ return get(key, null);
}
public Map<K, Versioned<V>> getAll(Iterable<K> keys) {
@@ -215,23 +176,6 @@ else if(items.size() == 1)
return result;
}
- public void put(K key, V value, T transforms) {
- List<Version> versions = getVersions(key);
- Versioned<V> versioned;
- if(versions.isEmpty())
- versioned = Versioned.value(value, new VectorClock());
- else if(versions.size() == 1)
- versioned = Versioned.value(value, versions.get(0));
- else {
- versioned = get(key, (Versioned<V>) null);
- if(versioned == null)
- versioned = Versioned.value(value, new VectorClock());
- else
- versioned.setObject(value);
- }
- put(key, versioned, transforms);
- }
-
public void put(K key, V value) {
List<Version> versions = getVersions(key);
Versioned<V> versioned;
@@ -240,13 +184,13 @@ public void put(K key, V value) {
else if(versions.size() == 1)
versioned = Versioned.value(value, versions.get(0));
else {
- versioned = get(key, (T) null);
+ versioned = get(key, null);
if(versioned == null)
versioned = Versioned.value(value, new VectorClock());
else
versioned.setObject(value);
}
- put(key, versioned, null);
+ put(key, versioned);
}
public boolean putIfNotObsolete(K key, Versioned<V> versioned) {
@@ -258,21 +202,7 @@ public boolean putIfNotObsolete(K key, Versioned<V> versioned) {
}
}
- public void put(K key, Versioned<V> versioned, T transforms) throws ObsoleteVersionException {
- for(int attempts = 0; attempts < this.metadataRefreshAttempts; attempts++) {
- try {
- store.put(key, versioned, transforms);
- return;
- } catch(InvalidMetadataException e) {
- bootStrap();
- }
- }
- throw new VoldemortException(this.metadataRefreshAttempts
- + " metadata refresh attempts failed.");
- }
-
public void put(K key, Versioned<V> versioned) throws ObsoleteVersionException {
-
for(int attempts = 0; attempts < this.metadataRefreshAttempts; attempts++) {
try {
store.put(key, versioned, null);
@@ -285,11 +215,11 @@ public void put(K key, Versioned<V> versioned) throws ObsoleteVersionException {
+ " metadata refresh attempts failed.");
}
- public boolean applyUpdate(UpdateAction<K, V, T> action) {
+ public boolean applyUpdate(UpdateAction<K, V> action) {
return applyUpdate(action, 3);
}
- public boolean applyUpdate(UpdateAction<K, V, T> action, int maxTries) {
+ public boolean applyUpdate(UpdateAction<K, V> action, int maxTries) {
boolean success = false;
try {
for(int i = 0; i < maxTries; i++) {
Oops, something went wrong.

0 comments on commit 0557655

Please sign in to comment.