| 531 | // Side effects: (possibly) initiates recruitment |
| 532 | template <class Interface> |
| 533 | bool 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 |
| 575 | std::map<Optional<Standalone<StringRef>>, int> getColocCounts( |
nothing calls this directly
no test coverage detected