Beispiel #1
0
    virtual bool run(OperationContext* txn,
                     const string& dbname,
                     BSONObj& cmdObj,
                     int,
                     string& errmsg,
                     BSONObjBuilder& result) {
        ScopedTransaction transaction(txn, MODE_X);
        Lock::GlobalWrite globalWriteLock(txn->lockState());

        ReplicationCoordinator* replCoord = getGlobalReplicationCoordinator();
        if (getGlobalReplicationCoordinator()->getSettings().usingReplSets()) {
            const MemberState memberState = replCoord->getMemberState();
            if (memberState.startup()) {
                return appendCommandStatus(
                    result, Status(ErrorCodes::NotYetInitialized, "no replication yet active"));
            }
            if (memberState.primary() || !replCoord->setFollowerMode(MemberState::RS_STARTUP2)) {
                return appendCommandStatus(
                    result, Status(ErrorCodes::NotSecondary, "primaries cannot resync"));
            }
            replCoord->setInitialSyncRequestedFlag(true);
            return true;
        }

        // below this comment pertains only to master/slave replication
        if (cmdObj.getBoolField("force")) {
            if (!waitForSyncToFinish(txn, errmsg))
                return false;
            replAllDead = "resync forced";
        }
        // TODO(dannenberg) replAllDead is bad and should be removed when masterslave is removed
        if (!replAllDead) {
            errmsg = "not dead, no need to resync";
            return false;
        }
        if (!waitForSyncToFinish(txn, errmsg))
            return false;

        ReplSource::forceResyncDead(txn, "client");
        result.append("info", "triggered resync for all sources");

        return true;
    }