final ODistributedConfiguration dbCfg = dManager.getDatabaseConfiguration(getName());
if (!dbCfg.isReplicationActive(null, dManager.getLocalNodeName()))
// DON'T REPLICATE
return wrapped.command(iCommand);
final OCommandExecutor executor = OCommandManager.instance().getExecutor(iCommand);
executor.setProgressListener(iCommand.getProgressListener());
executor.parse(iCommand);
final OCommandExecutor exec = executor instanceof OCommandExecutorSQLDelegate ? ((OCommandExecutorSQLDelegate) executor)
.getDelegate() : executor;
try {
final OSQLCommandTask task = new OSQLCommandTask(iCommand);
Object result = null;
OCommandDistributedReplicateRequest.DISTRIBUTED_EXECUTION_MODE executionMode = OCommandDistributedReplicateRequest.DISTRIBUTED_EXECUTION_MODE.LOCAL;
if (OScenarioThreadLocal.INSTANCE.get() != RUN_MODE.RUNNING_DISTRIBUTED) {
if (exec instanceof OCommandDistributedReplicateRequest)
executionMode = ((OCommandDistributedReplicateRequest) exec).getDistributedExecutionMode();
}
switch (executionMode) {
case LOCAL:
return wrapped.command(iCommand);
case REPLICATE: {
// REPLICATE IT, GET ALL THE INVOLVED NODES
final Collection<String> involvedClusters = exec.getInvolvedClusters();
final Collection<String> nodes;
task.setResultStrategy(OAbstractRemoteTask.RESULT_STRATEGY.ANY);
nodes = dbCfg.getServers(involvedClusters);
if (iCommand instanceof ODistributedCommand)
nodes.removeAll(((ODistributedCommand) iCommand).nodesToExclude());
result = dManager.sendRequest(getName(), involvedClusters, nodes, task, EXECUTION_MODE.RESPONSE);
break;
}
case SHARDED: {
// SHARDED, GET ONLY ONE NODE PER INVOLVED CLUSTER
final Collection<String> involvedClusters = exec.getInvolvedClusters();
final Collection<String> nodes;
task.setResultStrategy(OAbstractRemoteTask.RESULT_STRATEGY.UNION);
nodes = dbCfg.getOneServerPerCluster(involvedClusters, dManager.getLocalNodeName());
if (iCommand instanceof ODistributedCommand)
nodes.removeAll(((ODistributedCommand) iCommand).nodesToExclude());
boolean executeLocally = false;
if (exec.isIdempotent()) {
// IDEMPOTENT: CHECK IF CAN WORK LOCALLY ONLY
int maxReadQuorum;
if (involvedClusters.isEmpty())
maxReadQuorum = dbCfg.getReadQuorum(null);
else {