use of voldemort.versioning.Versioned in project voldemort by voldemort.
the class OfflineStateTest method testSlopStreaming.
private boolean testSlopStreaming() {
final List<Versioned<Slop>> entrySet = ServerTestUtils.createRandomSlops(0, 10000, testStoreName, "users", "test-replication-persistent", "test-readrepair-memory", "test-consistent", "test-consistent-with-pref-list");
Iterator<Versioned<Slop>> slopIterator = entrySet.iterator();
try {
getAdminClient().streamingOps.updateSlopEntries(0, slopIterator);
} catch (VoldemortException e) {
return false;
}
// check updated values
Iterator<Versioned<Slop>> entrysetItr = entrySet.iterator();
while (entrysetItr.hasNext()) {
Versioned<Slop> versioned = entrysetItr.next();
Slop nextSlop = versioned.getValue();
Store<ByteArray, byte[], byte[]> store = getStore(0, nextSlop.getStoreName());
if (nextSlop.getOperation().equals(Slop.Operation.PUT)) {
return store.get(nextSlop.getKey(), null).size() != 0;
} else if (nextSlop.getOperation().equals(Slop.Operation.DELETE)) {
return store.get(nextSlop.getKey(), null).size() == 0;
}
}
return false;
}
use of voldemort.versioning.Versioned in project voldemort by voldemort.
the class ClientTrafficVerifier method run.
@SuppressWarnings("serial")
@Override
public void run() {
Random r = new Random(System.currentTimeMillis());
while (!shouldStop) {
String k = keys.get(r.nextInt(KV_POOL_SIZE));
try {
switch(r.nextInt(3)) {
case // update
0:
if ((operationMode & MODE_ALLOW_PUT) == 0) {
break;
}
int newCount = kvUpdateCount.get(k) + 1;
client.put(k, kvMap.get(k) + "_" + newCount);
kvUpdateCount.put(k, newCount);
requestCount.put("PUT", requestCount.get("PUT") + 1);
break;
case // get
1:
if ((operationMode & MODE_ALLOW_GET) == 0) {
break;
}
Versioned<String> value = client.get(k);
verifyValue(k, value);
requestCount.put("GET", requestCount.get("GET") + 1);
break;
case // get all
2:
if ((operationMode & MODE_ALLOW_GETALL) == 0) {
break;
}
String k2 = keys.get(r.nextInt(KV_POOL_SIZE));
Map<String, Versioned<String>> result = client.getAll(Arrays.asList(k, k2));
verifyValue(k, result.get(k));
verifyValue(k2, result.get(k2));
requestCount.put("GETALL", requestCount.get("GETALL") + 1);
break;
}
} catch (ObsoleteVersionException e) {
// Theoretically, each thread works with its own set of keys the
// ObsoleteVersionException should not happen. But partitions
// are moving around nodes and because of the way we
// acknowledge writes before all nodes are complete and using
// async writes they can be out of sync and the exceptions can
// still happen. Did not try digging deeper on this one
// as it is irrelevant for the refactoring I am doing.
} catch (Exception e) {
logger.info("CLIENT EXCEPTION FAILURE on key [" + k + "]", e);
String exceptionName = "Key " + k + " " + e.getClass().toString();
if (exceptionCount.containsKey(exceptionName)) {
exceptionCount.put(exceptionName, exceptionCount.get(exceptionName) + 1);
} else {
exceptionCount.put(exceptionName, 1);
}
}
}
}
use of voldemort.versioning.Versioned in project voldemort by voldemort.
the class VoldemortServer method getTestMetadataStore.
private static MetadataStore getTestMetadataStore(VoldemortConfig voldemortConfig, Cluster cluster) {
ConfigurationStorageEngine metadataInnerEngine = new ConfigurationStorageEngine("metadata-config-store", voldemortConfig.getMetadataDirectory());
List<Versioned<String>> clusterXmlValue = metadataInnerEngine.get(MetadataStore.CLUSTER_KEY, null);
VectorClock version = null;
if (clusterXmlValue.size() <= 0) {
version = new VectorClock();
} else {
version = (VectorClock) clusterXmlValue.get(0).getVersion();
}
int nodeId = getNodeId(voldemortConfig, cluster);
version.incrementVersion(nodeId, System.currentTimeMillis());
metadataInnerEngine.put(MetadataStore.CLUSTER_KEY, new Versioned<String>(new ClusterMapper().writeCluster(cluster), version), null);
return MetadataStore.createInMemoryMetadataStore(metadataInnerEngine, nodeId);
}
use of voldemort.versioning.Versioned in project voldemort by voldemort.
the class DynamicTimeoutStoreClient method putWithCustomTimeout.
/**
* Performs a put operation with the specified composite request object
*
* @param requestWrapper A composite request object containing the key and
* value
* @return Version of the value for the successful put
*/
public Version putWithCustomTimeout(CompositeVoldemortRequest<K, V> requestWrapper) {
validateTimeout(requestWrapper.getRoutingTimeoutInMs());
List<Versioned<V>> versionedValues;
long startTime = System.currentTimeMillis();
String keyHexString = "";
if (logger.isDebugEnabled()) {
ByteArray key = (ByteArray) requestWrapper.getKey();
keyHexString = RestUtils.getKeyHexString(key);
logger.debug("PUT requested for key: " + keyHexString + " , for store: " + this.storeName + " at time(in ms): " + startTime + " . Nested GET and PUT VERSION requests to follow ---");
}
// We use the full timeout for doing the Get. In this, we're being
// optimistic that the subsequent put might be faster such that all the
// steps might finish within the allotted time
requestWrapper.setResolveConflicts(true);
versionedValues = getWithCustomTimeout(requestWrapper);
Versioned<V> versioned = getItemOrThrow(requestWrapper.getKey(), null, versionedValues);
long endTime = System.currentTimeMillis();
if (versioned == null)
versioned = Versioned.value(requestWrapper.getRawValue(), new VectorClock());
else
versioned.setObject(requestWrapper.getRawValue());
// This should not happen unless there's a bug in the
// getWithCustomTimeout
long timeLeft = requestWrapper.getRoutingTimeoutInMs() - (endTime - startTime);
if (timeLeft <= 0) {
throw new StoreTimeoutException("PUT request timed out");
}
CompositeVersionedPutVoldemortRequest<K, V> putVersionedRequestObject = new CompositeVersionedPutVoldemortRequest<K, V>(requestWrapper.getKey(), versioned, timeLeft);
putVersionedRequestObject.setRequestOriginTimeInMs(requestWrapper.getRequestOriginTimeInMs());
Version result = putVersionedWithCustomTimeout(putVersionedRequestObject);
long endTimeInMs = System.currentTimeMillis();
if (logger.isDebugEnabled()) {
logger.debug("PUT response received for key: " + keyHexString + " , for store: " + this.storeName + " at time(in ms): " + endTimeInMs);
}
return result;
}
use of voldemort.versioning.Versioned in project voldemort by voldemort.
the class VersionedSerializer method toObject.
public Versioned<T> toObject(byte[] bytes) {
VectorClock vectorClock = getVectorClock(bytes);
int size = 1;
if (vectorClock != null)
size = vectorClock.sizeInBytes();
T t = innerSerializer.toObject(ByteUtils.copy(bytes, size, bytes.length));
return new Versioned<T>(t, vectorClock);
}
Aggregations