Search in sources :

Example 6 with MemberHeartbeatData

use of com.torodb.mongodb.commands.pojos.MemberHeartbeatData 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)

Example 7 with MemberHeartbeatData

use of com.torodb.mongodb.commands.pojos.MemberHeartbeatData in project torodb by torodb.

the class TopologyCoordinator method updateHeartbeatDataForReconfig.

/**
   * Updates {@link #_hbdata} based on the newConfig, ensuring that every member in the newConfig
   * has an entry in _hbdata.
   * <p>
   * If any nodes in the newConfig are also present in {@link #_currentConfig}, copies their
   * heartbeat info into the corresponding entry in the updated _hbdata vector.
   */
private void updateHeartbeatDataForReconfig(ReplicaSetConfig newConfig, Instant now) {
    if (newConfig == null) {
        return;
    }
    List<MemberHeartbeatData> oldHeartbeats = _hbdata;
    _hbdata = new ArrayList<>(newConfig.getMembers().size());
    for (int index = 0; index < newConfig.getMembers().size(); index++) {
        MemberConfig newMemberConfig = newConfig.getMembers().get(index);
        MemberHeartbeatData newHeartbeatData = new MemberHeartbeatData();
        if (_rsConfig != null) {
            for (int oldIndex = 0; oldIndex < _rsConfig.getMembers().size(); oldIndex++) {
                MemberConfig oldMemberConfig = _rsConfig.getMembers().get(oldIndex);
                if (oldMemberConfig.getId() == newMemberConfig.getId() && oldMemberConfig.getHostAndPort().equals(newMemberConfig.getHostAndPort())) {
                    // This member existed in the old config with the same member ID and
                    // HostAndPort, so copy its heartbeat data over.
                    newHeartbeatData = oldHeartbeats.get(oldIndex);
                    break;
                }
            }
        }
        _hbdata.add(newHeartbeatData);
    }
}
Also used : MemberHeartbeatData(com.torodb.mongodb.commands.pojos.MemberHeartbeatData) MemberConfig(com.torodb.mongodb.commands.pojos.MemberConfig)

Aggregations

MemberHeartbeatData (com.torodb.mongodb.commands.pojos.MemberHeartbeatData)7 MemberConfig (com.torodb.mongodb.commands.pojos.MemberConfig)5 HostAndPort (com.google.common.net.HostAndPort)3 OptionalInt (java.util.OptionalInt)3 OpTime (com.eightkdata.mongowp.OpTime)2 HostUnreachableException (com.eightkdata.mongowp.exceptions.HostUnreachableException)2 InvalidOptionsException (com.eightkdata.mongowp.exceptions.InvalidOptionsException)2 NodeNotFoundException (com.eightkdata.mongowp.exceptions.NodeNotFoundException)2 ShutdownInProgressException (com.eightkdata.mongowp.exceptions.ShutdownInProgressException)2 UnauthorizedException (com.eightkdata.mongowp.exceptions.UnauthorizedException)2 ReplicaSetConfig (com.torodb.mongodb.commands.pojos.ReplicaSetConfig)2 ReplSetHeartbeatReply (com.torodb.mongodb.commands.signatures.internal.ReplSetHeartbeatReply)2 ReplSetSyncFromReply (com.torodb.mongodb.commands.signatures.repl.ReplSetSyncFromCommand.ReplSetSyncFromReply)2 Duration (java.time.Duration)2 ArrayList (java.util.ArrayList)2 ErrorCode (com.eightkdata.mongowp.ErrorCode)1 RemoteCommandResponse (com.eightkdata.mongowp.client.core.MongoConnection.RemoteCommandResponse)1 MongoException (com.eightkdata.mongowp.exceptions.MongoException)1 Preconditions (com.google.common.base.Preconditions)1 UnsignedInteger (com.google.common.primitives.UnsignedInteger)1