Search in sources :

Example 6 with ODistributedConfiguration

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);
}
Also used : List(java.util.List) ODistributedConfiguration(com.orientechnologies.orient.server.distributed.ODistributedConfiguration) Map(java.util.Map)

Example 7 with ODistributedConfiguration

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;
}
Also used : ArrayList(java.util.ArrayList) ODistributedConfiguration(com.orientechnologies.orient.server.distributed.ODistributedConfiguration)

Aggregations

ODistributedConfiguration (com.orientechnologies.orient.server.distributed.ODistributedConfiguration)7 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)4 OHazelcastPlugin (com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin)2 ArrayList (java.util.ArrayList)2 OCallable (com.orientechnologies.common.util.OCallable)1 OTableFormatter (com.orientechnologies.orient.console.OTableFormatter)1 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)1 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)1 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)1 ORecordId (com.orientechnologies.orient.core.id.ORecordId)1 OClassImpl (com.orientechnologies.orient.core.metadata.schema.OClassImpl)1 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)1 OServer (com.orientechnologies.orient.server.OServer)1 ServerRun (com.orientechnologies.orient.server.distributed.ServerRun)1 SimpleDateFormat (java.text.SimpleDateFormat)1 List (java.util.List)1 Map (java.util.Map)1