| 821 | } |
| 822 | |
| 823 | void doReliableRegistration(Duration maxBackoff) |
| 824 | { |
| 825 | if (!running.load()) { |
| 826 | return; |
| 827 | } |
| 828 | |
| 829 | if (connected || master.isNone()) { |
| 830 | return; |
| 831 | } |
| 832 | |
| 833 | if (credential.isSome() && !authenticated) { |
| 834 | return; |
| 835 | } |
| 836 | |
| 837 | VLOG(1) << "Sending SUBSCRIBE call to " << master->pid(); |
| 838 | |
| 839 | Call call; |
| 840 | call.set_type(Call::SUBSCRIBE); |
| 841 | |
| 842 | Call::Subscribe* subscribe = call.mutable_subscribe(); |
| 843 | subscribe->mutable_framework_info()->CopyFrom(framework); |
| 844 | *subscribe->mutable_offer_constraints() = offerConstraints; |
| 845 | *subscribe->mutable_suppressed_roles() = RepeatedPtrField<string>( |
| 846 | suppressedRoles.begin(), suppressedRoles.end()); |
| 847 | |
| 848 | if (framework.has_id() && !framework.id().value().empty()) { |
| 849 | subscribe->set_force(failover); |
| 850 | call.mutable_framework_id()->CopyFrom(framework.id()); |
| 851 | } |
| 852 | |
| 853 | send(master->pid(), call); |
| 854 | |
| 855 | // Bound the maximum backoff by 'REGISTRATION_RETRY_INTERVAL_MAX'. |
| 856 | maxBackoff = |
| 857 | std::min(maxBackoff, scheduler::REGISTRATION_RETRY_INTERVAL_MAX); |
| 858 | |
| 859 | // If failover timeout is present, bound the maximum backoff |
| 860 | // by 1/10th of the failover timeout. |
| 861 | if (framework.has_failover_timeout()) { |
| 862 | Try<Duration> duration = Duration::create(framework.failover_timeout()); |
| 863 | if (duration.isSome() && duration.get() > Duration::zero()) { |
| 864 | maxBackoff = std::min(maxBackoff, duration.get() / 10); |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | // Determine the delay for next attempt by picking a random |
| 869 | // duration between 0 and 'maxBackoff'. |
| 870 | // TODO(vinod): Use random numbers from <random> header. |
| 871 | Duration delay = maxBackoff * ((double) os::random() / RAND_MAX); |
| 872 | |
| 873 | VLOG(1) << "Will retry registration in " << delay << " if necessary"; |
| 874 | |
| 875 | // Backoff. |
| 876 | frameworkRegistrationTimer = process::delay( |
| 877 | delay, self(), &Self::doReliableRegistration, maxBackoff * 2); |
| 878 | } |
| 879 | |
| 880 | void resourceOffers( |
nothing calls this directly
no test coverage detected