@Override public Occurred compare(Version v) { if(!(v instanceof VectorClock)) throw new IllegalArgumentException("Cannot compare Versions of different types."); return VectorClockUtils.compare(this, (VectorClock) v); }
private VectorClock makeDenseClock() { // FIXME This is a temporary workaround for System store client not // being able to do a second insert. We simply generate a super // clock that will trump what is on storage // But this will not work, if the nodes are ever removed or re-assigned. // To complicate the issue further, SystemStore uses one clock for all // keys in a file. When you remove nodes, go delete, all version files from the disk // otherwise return VectorClockUtils.makeClockWithCurrentTime(currentCluster.getNodeIds()); }
private List<Versioned<byte[]>> pruneAndResolve(List<Versioned<byte[]>> vals, MutableBoolean didPrune) { return VectorClockUtils.resolveVersions(VersionedPutPruneJob.pruneNonReplicaEntries(vals, keyReplicas, didPrune)); }
/** * Generates a vector clock with the provided nodes and current time stamp * This clock can be used to overwrite the existing value avoiding obsolete * version exceptions in most cases, except If the existing Vector Clock was * generated in custom way. (i.e. existing vector clock does not use * milliseconds) * * @param serverIds servers in the clock */ public static VectorClock makeClockWithCurrentTime(Set<Integer> serverIds) { return makeClock(serverIds, System.currentTimeMillis(), System.currentTimeMillis()); }
void streamingPut(ByteArray key, Versioned<byte[]> value) { if(overwrite) { VectorClock denseClock = VectorClockUtils.makeClockWithCurrentTime(dstServerIds); Versioned<byte[]> updatedValue = new Versioned<byte[]>(value.getValue(), denseClock); dstStreamingClient.streamingPut(key, updatedValue); } else { dstStreamingClient.streamingPut(key, value); } entriesForkLifted++; if(entriesForkLifted % progressOps == 0) { logger.info(workName + " fork lifted " + entriesForkLifted + " entries successfully"); } }
VectorClockUtils.compare(fetchedClock1, fetchedClock2)); assertEquals("online versions themselves should conflict", Occurred.CONCURRENTLY, VectorClockUtils.compare(onlineClock1, onlineClock2)); assertEquals("fetched and online versions should conflict", Occurred.CONCURRENTLY, VectorClockUtils.compare(fetchedClock1, onlineClock1)); assertEquals("fetched and online versions should conflict", Occurred.CONCURRENTLY, VectorClockUtils.compare(fetchedClock1, onlineClock1)); assertEquals("fetched and online versions should conflict", Occurred.CONCURRENTLY, VectorClockUtils.compare(fetchedClock1, onlineClock2)); assertEquals("fetched and online versions should conflict", Occurred.CONCURRENTLY, VectorClockUtils.compare(fetchedClock2, onlineClock1)); assertEquals("fetched and online versions should conflict", Occurred.CONCURRENTLY, VectorClockUtils.compare(fetchedClock2, onlineClock2)); Occurred.CONCURRENTLY == VectorClockUtils.compare((VectorClock) vals.get(0) .getVersion(), nextOnlineClock1)); assertFalse("Next online write would not result in conflict", Occurred.CONCURRENTLY == VectorClockUtils.compare((VectorClock) vals.get(0) .getVersion(), nextOnlineClock2));
List<Versioned<byte[]>> resolvedVals = VectorClockUtils.resolveVersions(prunedVals);
public static void setQuota(String storeName, QuotaType type, StoreRepository repository, Set<Integer> nodeIds, long lquota) { FileBackedCachingStorageEngine quotaStore = getQuotaStore(repository); String quotaKey = makeQuotaKey(storeName, QuotaType.STORAGE_SPACE); ByteArray keyArray = convertToByteArray(quotaKey); List<Versioned<byte[]>> existingValue = quotaStore.get(keyArray, null); String quotaValue = Long.toString(lquota); ByteArray valueArray = convertToByteArray(quotaValue); VectorClock newClock = VectorClockUtils.makeClockWithCurrentTime(nodeIds); Versioned<byte[]> newValue = new Versioned<byte[]>(valueArray.get(), newClock); quotaStore.put(keyArray, newValue, null); } }
assertEquals("fetched and online versions should conflict", Occurred.CONCURRENTLY, VectorClockUtils.compare(fetchedClock, onlineClock)); 1); assertFalse("Next online write would not result in conflict", Occurred.CONCURRENTLY == VectorClockUtils.compare((VectorClock) vals.get(0) .getVersion(), nextOnlineClock));
assertEquals("Not pruned properly", TestUtils.getClock(0), prunedVals.get(3).getVersion()); List<Versioned<byte[]>> resolvedVals = VectorClockUtils.resolveVersions(prunedVals);
public void setGetPutQuotasForEachServer() throws Exception { Properties adminProperties = new Properties(); adminProperties.setProperty("max_connections", "2"); adminClient = new AdminClient(cluster, new AdminClientConfig().setMaxConnectionsPerNode(2)); Map<Pair<Integer, QuotaType>, Integer> throughPutMap = new HashMap<Pair<Integer, QuotaType>, Integer>(); // Set Node0 Quota throughPutMap.put(new Pair<Integer, QuotaType>(0, QuotaType.PUT_THROUGHPUT), 5); throughPutMap.put(new Pair<Integer, QuotaType>(0, QuotaType.GET_THROUGHPUT), 20); // Set Node1 Quota throughPutMap.put(new Pair<Integer, QuotaType>(1, QuotaType.PUT_THROUGHPUT), 2); throughPutMap.put(new Pair<Integer, QuotaType>(1, QuotaType.GET_THROUGHPUT), 20); for(Entry<Pair<Integer, QuotaType>, Integer> throughPut: throughPutMap.entrySet()) { int nodeId = throughPut.getKey().getFirst(); QuotaType type = throughPut.getKey().getSecond(); int value = throughPut.getValue(); VectorClock clock = VectorClockUtils.makeClockWithCurrentTime(cluster.getNodeIds()); NodeValue<ByteArray, byte[]> operationValue = new NodeValue<ByteArray, byte[]>(nodeId, new ByteArray(getKeyBytes(type)), new Versioned<byte[]>(ByteUtils.getBytes(Integer.toString(value), encodingType), clock)); try { adminClient.storeOps.putNodeKeyValue(quotaStoreName, operationValue); } catch(Exception e) { throw new Exception("Exception when setting put quota for node " + nodeId + " Operation " + type + "." + e.getMessage()); } } }
@Test public void testClusterWithDifferentStateFails() throws IOException { Cluster localCluster = ServerTestUtils.getLocalCluster(1); VoldemortConfig config = getVoldemortConfig(new Properties()); server = new VoldemortServer(config, localCluster); server.start(); final int UPDATED_NODE_ID = 3; Node oldNode = localCluster.getNodes().iterator().next(); // For single local node, host matcher is not used. config.setNodeIdImplementation(new NodeIdHostMatcher(UPDATED_NODE_ID)); Cluster updatedCluster = ServerTestUtils.getLocalCluster(UPDATED_NODE_ID + 1); oldAdminClient = new AdminClient(localCluster); try { oldAdminClient.metadataMgmtOps.updateRemoteCluster(oldNode.getId(), updatedCluster, VectorClockUtils.makeClockWithCurrentTime(localCluster.getNodeIds())); Assert.fail("Invalid node id should have failed"); } catch(VoldemortException ex) { // Expected, ignore } }
VectorClockUtils.makeClockWithCurrentTime(localCluster.getNodeIds()));