Repository: envoyproxy/envoy
File: source/common/upstream/cluster_manager_impl.h (C/C++)

Code before:
   * manager that created the handle.
   *
   * It's a protected type, so unit tests can use it.
   */
  class OdCdsApiHandleImpl : public OdCdsApiHandle {
  public:
    static OdCdsApiHandlePtr create(ClusterManagerImpl& parent, uint64_t subscription_key) {
      return std::make_unique<OdCdsApiHandleImpl>(parent, subscription_key);
    }

    OdCdsApiHandleImpl(ClusterManagerImpl& parent, uint64_t subscription_key)
        : parent_(parent), subscription_key_(subscription_key) {}

    // Ref count cleanup follows ThreadLocal::SlotImpl::~SlotImpl() pattern.
    ~OdCdsApiHandleImpl() override;

    ClusterDiscoveryCallbackHandlePtr
    requestOnDemandClusterDiscovery(absl::string_view name, ClusterDiscoveryCallbackPtr callback,
                                    std::chrono::milliseconds timeout) override {
      return parent_.requestOnDemandClusterDiscovery(subscription_key_, std::string(name),
                                                     std::move(callback), timeout);
    }

  private:
    ClusterManagerImpl& parent_;
    uint64_t subscription_key_;
  };

  virtual void postThreadLocalClusterUpdate(ClusterManagerCluster& cm_cluster,
                                            ThreadLocalClusterUpdateParams&& params);

  /**
   * Notifies cluster discovery managers in each worker thread that the discovery process for the
   * cluster with a passed name has timed out.
   *
   * It's protected, so the tests can use it.
   */
  void notifyExpiredDiscovery(absl::string_view name);

  /**
   * Creates a new discovery manager in current thread and swaps it with the one in thread local
   * cluster manager. This could be used to simulate requesting a cluster from a different
   * thread. Used for tests only.
   *
   * Protected, so tests can use it.
   *
   * @return the previous cluster discovery manager.
   */
  ClusterDiscoveryManager createAndSwapClusterDiscoveryManager(std::string thread_name);

private:

Review comment (suggestion):
High-level comment:
the use of subscription here is misleading - the key refers to a ConfigSource (+locator that should probably be deprecated), and not a subscription.

s/subscription_key_/config_source_key_/

Code after:
   * An implementation of an on-demand CDS handle. It forwards the discovery request to the cluster
   * manager that created the handle.
   *
   * It's a protected type, so unit tests can use it.
   */
  class OdCdsApiHandleImpl : public OdCdsApiHandle {
  public:
    static OdCdsApiHandlePtr create(ClusterManagerImpl& parent, uint64_t config_source_key) {
      return std::make_unique<OdCdsApiHandleImpl>(parent, config_source_key);
    }

    OdCdsApiHandleImpl(ClusterManagerImpl& parent, uint64_t config_source_key)
        : parent_(parent), config_source_key_(config_source_key) {}

    ClusterDiscoveryCallbackHandlePtr
    requestOnDemandClusterDiscovery(absl::string_view name, ClusterDiscoveryCallbackPtr callback,
                                    std::chrono::milliseconds timeout) override {
      return parent_.requestOnDemandClusterDiscovery(config_source_key_, std::string(name),
                                                     std::move(callback), timeout);
    }

  private:
    ClusterManagerImpl& parent_;
    uint64_t config_source_key_;
  };

  virtual void postThreadLocalClusterUpdate(ClusterManagerCluster& cm_cluster,
                                            ThreadLocalClusterUpdateParams&& params);

  /**
   * Notifies cluster discovery managers in each worker thread that the discovery process for the
   * cluster with a passed name has timed out.
   *
   * It's protected, so the tests can use it.
   */
  void notifyExpiredDiscovery(absl::string_view name);

  /**
   * Creates a new discovery manager in current thread and swaps it with the one in thread local
   * cluster manager. This could be used to simulate requesting a cluster from a different
   * thread. Used for tests only.
   *
   * Protected, so tests can use it.
   *
   * @return the previous cluster discovery manager.
   */
  ClusterDiscoveryManager createAndSwapClusterDiscoveryManager(std::string thread_name);

private:
  // To enable access to the protected constructor.
  friend ProdClusterManagerFactory;