void SyncTail::handleSlaveDelay(const BSONObj& lastOp) { ReplicationCoordinator* replCoord = getGlobalReplicationCoordinator(); int slaveDelaySecs = durationCount<Seconds>(replCoord->getSlaveDelaySecs()); // ignore slaveDelay if the box is still initializing. once // it becomes secondary we can worry about it. if (slaveDelaySecs > 0 && replCoord->getMemberState().secondary()) { const Timestamp ts = lastOp["ts"].timestamp(); long long a = ts.getSecs(); long long b = time(0); long long lag = b - a; long long sleeptime = slaveDelaySecs - lag; if (sleeptime > 0) { uassert(12000, "rs slaveDelay differential too big check clocks and systems", sleeptime < 0x40000000); if (sleeptime < 60) { sleepsecs((int)sleeptime); } else { warning() << "slavedelay causing a long sleep of " << sleeptime << " seconds"; // sleep(hours) would prevent reconfigs from taking effect & such! long long waitUntil = b + sleeptime; while (time(0) < waitUntil) { sleepsecs(6); // Handle reconfigs that changed the slave delay if (durationCount<Seconds>(replCoord->getSlaveDelaySecs()) != slaveDelaySecs) break; } } } } // endif slaveDelay }
StatusWith<RecordId> keyForOptime(const Timestamp& opTime) { // Make sure secs and inc wouldn't be negative if treated as signed. This ensures that they // don't sort differently when put in a RecordId. It also avoids issues with Null/Invalid // RecordIds if (opTime.getSecs() > uint32_t(std::numeric_limits<int32_t>::max())) return StatusWith<RecordId>(ErrorCodes::BadValue, "ts secs too high"); if (opTime.getInc() > uint32_t(std::numeric_limits<int32_t>::max())) return StatusWith<RecordId>(ErrorCodes::BadValue, "ts inc too high"); const RecordId out = RecordId(opTime.getSecs(), opTime.getInc()); if (out <= RecordId::min()) return StatusWith<RecordId>(ErrorCodes::BadValue, "ts too low"); if (out >= RecordId::max()) return StatusWith<RecordId>(ErrorCodes::BadValue, "ts too high"); return StatusWith<RecordId>(out); }