Search in sources :

Example 1 with ReplSetSyncFromReply

use of com.torodb.mongodb.commands.signatures.repl.ReplSetSyncFromCommand.ReplSetSyncFromReply in project torodb by torodb.

the class TopologyCoordinator method executeReplSetSyncFrom.

ReplSetSyncFromReply executeReplSetSyncFrom(ErrorCode status, HostAndPort target, OpTime lastOpApplied) throws MongoException {
    if (status == ErrorCode.CALLBACK_CANCELED) {
        throw new ShutdownInProgressException("replication system is shutting down");
    }
    final HostAndPort syncFromRequested = target;
    MemberConfig targetConfig = null;
    int targetIndex;
    for (targetIndex = 0; targetIndex < _rsConfig.getMembers().size(); targetIndex++) {
        MemberConfig it = _rsConfig.getMembers().get(targetIndex);
        if (it.getHostAndPort().equals(target)) {
            targetConfig = it;
            break;
        }
    }
    if (targetConfig == null) {
        throw new NodeNotFoundException("Could not find member \"" + target + "\" in replica set");
    }
    if (targetConfig.isArbiter()) {
        throw new InvalidOptionsException("Cannot sync from \"" + target + "\" because it is an arbiter");
    }
    String warning = null;
    MemberHeartbeatData hbdata = _hbdata.get(targetIndex);
    if (hbdata.isAuthIssue()) {
        throw new UnauthorizedException("not authorized to communicate with " + target);
    }
    if (hbdata.getHealth() == Health.UNREACHABLE) {
        throw new HostUnreachableException("I cannot reach the requested member: " + target);
    }
    assert hbdata.getOpTime() != null;
    if (hbdata.getOpTime().getSecs() + 10 < lastOpApplied.getSecs()) {
        LOGGER.warn("attempting to sync from {}, but its latest opTime is {} and ours is {} " + "so this may not work", target, hbdata.getOpTime().getSecs(), lastOpApplied.getSecs());
        warning = "requested member \"" + target + "\" is more than 10 seconds behind us";
    }
    HostAndPort prevSyncSource = getSyncSourceAddress().orElse(null);
    setForceSyncSourceIndex(targetIndex);
    return new ReplSetSyncFromReply(prevSyncSource, syncFromRequested, warning);
}
Also used : MemberHeartbeatData(com.torodb.mongodb.commands.pojos.MemberHeartbeatData) HostAndPort(com.google.common.net.HostAndPort) NodeNotFoundException(com.eightkdata.mongowp.exceptions.NodeNotFoundException) InvalidOptionsException(com.eightkdata.mongowp.exceptions.InvalidOptionsException) ShutdownInProgressException(com.eightkdata.mongowp.exceptions.ShutdownInProgressException) HostUnreachableException(com.eightkdata.mongowp.exceptions.HostUnreachableException) UnauthorizedException(com.eightkdata.mongowp.exceptions.UnauthorizedException) ReplSetSyncFromReply(com.torodb.mongodb.commands.signatures.repl.ReplSetSyncFromCommand.ReplSetSyncFromReply) MemberConfig(com.torodb.mongodb.commands.pojos.MemberConfig)

Aggregations

HostUnreachableException (com.eightkdata.mongowp.exceptions.HostUnreachableException)1 InvalidOptionsException (com.eightkdata.mongowp.exceptions.InvalidOptionsException)1 NodeNotFoundException (com.eightkdata.mongowp.exceptions.NodeNotFoundException)1 ShutdownInProgressException (com.eightkdata.mongowp.exceptions.ShutdownInProgressException)1 UnauthorizedException (com.eightkdata.mongowp.exceptions.UnauthorizedException)1 HostAndPort (com.google.common.net.HostAndPort)1 MemberConfig (com.torodb.mongodb.commands.pojos.MemberConfig)1 MemberHeartbeatData (com.torodb.mongodb.commands.pojos.MemberHeartbeatData)1 ReplSetSyncFromReply (com.torodb.mongodb.commands.signatures.repl.ReplSetSyncFromCommand.ReplSetSyncFromReply)1