use of com.orientechnologies.orient.server.distributed.ODistributedConfiguration in project orientdb by orientechnologies.
the class ODCDistributedConflictResolver method onConflict.
public OConflictResult onConflict(final String databaseName, final String clusterName, final ORecordId rid, final ODistributedServerManager dManager, final Map<Object, List<String>> candidates, final ODocument config) {
final ODistributedConfiguration dCfg = dManager.getDatabaseConfiguration(databaseName);
final String winnerDC = config.field("winner");
// FILTER THE RESULT BY REMOVING THE SERVER THAT ARE IN THE CONFIGURED DC
for (Map.Entry<Object, List<String>> entry : candidates.entrySet()) {
final List<String> servers = entry.getValue();
for (Iterator<String> it = servers.iterator(); it.hasNext(); ) {
final String server = it.next();
if (!winnerDC.equals(dCfg.getDataCenterOfServer(server)))
// COLLECT ONLY THE RESULT FROM SERVER IN THE CONFIGURED DC
it.remove();
}
}
return super.onConflict(databaseName, clusterName, rid, dManager, candidates, config);
}
use of com.orientechnologies.orient.server.distributed.ODistributedConfiguration in project orientdb by orientechnologies.
the class OMajorityDistributedConflictResolver method onConflict.
public OConflictResult onConflict(final String databaseName, final String clusterName, final ORecordId rid, final ODistributedServerManager dManager, final Map<Object, List<String>> candidates, final ODocument config) {
final OConflictResult result = new OConflictResult();
final Object bestResult = getBestResult(candidates, null);
if (bestResult == null)
return result;
final ODistributedConfiguration dCfg = dManager.getDatabaseConfiguration(databaseName);
final int writeQuorum = dCfg.getWriteQuorum(clusterName, dManager.getAvailableNodes(databaseName), dManager.getLocalNodeName());
final int bestResultServerCount = candidates.get(bestResult).size();
if (bestResultServerCount >= writeQuorum) {
// BEST RESULT RESPECT THE QUORUM, IT'S DEFINITELY THE WINNER
OLogManager.instance().debug(this, "Majority Conflict Resolver decided the value '%s' is the winner for record %s, because is major than the configured writeQuorum (%d). Servers ok=%s", bestResult, rid, writeQuorum, candidates.get(result.winner));
result.winner = bestResult;
} else {
// FOUND IF THERE IS AT LEAST A MAJORITY
final List<Object> exclude = new ArrayList<Object>();
exclude.add(bestResult);
final Object secondBestResult = getBestResult(candidates, exclude);
if (bestResultServerCount > candidates.get(secondBestResult).size()) {
OLogManager.instance().debug(this, "Majority Conflict Resolver decided the value '%s' is the winner for the record %s because it is the majority even if under the configured writeQuorum (%d). Servers ok=%s", bestResult, rid, writeQuorum, candidates.get(result.winner));
result.winner = bestResult;
} else {
// NO MAJORITY: DON'T TAKE ANY ACTION
OLogManager.instance().debug(this, "Majority Conflict Resolver could not find a winner for the record %s (candidates=%s)", rid, candidates);
// COLLECT ALL THE RESULT == BEST RESULT
result.candidates.put(bestResult, candidates.get(bestResult));
result.candidates.put(secondBestResult, candidates.get(secondBestResult));
exclude.add(secondBestResult);
Object lastBestResult = getBestResult(candidates, exclude);
int resultCount = candidates.get(secondBestResult).size();
while (lastBestResult != null && resultCount == bestResultServerCount && exclude.size() < candidates.size()) {
result.candidates.put(lastBestResult, candidates.get(lastBestResult));
exclude.add(lastBestResult);
lastBestResult = getBestResult(candidates, exclude);
if (lastBestResult == null)
break;
resultCount = candidates.get(lastBestResult).size();
}
}
}
return result;
}
Aggregations