Пример #1
0
    Status LegacyReplicationCoordinator::setLastOptime(const OID& rid,
                                                       const OpTime& ts,
                                                       const BSONObj& config) {
        std::string oplogNs = getReplicationMode() == modeReplSet?
                "local.oplog.rs" : "local.oplog.$main";
        if (!updateSlaveTracking(BSON("_id" << rid), config, oplogNs, ts)) {
            return Status(ErrorCodes::NodeNotFound,
                          str::stream() << "could not update node with _id: " 
                                        << config["_id"].Int()
                                        << " beacuse it cannot be found in current ReplSetConfig");
        }

        if (getReplicationMode() == modeReplSet && !getCurrentMemberState().primary()) {
            // pass along if we are not primary
            LOG(2) << "received notification that " << config << " has reached optime: "
                   << ts.toStringPretty();
            theReplSet->syncSourceFeedback.updateMap(rid, ts);
        }
        return Status::OK();
    }
Пример #2
0
    Status LegacyReplicationCoordinator::setLastOptime(OperationContext* txn,
                                                       const OID& rid,
                                                       const OpTime& ts) {
        {
            boost::lock_guard<boost::mutex> lock(_mutex);
            if (ts <= mapFindWithDefault(_slaveOpTimeMap, rid, OpTime())) {
                // Only update if ts is newer than what we have already
                return Status::OK();
            }
            BSONObj config = mapFindWithDefault(_ridConfigMap, rid, BSONObj());
            LOG(2) << "received notification that node with RID " << rid << " and config " << config
                    << " has reached optime: " << ts.toStringPretty();

            if (rid != getMyRID(txn)) {
                // TODO(spencer): Remove this invariant for backwards compatibility
                invariant(!config.isEmpty());
                // This is what updates the progress information used for satisfying write concern
                // and wakes up threads waiting for replication.
                if (!updateSlaveTracking(BSON("_id" << rid), config, ts)) {
                    return Status(ErrorCodes::NodeNotFound,
                                  str::stream() << "could not update node with _id: "
                                          << config["_id"].Int()
                                          << " because it cannot be found in current ReplSetConfig");
                }
            }

            // This updates the _slaveOpTimeMap which is used for forwarding slave progress
            // upstream in chained replication.
            LOG(2) << "Updating our knowledge of the replication progress for node with RID " <<
                    rid << " to be at optime " << ts;
            _slaveOpTimeMap[rid] = ts;
        }

        if (getReplicationMode() == modeReplSet && !getCurrentMemberState().primary()) {
            // pass along if we are not primary
            theReplSet->syncSourceFeedback.forwardSlaveProgress();
        }
        return Status::OK();
    }