MCPcopy Create free account
hub / github.com/apple/foundationdb / isHealthySingleton

Function isHealthySingleton

fdbserver/ClusterController.actor.cpp:533–572  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

531// Side effects: (possibly) initiates recruitment
532template <class Interface>
533bool isHealthySingleton(ClusterControllerData* self,
534 const WorkerDetails& newWorker,
535 const Singleton<Interface>& singleton,
536 const ProcessClass::Fitness& bestFitness,
537 const Optional<UID> recruitingID) {
538 // A singleton is stable if it exists in cluster, has not been killed off of proc and is not being recruited
539 bool isStableSingleton = singleton.interface.present() &&
540 self->id_worker.count(singleton.interface.get().locality.processId()) &&
541 (!recruitingID.present() || (recruitingID.get() == singleton.interface.get().id()));
542
543 if (!isStableSingleton) {
544 return false; // not healthy because unstable
545 }
546
547 auto& currWorker = self->id_worker[singleton.interface.get().locality.processId()];
548 auto currFitness = currWorker.details.processClass.machineClassFitness(singleton.getClusterRole());
549 if (currWorker.priorityInfo.isExcluded) {
550 currFitness = ProcessClass::ExcludeFit;
551 }
552 // If any of the following conditions are met, we will switch the singleton's process:
553 // - if the current proc is used by some non-master, non-singleton role
554 // - if the current fitness is less than optimal (lower fitness is better)
555 // - if currently at peak fitness but on same process as master, and the new worker is on different process
556 bool shouldRerecruit =
557 self->isUsedNotMaster(currWorker.details.interf.locality.processId()) || bestFitness < currFitness ||
558 (currFitness == bestFitness && currWorker.details.interf.locality.processId() == self->masterProcessId &&
559 newWorker.interf.locality.processId() != self->masterProcessId);
560 if (shouldRerecruit) {
561 std::string roleAbbr = singleton.getRole().abbreviation;
562 TraceEvent(("CCHalt" + roleAbbr).c_str(), self->id)
563 .detail(roleAbbr + "ID", singleton.interface.get().id())
564 .detail("Excluded", currWorker.priorityInfo.isExcluded)
565 .detail("Fitness", currFitness)
566 .detail("BestFitness", bestFitness);
567 singleton.recruit(self); // SIDE EFFECT: initiating recruitment
568 return false; // not healthy since needed to be rerecruited
569 } else {
570 return true; // healthy because doesn't need to be rerecruited
571 }
572}
573
574// Returns a mapping from pid->pidCount for pids
575std::map<Optional<Standalone<StringRef>>, int> getColocCounts(

Callers

nothing calls this directly

Calls 12

TraceEventClass · 0.85
processIdMethod · 0.80
machineClassFitnessMethod · 0.80
detailMethod · 0.80
countMethod · 0.65
getMethod · 0.65
presentMethod · 0.45
idMethod · 0.45
getClusterRoleMethod · 0.45
getRoleMethod · 0.45
c_strMethod · 0.45
recruitMethod · 0.45

Tested by

no test coverage detected