Permalink
Browse files

Merge branch 'master' into server-transforms

Conflicts:
	src/java/voldemort/store/invalidmetadata/InvalidMetadataCheckingStore.java
  • Loading branch information...
afeinberg committed Jun 23, 2010
2 parents 32c5055 + 99468d4 commit 1a4a1978541eb5f8d63922fc76c0dc091d449274
@@ -17,8 +17,11 @@
package voldemort.store.invalidmetadata;
import java.util.List;
+import java.util.Map;
import voldemort.VoldemortException;
+import voldemort.cluster.Node;
+import voldemort.routing.RoutingStrategy;
import voldemort.store.DelegatingStore;
import voldemort.store.InvalidMetadataException;
import voldemort.store.Store;
@@ -68,9 +71,23 @@ public boolean delete(ByteArray key, Version version) throws VoldemortException
return getInnerStore().delete(key, version);
}
+ @Override
+ public Map<ByteArray, List<Versioned<byte[]>>> getAll(Iterable<ByteArray> keys, Map<ByteArray, byte[]> transforms)
+ throws VoldemortException {
+ StoreUtils.assertValidKeys(keys);
+ RoutingStrategy routingStrategy = metadata.getRoutingStrategy(getName());
+ Node node = metadata.getCluster().getNodeById(nodeId);
+ for (ByteArray key: keys)
+ StoreUtils.assertValidMetadata(key,
+ routingStrategy,
+ node);
+
+ return getInnerStore().getAll(keys, transforms);
+ }
+
@Override
public void put(ByteArray key, Versioned<byte[]> value, byte[] transforms)
- throws VoldemortException {
+ throws VoldemortException {
StoreUtils.assertValidKey(key);
StoreUtils.assertValidMetadata(key,
metadata.getRoutingStrategy(getName()),
@@ -19,6 +19,7 @@
import java.util.Arrays;
import java.util.List;
+import com.google.common.collect.ImmutableList;
import junit.framework.TestCase;
import voldemort.ServerTestUtils;
import voldemort.cluster.Cluster;
@@ -138,7 +139,7 @@ private void doOperations(int nodeId,
if(containsNodeId(routingStrategy.routeRequest(key.get()), nodeId)) {
i++; // increment count
- switch(i % 3) {
+ switch(i % 4) {
case 0:
store.get(key, null);
break;
@@ -148,7 +149,9 @@ private void doOperations(int nodeId,
case 2:
store.put(key, new Versioned<byte[]>(value), null);
break;
-
+ case 3:
+ store.getAll(ImmutableList.of(key));
+ break;
}
}
}
@@ -0,0 +1,156 @@
+package voldemort.store.rebalancing;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import voldemort.ServerTestUtils;
+import voldemort.TestUtils;
+import voldemort.client.ClientConfig;
+import voldemort.client.SocketStoreClientFactory;
+import voldemort.client.StoreClient;
+import voldemort.client.protocol.admin.AdminClient;
+import voldemort.cluster.Cluster;
+import voldemort.cluster.Node;
+import voldemort.server.VoldemortConfig;
+import voldemort.server.VoldemortServer;
+import voldemort.utils.RebalanceUtils;
+import voldemort.versioning.VectorClock;
+import voldemort.versioning.Versioned;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.Assert.*;
+
+/**
+ * Test {@link RebootstrappingStore}
+ */
+public class RebootstrappingStoreTest {
+
+ private final static String STORE_NAME = "test";
+ private final static String STORES_XML = "test/common/voldemort/config/single-store.xml";
+
+ private final int[][] startCluster = new int[][] {{0, 1}, {}};
+
+ private Map<String, String> entries;
+ private Cluster cluster;
+ private List<VoldemortServer> servers;
+ private StoreClient<String, String> storeClient;
+
+ @Before
+ public void setUp() throws Exception {
+ entries = Maps.newHashMap();
+ entries.put("a", "1");
+ entries.put("b", "2");
+ cluster = ServerTestUtils.getLocalCluster(2, startCluster);
+ servers = Lists.newArrayList();
+ Properties props = new Properties();
+
+ for (Node node: cluster.getNodes()) {
+ VoldemortConfig config = ServerTestUtils.createServerConfig(false,
+ node.getId(),
+ TestUtils.createTempDir()
+ .getAbsolutePath(),
+ null,
+ STORES_XML,
+ props);
+ servers.add(ServerTestUtils.startVoldemortServer(config, cluster));
+ }
+
+ String bootstrapUrl = cluster.getNodeById(0).getSocketUrl().toString();
+ storeClient = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl))
+ .getStoreClient(STORE_NAME);
+
+ for (Map.Entry<String, String> entry: entries.entrySet())
+ storeClient.put(entry.getKey(), entry.getValue());
+ }
+
+ @After
+ public void tearDown() {
+ if (servers != null)
+ for (VoldemortServer server: servers)
+ server.stop();
+ }
+
+ public void rebalance() {
+ assert servers != null && servers.size() > 1;
+
+ VoldemortConfig config = servers.get(0).getVoldemortConfig();
+ AdminClient adminClient = RebalanceUtils.createTempAdminClient(config, cluster, 2, 4);
+ int req = adminClient.migratePartitions(0,
+ 1,
+ STORE_NAME,
+ ImmutableList.of(0, 1),
+ null);
+ adminClient.waitForCompletion(1, req, 5, TimeUnit.SECONDS);
+ Versioned<Cluster> versionedCluster = adminClient.getRemoteCluster(0);
+ Node node0 = versionedCluster.getValue().getNodeById(0);
+ Node node1 = versionedCluster.getValue().getNodeById(1);
+ Node newNode0 = new Node(node0.getId(),
+ node0.getHost(),
+ node0.getHttpPort(),
+ node0.getSocketPort(),
+ node0.getAdminPort(),
+ ImmutableList.<Integer>of());
+ Node newNode1 = new Node(node1.getId(),
+ node1.getHost(),
+ node1.getHttpPort(),
+ node1.getSocketPort(),
+ node1.getAdminPort(),
+ ImmutableList.of(0, 1));
+ int deleted = adminClient.deletePartitions(0, STORE_NAME, ImmutableList.of(0, 1), null);
+ assert deleted > 0;
+ Cluster newCluster = new Cluster(cluster.getName(), ImmutableList.of(newNode0, newNode1));
+ for (Node node: cluster.getNodes()) {
+ VectorClock clock = (VectorClock) versionedCluster.getVersion();
+ clock.incrementVersion(node.getId(), System.currentTimeMillis());
+
+ adminClient.updateRemoteCluster(node.getId(), newCluster, clock);
+ }
+ }
+
+ @Test
+ public void testGet() {
+ Versioned<String> r0 = storeClient.get("a");
+ Versioned<String> r1 = storeClient.get("b");
+ assertEquals("1", r0.getValue());
+ assertEquals("2", r1.getValue());
+ rebalance();
+ r0 = storeClient.get("a");
+ r1 = storeClient.get("b");
+ assertEquals("#1 get() okay after re-bootstrap", "1", r0.getValue());
+ assertEquals("#2 get() okay after re-bootstrap", "2", r1.getValue());
+ }
+
+ @Test
+ public void testPut() {
+ Versioned<String> r0 = storeClient.get("a");
+ assertEquals("1", r0.getValue());
+ rebalance();
+ storeClient.put("c", "3");
+ assertEquals("put() okay after re-bootstrap", "3", storeClient.get("c").getValue());
+ }
+
+ @Test
+ public void testDelete() {
+
+ }
+
+ @Test
+ public void testGetAll() {
+ Versioned<String> r0 = storeClient.get("a");
+ assertEquals("1", r0.getValue());
+ rebalance();
+ Map<String, Versioned<String>> res = storeClient.getAll(ImmutableList.of("a", "b"));
+
+ assertTrue("getAll() contains a", res.containsKey("a"));
+ assertTrue("getAll() contains b", res.containsKey("b"));
+ assertEquals("getAll() returns correct value #1", "1", res.get("a").getValue());
+ assertEquals("getAll() returns correct value #2", "2", res.get("b").getValue());
+ }
+}

0 comments on commit 1a4a197

Please sign in to comment.