use of voldemort.versioning.VectorClock in project voldemort by voldemort.
the class AdminCommandStream method readEntriesBinary.
private static Iterator<Pair<ByteArray, Versioned<byte[]>>> readEntriesBinary(File inputDir, String storeName) throws IOException {
File inputFile = new File(inputDir, storeName + ".entries");
if (!inputFile.exists()) {
throw new FileNotFoundException("File " + inputFile.getAbsolutePath() + " does not exist!");
}
final DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(inputFile)));
return new AbstractIterator<Pair<ByteArray, Versioned<byte[]>>>() {
@Override
protected Pair<ByteArray, Versioned<byte[]>> computeNext() {
try {
int length = dis.readInt();
byte[] keyBytes = new byte[length];
ByteUtils.read(dis, keyBytes);
length = dis.readInt();
byte[] versionBytes = new byte[length];
ByteUtils.read(dis, versionBytes);
length = dis.readInt();
byte[] valueBytes = new byte[length];
ByteUtils.read(dis, valueBytes);
ByteArray key = new ByteArray(keyBytes);
VectorClock version = new VectorClock(versionBytes);
Versioned<byte[]> value = new Versioned<byte[]>(valueBytes, version);
return new Pair<ByteArray, Versioned<byte[]>>(key, value);
} catch (EOFException e) {
try {
dis.close();
} catch (IOException ie) {
ie.printStackTrace();
}
return endOfData();
} catch (IOException e) {
try {
dis.close();
} catch (IOException ie) {
ie.printStackTrace();
}
throw new VoldemortException("Error reading from input file ", e);
}
}
};
}
use of voldemort.versioning.VectorClock in project voldemort by voldemort.
the class RebootstrappingStoreTest method rebalance.
public void rebalance() {
assert servers != null && servers.size() > 1;
VoldemortConfig config = servers.get(0).getVoldemortConfig();
AdminClient adminClient = AdminClient.createTempAdminClient(config, cluster, 4);
List<Integer> partitionIds = ImmutableList.of(0, 1);
int req = adminClient.storeMntOps.migratePartitions(0, 1, STORE_NAME, partitionIds, null, null);
adminClient.rpcOps.waitForCompletion(1, req, 5, TimeUnit.SECONDS);
Versioned<Cluster> versionedCluster = adminClient.metadataMgmtOps.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));
long deleted = adminClient.storeMntOps.deletePartitions(0, STORE_NAME, ImmutableList.of(0, 1), null);
assert deleted > 0;
Cluster newCluster = new Cluster(cluster.getName(), ImmutableList.of(newNode0, newNode1), Lists.newArrayList(cluster.getZones()));
for (Node node : cluster.getNodes()) {
VectorClock clock = (VectorClock) versionedCluster.getVersion();
clock.incrementVersion(node.getId(), System.currentTimeMillis());
adminClient.metadataMgmtOps.updateRemoteCluster(node.getId(), newCluster, clock);
}
}
use of voldemort.versioning.VectorClock in project voldemort by voldemort.
the class RedirectingStoreTest method testProxyPuts.
@Test
public void testProxyPuts() {
List<ByteArray> testPrimaryKeys = new ArrayList<ByteArray>(this.proxyPutTestPrimaryEntries.keySet());
List<ByteArray> testSecondaryKeys = new ArrayList<ByteArray>(this.proxyPutTestSecondaryEntries.keySet());
final RedirectingStore redirectingStoreNode2 = getRedirectingStore(2, servers[2].getMetadataStore(), "test");
final RedirectingStore redirectingStoreNode0 = getRedirectingStore(0, servers[0].getMetadataStore(), "test");
final Store<ByteArray, byte[], byte[]> socketStoreNode2 = redirectingStoreNode2.getRedirectingSocketStore("test", 2);
final Store<ByteArray, byte[], byte[]> socketStoreNode0 = redirectingStoreNode0.getRedirectingSocketStore("test", 0);
// 1. Make sure the vector clocks make sense.. Read through Node 2 and
// proxy getting from Node 0 and issue a write based off that,
// incrementing the clock for Node 2 and make sure there is no
// ObsoleteVersionException at both Node 0 and
// Node 2.
ByteArray secondaryKey = testSecondaryKeys.get(0);
VectorClock clock1 = ((VectorClock) redirectingStoreNode2.getVersions(secondaryKey).get(0)).incremented(2, System.currentTimeMillis());
try {
redirectingStoreNode2.put(secondaryKey, Versioned.value("write-through".getBytes("UTF-8"), clock1), null);
} catch (Exception e) {
fail("Unexpected error in testing write through proxy put");
e.printStackTrace();
}
waitForProxyPutsToDrain(redirectingStoreNode2);
assertTrue("Unexpected failures in proxy put", redirectingStoreNode2.getProxyPutStats().getNumProxyPutFailures() == 0);
assertEquals("Unexpected value in Node 2", "write-through", new String(socketStoreNode2.get(secondaryKey, null).get(0).getValue()));
assertTrue("Proxy write not seen on proxy node 0", "write-through".equals(new String(socketStoreNode0.get(secondaryKey, null).get(0).getValue())));
// Also test that if put fails locally, proxy put is not attempted.
try {
redirectingStoreNode2.put(secondaryKey, Versioned.value("write-through-updated".getBytes("UTF-8"), clock1), null);
fail("Should have thrown OVE");
} catch (ObsoleteVersionException ove) {
// Expected
} catch (Exception e) {
fail("Unexpected error in testing write through proxy put");
e.printStackTrace();
}
waitForProxyPutsToDrain(redirectingStoreNode2);
assertFalse("Proxy write not seen on proxy node 0", "write-through-updated".equals(new String(socketStoreNode0.get(secondaryKey, null).get(0).getValue())));
// 2. Make sure if the proxy node is still a replica, we don't issue
// proxy puts. Node 2 -> Node 0 on partition 0, for which Node 0 is
// still a replica
ByteArray primaryKey = testPrimaryKeys.get(0);
VectorClock clock2 = ((VectorClock) redirectingStoreNode2.getVersions(primaryKey).get(0)).incremented(2, System.currentTimeMillis());
try {
redirectingStoreNode2.put(primaryKey, Versioned.value("write-through".getBytes("UTF-8"), clock2), null);
} catch (Exception e) {
fail("Unexpected error in testing write through proxy put");
e.printStackTrace();
}
waitForProxyPutsToDrain(redirectingStoreNode2);
assertEquals("Unexpected value in Node 2", "write-through", new String(socketStoreNode2.get(primaryKey, null).get(0).getValue()));
assertFalse("Proxy write seen on proxy node which is a replica", "write-through".equals(new String(socketStoreNode0.get(primaryKey, null).get(0).getValue())));
// generate OVE.
try {
redirectingStoreNode2.put(primaryKey, Versioned.value("write-through".getBytes("UTF-8"), clock2), null);
fail("Should have thrown OVE");
} catch (ObsoleteVersionException ove) {
// Expected
} catch (Exception e) {
fail("Unexpected error in testing write through proxy put");
e.printStackTrace();
}
}
use of voldemort.versioning.VectorClock in project voldemort by voldemort.
the class FileBackedCachingStorageEngineTest method testGetAll.
@Override
@Test
public void testGetAll() throws Exception {
Store<ByteArray, byte[], byte[]> store = getStore();
int putCount = 10;
List<ByteArray> keys = getKeys(putCount);
List<byte[]> values = getValues(putCount);
assertEquals(putCount, values.size());
VectorClock clock = new VectorClock();
for (int i = 0; i < putCount; i++) {
store.put(keys.get(i), new Versioned<byte[]>(values.get(i), clock), null);
clock = clock.incremented(0, System.currentTimeMillis());
}
int countForGet = putCount / 2;
List<ByteArray> keysForGet = keys.subList(0, countForGet);
List<byte[]> valuesForGet = values.subList(0, countForGet);
Map<ByteArray, List<Versioned<byte[]>>> result = store.getAll(keysForGet, null);
assertGetAllValues(keysForGet, valuesForGet, result);
}
use of voldemort.versioning.VectorClock in project voldemort by voldemort.
the class FileBackedCachingStorageEngineTest method testDelete.
@Override
public void testDelete() {
ByteArray key = getKey();
Store<ByteArray, byte[], byte[]> store = getStore();
VectorClock c1 = getClock(1, 1);
byte[] value = getValue();
// can't delete something that isn't there
assertTrue(!store.delete(key, c1));
store.put(key, new Versioned<byte[]>(value, c1), null);
assertEquals(1, store.get(key, null).size());
// now delete that version too
assertTrue("Delete failed!", store.delete(key, c1));
assertEquals(0, store.get(key, null).size());
}
Aggregations