use of voldemort.versioning.Occurred in project voldemort by voldemort.
the class AbstractStorageEngine method resolveAndConstructVersionsToPersist.
/**
* Computes the final list of versions to be stored, on top of what is
* currently being stored. Final list is valuesInStorage modified in place
*
*
* @param valuesInStorage list of versions currently in storage
* @param multiPutValues list of new versions being written to storage
* @return list of versions from multiPutVals that were rejected as obsolete
*/
protected List<Versioned<V>> resolveAndConstructVersionsToPersist(List<Versioned<V>> valuesInStorage, List<Versioned<V>> multiPutValues) {
List<Versioned<V>> obsoleteVals = new ArrayList<Versioned<V>>(multiPutValues.size());
// acceptable
for (Versioned<V> value : multiPutValues) {
Iterator<Versioned<V>> iter = valuesInStorage.iterator();
boolean obsolete = false;
// Compare the current version with a set of accepted versions
while (iter.hasNext()) {
Versioned<V> curr = iter.next();
Occurred occurred = value.getVersion().compare(curr.getVersion());
if (occurred == Occurred.BEFORE) {
obsolete = true;
break;
} else if (occurred == Occurred.AFTER) {
iter.remove();
}
}
if (obsolete) {
// add to return value if obsolete
obsoleteVals.add(value);
} else {
// else update the set of accepted versions
valuesInStorage.add(value);
}
}
return obsoleteVals;
}
use of voldemort.versioning.Occurred in project voldemort by voldemort.
the class ReadRepairer method singleKeyGetRepairs.
private List<NodeValue<K, V>> singleKeyGetRepairs(List<NodeValue<K, V>> nodeValues) {
int size = nodeValues.size();
if (size <= 1)
return Collections.emptyList();
// 1. Create a multi-map of nodes to their existing Versions
Multimap<Integer, NodeValue<K, V>> nodeVersionsMap = HashMultimap.create();
for (NodeValue<K, V> nodeValue : nodeValues) {
nodeVersionsMap.put(nodeValue.getNodeId(), nodeValue);
}
// 2. Create a map of the final set of versions (for this key)
Map<Version, NodeValue<K, V>> mostCurrentVersionsMap = new HashMap<Version, NodeValue<K, V>>();
// Initialize with the first element from the input
mostCurrentVersionsMap.put(nodeValues.get(0).getVersion(), nodeValues.get(0));
// check each value against the current set of most current versions
for (int i = 1; i < nodeValues.size(); i++) {
NodeValue<K, V> curr = nodeValues.get(i);
boolean concurrentToAll = true;
/*
* Make a copy for the traversal. This is because the original map
* can be modified during this traversal
*/
Set<Version> knownGoodVersions = new HashSet<Version>(mostCurrentVersionsMap.keySet());
for (Version currentGoodversion : knownGoodVersions) {
// If the version already exists, do nothing
if (curr.getVersion().equals(currentGoodversion)) {
concurrentToAll = false;
if (logger.isDebugEnabled()) {
logger.debug("Version already exists in the most current set: " + curr);
}
break;
}
// Check the ordering of the current value
Occurred occurred = curr.getVersion().compare(currentGoodversion);
if (occurred == Occurred.BEFORE) {
// This value is obsolete! Break from the loop
if (logger.isDebugEnabled()) {
logger.debug("Version is obsolete : " + curr);
}
concurrentToAll = false;
break;
} else if (occurred == Occurred.AFTER) {
// This concurrent value is obsolete and the current value
// should replace it
mostCurrentVersionsMap.remove(currentGoodversion);
concurrentToAll = false;
mostCurrentVersionsMap.put(curr.getVersion(), curr);
if (logger.isDebugEnabled()) {
logger.debug("Updating the current best - adding : " + curr);
}
}
}
// to the concurrent set
if (concurrentToAll) {
mostCurrentVersionsMap.put(curr.getVersion(), curr);
if (logger.isDebugEnabled()) {
logger.debug("Value is concurrent to all ! : " + curr);
}
}
}
// 3. Compare 1 and 2 and create the repair list
List<NodeValue<K, V>> repairs = new ArrayList<NodeValue<K, V>>(3);
for (int nodeId : nodeVersionsMap.keySet()) {
Set<Version> finalVersions = new HashSet<Version>(mostCurrentVersionsMap.keySet());
if (logger.isDebugEnabled()) {
logger.debug("Set of final versions = " + finalVersions);
}
// Calculate the set difference between final Versions and
// the versions currently existing for nodeId
Set<Version> currentNodeVersions = new HashSet<Version>();
for (NodeValue<K, V> nodeValue : nodeVersionsMap.get(nodeId)) {
currentNodeVersions.add(nodeValue.getVersion());
}
finalVersions.removeAll(currentNodeVersions);
if (logger.isDebugEnabled()) {
logger.debug("Remaining versions to be repaired for this node after the set difference = " + finalVersions);
}
// Repair nodeId with the remaining Versioned values
for (Version remainingVersion : finalVersions) {
NodeValue<K, V> repair = new NodeValue<K, V>(nodeId, mostCurrentVersionsMap.get(remainingVersion).getKey(), mostCurrentVersionsMap.get(remainingVersion).getVersioned());
if (logger.isDebugEnabled()) {
logger.debug("Node value marked to be repaired : " + repair);
}
repairs.add(repair);
}
}
return repairs;
}
Aggregations