use of voldemort.versioning.Version in project voldemort by voldemort.
the class KratiStorageEngine method delete.
@Override
public boolean delete(ByteArray key, Version maxVersion) throws VoldemortException {
StoreUtils.assertValidKey(key);
synchronized (this.locks.lockFor(key.get())) {
if (maxVersion == null) {
try {
return datastore.delete(key.get());
} catch (Exception e) {
logger.error("Failed to delete key: ", e);
throw new VoldemortException("Failed to delete key: " + key, e);
}
}
List<Versioned<byte[]>> returnedValuesList = this.get(key, null);
// Case if there is nothing to delete
if (returnedValuesList.size() == 0) {
return false;
}
Iterator<Versioned<byte[]>> iter = returnedValuesList.iterator();
while (iter.hasNext()) {
Versioned<byte[]> currentValue = iter.next();
Version currentVersion = currentValue.getVersion();
if (currentVersion.compare(maxVersion) == Occurred.BEFORE) {
iter.remove();
}
}
try {
if (returnedValuesList.size() == 0)
return datastore.delete(key.get());
else
return datastore.put(key.get(), assembleValues(returnedValuesList));
} catch (Exception e) {
String message = "Failed to delete key " + key;
logger.error(message, e);
throw new VoldemortException(message, e);
}
}
}
use of voldemort.versioning.Version in project voldemort by voldemort.
the class R2Store method parseGetVersionResponse.
private List<Version> parseGetVersionResponse(ByteString entity) {
byte[] bytes = new byte[entity.length()];
entity.copyBytes(bytes, 0);
String vectorClockListStr = new String(bytes);
List<Version> vectorClockList = RestUtils.deserializeVectorClocks(vectorClockListStr);
return vectorClockList;
}
use of voldemort.versioning.Version in project voldemort by voldemort.
the class R2Store method getVersions.
@Override
public List<Version> getVersions(ByteArray key) {
List<Version> resultList = new ArrayList<Version>();
String base64Key = RestUtils.encodeVoldemortKey(key.get());
RestRequestBuilder rb = null;
try {
rb = new RestRequestBuilder(new URI(this.restBootstrapURL + "/" + getName() + "/" + base64Key));
String timeoutStr = Long.toString(this.config.getTimeoutConfig().getOperationTimeout(VoldemortOpCode.GET_VERSION_OP_CODE));
rb.setHeader(RestMessageHeaders.X_VOLD_GET_VERSION, "true");
RestResponse response = fetchGetResponse(rb, timeoutStr);
final ByteString entity = response.getEntity();
if (entity != null) {
resultList = parseGetVersionResponse(entity);
} else {
if (logger.isDebugEnabled()) {
logger.debug("Did not get any response!");
}
}
} catch (ExecutionException e) {
if (e.getCause() instanceof RestException) {
RestException exception = (RestException) e.getCause();
if (logger.isDebugEnabled()) {
logger.debug("REST EXCEPTION STATUS : " + exception.getResponse().getStatus());
}
} else {
throw new VoldemortException("Unknown HTTP request execution exception: " + e.getMessage(), e);
}
} catch (InterruptedException e) {
if (logger.isDebugEnabled()) {
logger.debug("Operation interrupted : " + e.getMessage(), e);
}
throw new VoldemortException("Operation interrupted exception: " + e.getMessage(), e);
} catch (URISyntaxException e) {
throw new VoldemortException("Illegal HTTP URL" + e.getMessage(), e);
}
return resultList;
}
use of voldemort.versioning.Version in project voldemort by voldemort.
the class SampleRESTClient method main.
public static void main(String[] args) {
// Create the client
Properties props = new Properties();
props.setProperty(ClientConfig.BOOTSTRAP_URLS_PROPERTY, "http://localhost:8080");
props.setProperty(ClientConfig.ROUTING_TIMEOUT_MS_PROPERTY, "1500");
RESTClientFactoryConfig mainConfig = new RESTClientFactoryConfig(props, null);
RESTClientFactory factory = new RESTClientFactory(mainConfig);
StoreClient<String, String> storeClient = factory.getStoreClient("test");
try {
// Sample put
System.out.println("First valid put");
storeClient.put("a", "Howdy!!!!");
System.out.println("Second valid put");
storeClient.put("b", "Partner!!!!");
// Do a sample get operation:
Versioned<String> versionedValue = storeClient.get("a");
System.out.println("Received response : " + versionedValue);
Version obsoleteVersion = ((VectorClock) versionedValue.getVersion()).clone();
// Do a versioned put operation:
System.out.println("First versioned put");
versionedValue.setObject("New Value !!!");
System.out.println("************* original version : " + versionedValue.getVersion());
Version putVersion = storeClient.put("a", versionedValue);
System.out.println("************* Updated version : " + putVersion);
// Obsolete version put
System.out.println("Obsolete put");
Versioned<String> obsoleteVersionedValue = new Versioned<String>("Obsolete value", obsoleteVersion);
try {
storeClient.put("a", obsoleteVersionedValue);
System.err.println(" **************** Should not reach this point **************** ");
} catch (Exception e) {
System.out.println("Exception occurred as expected: " + e.getMessage());
}
// Do a get again on the last versioned put operation:
versionedValue = storeClient.get("a");
System.out.println("Received response on the versioned put: " + versionedValue);
System.out.println("Versioned put based on the last put ");
Versioned<String> newVersionedPut = new Versioned<String>("Yet another value !!!", putVersion);
storeClient.put("a", newVersionedPut);
// Do a get again on the last versioned put operation:
versionedValue = storeClient.get("a");
System.out.println("Received response on the (second) versioned put: " + versionedValue);
List<String> keyList = new ArrayList<String>();
keyList.add("a");
keyList.add("b");
System.out.println("Received response : " + storeClient.getAll(keyList));
} finally {
factory.close();
}
}
use of voldemort.versioning.Version in project voldemort by voldemort.
the class RestServiceR2StoreTest method testGetVersions.
@Override
@Test
public void testGetVersions() throws Exception {
List<ByteArray> keys = getKeys(2);
ByteArray key = keys.get(0);
byte[] value = getValue();
VectorClock vc = getClock(0, 0);
Store<ByteArray, byte[], byte[]> store = getStore();
store.put(key, Versioned.value(value, vc), null);
List<Versioned<byte[]>> versioneds = store.get(key, null);
List<Version> versions = store.getVersions(key);
assertEquals(1, versioneds.size());
assertTrue(versions.size() > 0);
for (int i = 0; i < versions.size(); i++) assertEquals(versioneds.get(0).getVersion(), versions.get(i));
assertEquals(0, store.getVersions(keys.get(1)).size());
}
Aggregations