* read-repair
*/
@Test
public void testMissingKeysAreAddedToNodeWhenDoingReadRepair() throws Exception {
ByteArray key = TestUtils.toByteArray("key");
byte[] value = "foo".getBytes();
Cluster cluster = VoldemortTestConstants.getThreeNodeCluster();
StoreDefinition storeDef = ServerTestUtils.getStoreDef("test",
3,
3,
3,
2,
2,
RoutingStrategyType.CONSISTENT_STRATEGY);
Map<Integer, Store<ByteArray, byte[], byte[]>> subStores = Maps.newHashMap();
for(int a = 0; a < 3; a++) {
int id = Iterables.get(cluster.getNodes(), a).getId();
InMemoryStorageEngine<ByteArray, byte[], byte[]> subStore = new InMemoryStorageEngine<ByteArray, byte[], byte[]>("test");
subStores.put(id, subStore);
}
FailureDetectorConfig failureDetectorConfig = new FailureDetectorConfig().setImplementationClassName(failureDetectorClass.getName())
.setBannagePeriod(1000)
.setCluster(cluster)
.setStoreVerifier(create(subStores))
.setTime(time);
failureDetector = create(failureDetectorConfig, false);
routedStoreThreadPool = Executors.newFixedThreadPool(1);
RoutedStoreFactory routedStoreFactory = new RoutedStoreFactory(routedStoreThreadPool);
RoutedStore store = routedStoreFactory.create(cluster,
storeDef,
subStores,
failureDetector,
new RoutedStoreConfig().setTimeoutConfig(new TimeoutConfig(1000L,
false)));
recordException(failureDetector, Iterables.get(cluster.getNodes(), 0));
store.put(key, new Versioned<byte[]>(value), null);
recordSuccess(failureDetector, Iterables.get(cluster.getNodes(), 0));
time.sleep(2000);
assertEquals(2, store.get(key, null).size());
// Last get should have repaired the missing key from node 0 so all
// stores should now return a value
assertEquals(3, store.get(key, null).size());
ByteArray anotherKey = TestUtils.toByteArray("anotherKey");
// Try again, now use getAll to read repair
recordException(failureDetector, Iterables.get(cluster.getNodes(), 0));
store.put(anotherKey, new Versioned<byte[]>(value), null);
recordSuccess(failureDetector, Iterables.get(cluster.getNodes(), 0));
assertEquals(2, store.getAll(Arrays.asList(anotherKey), null).get(anotherKey).size());