mirror of https://github.com/grpc/grpc.git
Initial sketch of a client configuration library. It's expected this will subsume the client_setup functionality that we currently have, and begin providing customizable load balancing support. Releasing the headers now (no implementation work has been done) so that we can bat around thoughts on this and make sure all the use cases are implementable, and our primary use cases are easily so.pull/2177/head
parent
096b77dcdf
commit
9d0e047a5c
6 changed files with 400 additions and 0 deletions
@ -0,0 +1,45 @@ |
||||
Client Configuration Support for GRPC |
||||
===================================== |
||||
|
||||
This library provides high level configuration machinery to construct client |
||||
channels and load balance between them. |
||||
|
||||
Each grpc_channel is created with a grpc_resolver. It is the resolver's duty |
||||
to resolve a name into configuration data for the channel. Such configuration |
||||
data might include: |
||||
|
||||
- a list of (ip, port) addresses to connect to |
||||
- a load balancing policy to decide which server to send a request to |
||||
- a set of filters to mutate outgoing requests (say, by adding metadata) |
||||
|
||||
The resolver provides this data as a stream of grpc_client_config objects to |
||||
the channel. We represent configuration as a stream so that it can be changed |
||||
by the resolver during execution, by reacting to external events (such as a |
||||
new configuration file being pushed to some store). |
||||
|
||||
|
||||
Load Balancing |
||||
-------------- |
||||
|
||||
Load balancing configuration is provided by a grpc_lb_policy object, stored as |
||||
part of grpc_client_config. |
||||
|
||||
A load balancing policies primary job is to pick a target server given only the |
||||
initial metadata for a request. It does this by providing a |
||||
grpc_configured_channel object to the owning channel. |
||||
|
||||
|
||||
Configured Sub-Channels |
||||
----------------------- |
||||
|
||||
A configured sub-channel provides a connection to a server for a client |
||||
channel. It has a connectivity state like a regular channel, and so can be |
||||
connected or disconnected. This connectivity state can be used to inform load |
||||
balancing decisions (for example, by avoiding disconnected backends). |
||||
|
||||
Configured sub-channels are fully setup to participate in the grpc data plane. |
||||
Their behavior is specified by a set of grpc channel filters defined at their |
||||
construction. To customize this behavior, resolvers build |
||||
grpc_configured_subchannel_factory objects, which use the decorator pattern |
||||
to customize construction arguments for concrete grpc_configured_subchannel |
||||
instances. |
@ -0,0 +1,49 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_INTERNAL_CORE_CLIENT_CONFIG_CLIENT_CONFIG_H |
||||
#define GRPC_INTERNAL_CORE_CLIENT_CONFIG_CLIENT_CONFIG_H |
||||
|
||||
/** Total configuration for a client. Provided, and updated, by
|
||||
grpc_resolver */ |
||||
typedef struct grpc_client_config grpc_client_config; |
||||
|
||||
void grpc_client_config_ref(grpc_client_config *client_config); |
||||
void grpc_client_config_unref(grpc_client_config *client_config); |
||||
|
||||
void grpc_client_config_set_lb_policy(grpc_client_config *client_config, |
||||
grpc_lb_policy *lb_policy); |
||||
grpc_lb_policy *grpc_client_config_get_lb_policy( |
||||
grpc_client_config *client_config); |
||||
|
||||
#endif /* GRPC_INTERNAL_CORE_CLIENT_CONFIG_CLIENT_CONFIG_H */ |
@ -0,0 +1,72 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_INTERNAL_CORE_CLIENT_CONFIG_CONFIGURED_SUBCHANNEL_H |
||||
#define GRPC_INTERNAL_CORE_CLIENT_CONFIG_CONFIGURED_SUBCHANNEL_H |
||||
|
||||
/** A (sub-)channel that knows how to connect to exactly one target
|
||||
address. Provides a target for load balancing. */ |
||||
typedef struct grpc_configured_subchannel grpc_configured_subchannel; |
||||
|
||||
/** Connectivity state of a channel.
|
||||
TODO(ctiller): move to grpc.h when we implement the public |
||||
version of the connectivity apis */ |
||||
typedef enum { |
||||
/** channel is connecting */ |
||||
GRPC_CHANNEL_CONNECTING, |
||||
/** channel is ready for work */ |
||||
GRPC_CHANNEL_READY, |
||||
/** channel has seen a failure but expects to recover */ |
||||
GRPC_CHANNEL_TRANSIENT_FAILURE, |
||||
/** channel is idle */ |
||||
GRPC_CHANNEL_IDLE, |
||||
/** channel has seen a failure that it cannot recover from */ |
||||
GRPC_CHANNEL_FATAL_FAILURE |
||||
} grpc_connectivity_state; |
||||
|
||||
void grpc_configured_subchannel_ref(grpc_configured_subchannel *channel); |
||||
void grpc_configured_subchannel_unref(grpc_configured_subchannel *channel); |
||||
|
||||
/** poll the current connectivity state of a channel */ |
||||
grpc_connectivity_state grpc_configured_subchannel_check_connectivity( |
||||
grpc_configured_subchannel *channel); |
||||
/** call notify when the connectivity state of a channel changes from *state.
|
||||
Updates *state with the new state of the channel */ |
||||
void grpc_configured_subchannel_notify_on_state_change( |
||||
grpc_configured_subchannel *channel, grpc_connectivity_state *state, |
||||
grpc_iomgr_closure *notify); |
||||
/** continue processing of transport operation \a op */ |
||||
void grpc_configured_subchannel_continue_op(grpc_configured_subchannel *channel, |
||||
grpc_transport_op *op); |
||||
|
||||
#endif /* GRPC_INTERNAL_CORE_CLIENT_CONFIG_CONFIGURED_SUBCHANNEL_H */ |
@ -0,0 +1,86 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_INTERNAL_CORE_CLIENT_CONFIG_CONFIGURED_SUBCHANNEL_FACTORY_H |
||||
#define GRPC_INTERNAL_CORE_CLIENT_CONFIG_CONFIGURED_SUBCHANNEL_FACTORY_H |
||||
|
||||
typedef struct grpc_configured_subchannel_factory |
||||
grpc_configured_subchannel_factory; |
||||
typedef struct grpc_configured_subchannel_factory_vtable |
||||
grpc_configured_subchannel_factory_vtable; |
||||
|
||||
/** Constructor for new configured channels.
|
||||
Creating decorators around this type is encouraged to adapt behavior. */ |
||||
struct grpc_configured_subchannel_factory { |
||||
const grpc_configured_subchannel_factory_vtable *vtable; |
||||
}; |
||||
|
||||
struct grpc_configured_subchannel_args { |
||||
/* TODO(ctiller): consider making (parent, metadata_context) more opaque
|
||||
- these details are not needed at this level of API */ |
||||
/** Parent channel element - passed from the master channel */ |
||||
grpc_channel_element *parent; |
||||
/** Metadata context for this channel - passed from the master channel */ |
||||
grpc_mdctx *metadata_context; |
||||
/** Channel filters for this channel - wrapped factories will likely
|
||||
want to mutate this */ |
||||
const grpc_channel_filter **filters; |
||||
/** The number of filters in the above array */ |
||||
size_t filter_count; |
||||
/** Channel arguments to be supplied to the newly created channel */ |
||||
const grpc_channel_args *args; |
||||
|
||||
struct sockaddr *addr; |
||||
}; |
||||
|
||||
struct grpc_configured_subchannel_factory_vtable { |
||||
void (*ref)(grpc_configured_subchannel_factory *factory); |
||||
void (*unref)(grpc_configured_subchannel_factory *factory); |
||||
grpc_configured_subchannel *(*create_subchannel)( |
||||
grpc_configured_subchannel_factory *factory, |
||||
grpc_configured_subchannel_args *args); |
||||
}; |
||||
|
||||
void grpc_configured_subchannel_factory_ref( |
||||
grpc_configured_subchannel_factory *factory); |
||||
void grpc_configured_subchannel_factory_unref( |
||||
grpc_configured_subchannel_factory *factory); |
||||
/** Create a new grpc_configured_subchannel */ |
||||
void grpc_configured_subchannel_factory_create_subchannel( |
||||
grpc_configured_subchannel_factory *factory, |
||||
grpc_configured_subchannel_args *args); |
||||
|
||||
grpc_configured_subchannel_factory * |
||||
grpc_default_configured_subchannel_factory(); |
||||
|
||||
#endif /* GRPC_INTERNAL_CORE_CLIENT_CONFIG_CONFIGURED_SUBCHANNEL_FACTORY_H */ |
@ -0,0 +1,73 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_INTERNAL_CORE_CLIENT_CONFIG_LB_POLICY_H |
||||
#define GRPC_INTERNAL_CORE_CLIENT_CONFIG_LB_POLICY_H |
||||
|
||||
#include "src/core/client_config/configured_channel.h" |
||||
|
||||
/** A load balancing policy: specified by a vtable and a struct (which
|
||||
is expected to be extended to contain some parameters) */ |
||||
typedef struct grpc_lb_policy grpc_lb_policy; |
||||
typedef struct grpc_lb_policy_vtable grpc_lb_policy_vtable; |
||||
|
||||
typedef void (*grpc_lb_completion)(void *cb_arg, |
||||
grpc_configured_channel *configured_channel, |
||||
grpc_status_code status, const char *errmsg); |
||||
|
||||
struct grpc_lb_policy_vtable { |
||||
void (*ref)(grpc_lb_policy *policy); |
||||
void (*unref)(grpc_lb_policy *policy); |
||||
|
||||
void (*shutdown)(grpc_lb_policy *policy); |
||||
|
||||
/** implement grpc_lb_policy_pick */ |
||||
void (*pick)(grpc_lb_policy *policy, grpc_pollset *pollset, |
||||
grpc_metadata_batch *initial_metadata, |
||||
grpc_configured_channel **target, |
||||
grpc_iomgr_closure *on_complete); |
||||
}; |
||||
|
||||
/** Start shutting down (fail any pending picks) */ |
||||
void grpc_lb_policy_shutdown(grpc_lb_policy *policy); |
||||
|
||||
/** Given initial metadata in \a initial_metadata, find an appropriate
|
||||
target for this rpc, and 'return' it by calling \a on_complete after setting |
||||
\a target. |
||||
Picking can be asynchronous. Any IO should be done under \a pollset. */ |
||||
void grpc_lb_policy_pick(grpc_lb_policy *policy, grpc_pollset *pollset, |
||||
grpc_metadata_batch *initial_metadata, |
||||
grpc_configured_channel **target, |
||||
grpc_iomgr_closure *on_complete); |
||||
|
||||
#endif /* GRPC_INTERNAL_CORE_CONFIG_LB_POLICY_H */ |
@ -0,0 +1,75 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_INTERNAL_CORE_CLIENT_CONFIG_RESOLVER_H |
||||
#define GRPC_INTERNAL_CORE_CLIENT_CONFIG_RESOLVER_H |
||||
|
||||
typedef struct grpc_resolver grpc_resolver; |
||||
typedef struct grpc_resolver_vtable grpc_resolver_vtable; |
||||
|
||||
/** grpc_resolver provides grpc_client_config objects to grpc_channel
|
||||
objects */ |
||||
struct grpc_resolver { |
||||
const grpc_resolver_vtable *vtable; |
||||
}; |
||||
|
||||
struct grpc_resolver_vtable { |
||||
void (*ref)(grpc_resolver *resolver); |
||||
void (*unref)(grpc_resolver *resolver); |
||||
void (*shutdown)(grpc_resolver *resolver); |
||||
void (*channel_saw_error)(grpc_resolver *resolver, |
||||
struct sockaddr *failing_address); |
||||
void (*next)(grpc_resolver *resolver, grpc_client_config **target_config, |
||||
grpc_iomgr_closure *on_complete); |
||||
}; |
||||
|
||||
void grpc_resolver_ref(grpc_resolver *resolver); |
||||
void grpc_resolver_unref(grpc_resolver *resolver); |
||||
void grpc_resolver_shutdown(grpc_resolver *resolver); |
||||
|
||||
/** Notification that the channel has seen an error on some address.
|
||||
Can be used as a hint that re-resolution is desirable soon. */ |
||||
void grpc_resolver_channel_saw_error(grpc_resolver *resolver, |
||||
struct sockaddr *failing_address); |
||||
|
||||
/** Get the next client config. Called by the channel to fetch a new
|
||||
configuration. Expected to set *target_config with a new configuration, |
||||
and then schedule on_complete for execution. |
||||
|
||||
If resolution is fatally broken, set *target_config to NULL and |
||||
schedule on_complete. */ |
||||
void grpc_resolver_next(grpc_resolver *resolver, |
||||
grpc_client_config **target_config, |
||||
grpc_iomgr_closure *on_complete); |
||||
|
||||
#endif /* GRPC_INTERNAL_CORE_CONFIG_RESOLVER_H */ |
Loading…
Reference in new issue