Add dtors in LB policy subclasses.

reviewable/pr17577/r2
Mark D. Roth 6 years ago
parent 21446eb35a
commit 8cd7178afb
  1. 36
      test/core/util/forwarding_load_balancing_policy.cc
  2. 35
      test/core/util/forwarding_load_balancing_policy.h
  3. 2
      test/cpp/end2end/client_lb_end2end_test.cc

@ -18,8 +18,44 @@
#include "test/core/util/forwarding_load_balancing_policy.h"
#include "src/core/ext/filters/client_channel/lb_policy_registry.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/iomgr/combiner.h"
#include "src/core/lib/iomgr/pollset_set.h"
namespace grpc_core {
TraceFlag grpc_trace_forwarding_lb(false, "forwarding_lb");
ForwardingLoadBalancingPolicy::ForwardingLoadBalancingPolicy(
const Args& args, const std::string& delegate_policy_name)
: LoadBalancingPolicy(args) {
delegate_ =
LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(
delegate_policy_name.c_str(), args);
grpc_pollset_set_add_pollset_set(delegate_->interested_parties(),
interested_parties());
// Give re-resolution closure to delegate.
GRPC_CLOSURE_INIT(&on_delegate_request_reresolution_,
OnDelegateRequestReresolutionLocked, this,
grpc_combiner_scheduler(combiner()));
Ref().release(); // held by callback.
delegate_->SetReresolutionClosureLocked(&on_delegate_request_reresolution_);
}
ForwardingLoadBalancingPolicy::~ForwardingLoadBalancingPolicy() {}
void ForwardingLoadBalancingPolicy::OnDelegateRequestReresolutionLocked(
void* arg, grpc_error* error) {
ForwardingLoadBalancingPolicy* self =
static_cast<ForwardingLoadBalancingPolicy*>(arg);
if (error != GRPC_ERROR_NONE || self->delegate_ == nullptr) {
self->Unref();
return;
}
self->TryReresolutionLocked(&grpc_trace_forwarding_lb, GRPC_ERROR_NONE);
self->delegate_->SetReresolutionClosureLocked(
&self->on_delegate_request_reresolution_);
}
} // namespace grpc_core

@ -19,16 +19,12 @@
#include <string>
#include "src/core/ext/filters/client_channel/lb_policy.h"
#include "src/core/ext/filters/client_channel/lb_policy_registry.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channelz.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gprpp/orphanable.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/iomgr/closure.h"
#include "src/core/lib/iomgr/combiner.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/pollset_set.h"
#include "src/core/lib/json/json.h"
#include "src/core/lib/transport/connectivity_state.h"
@ -37,26 +33,13 @@
namespace grpc_core {
extern TraceFlag grpc_trace_forwarding_lb;
// A minimal forwarding class to avoid implementing a standalone test LB.
class ForwardingLoadBalancingPolicy : public LoadBalancingPolicy {
public:
ForwardingLoadBalancingPolicy(const Args& args,
const std::string& delegate_policy_name)
: LoadBalancingPolicy(args) {
delegate_ =
LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(
delegate_policy_name.c_str(), args);
grpc_pollset_set_add_pollset_set(delegate_->interested_parties(),
interested_parties());
// Give re-resolution closure to delegate.
GRPC_CLOSURE_INIT(&on_delegate_request_reresolution_,
OnDelegateRequestReresolutionLocked, this,
grpc_combiner_scheduler(combiner()));
Ref().release(); // held by callback.
delegate_->SetReresolutionClosureLocked(&on_delegate_request_reresolution_);
}
const std::string& delegate_policy_name);
~ForwardingLoadBalancingPolicy() override;
const char* name() const override { return delegate_->name(); }
@ -108,17 +91,7 @@ class ForwardingLoadBalancingPolicy : public LoadBalancingPolicy {
void ShutdownLocked() override { delegate_.reset(); }
static void OnDelegateRequestReresolutionLocked(void* arg,
grpc_error* error) {
ForwardingLoadBalancingPolicy* self =
static_cast<ForwardingLoadBalancingPolicy*>(arg);
if (error != GRPC_ERROR_NONE || self->delegate_ == nullptr) {
self->Unref();
return;
}
self->TryReresolutionLocked(&grpc_trace_forwarding_lb, GRPC_ERROR_NONE);
self->delegate_->SetReresolutionClosureLocked(
&self->on_delegate_request_reresolution_);
}
grpc_error* error);
OrphanablePtr<LoadBalancingPolicy> delegate_;
grpc_closure on_delegate_request_reresolution_;

@ -1255,6 +1255,8 @@ class ClientLbInterceptTrailingMetadataTest : public ClientLbEnd2endTest {
delegate_lb_policy_name),
test_(test) {}
~InterceptRecvTrailingMetadataLoadBalancingPolicy() override = default;
bool PickLocked(PickState* pick, grpc_error** error) override {
bool ret = ForwardingLoadBalancingPolicy::PickLocked(pick, error);
// Note: This assumes that the delegate policy does not

Loading…
Cancel
Save