grpc
src
core
ext
filters
client_channel
lb_policy
address_filtering.h
Go to the documentation of this file.
1
//
2
// Copyright 2020 gRPC authors.
3
//
4
// Licensed under the Apache License, Version 2.0 (the "License");
5
// you may not use this file except in compliance with the License.
6
// You may obtain a copy of the License at
7
//
8
// http://www.apache.org/licenses/LICENSE-2.0
9
//
10
// Unless required by applicable law or agreed to in writing, software
11
// distributed under the License is distributed on an "AS IS" BASIS,
12
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
// See the License for the specific language governing permissions and
14
// limitations under the License.
15
//
16
17
#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_ADDRESS_FILTERING_H
18
#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_ADDRESS_FILTERING_H
19
20
#include <
grpc/support/port_platform.h
>
21
22
#include <map>
23
#include <memory>
24
#include <string>
25
#include <vector>
26
27
#include "absl/status/statusor.h"
28
29
#include "
src/core/lib/resolver/server_address.h
"
30
31
// The resolver returns a flat list of addresses. When a hierarchy of
32
// LB policies is in use, each leaf of the hierarchy will need a
33
// different subset of those addresses. This library provides a
34
// mechanism for determining which address is passed to which leaf
35
// policy.
36
//
37
// Each address will have an associated path that indicates which child
38
// it should be sent to at each level of the hierarchy to wind up at the
39
// right leaf policy. Each LB policy will look at the first element of
40
// the path of each address to determine which child to send the address
41
// to. It will then remove that first element when passing the address
42
// down to its child.
43
//
44
// For example, consider the following LB policy hierarchy:
45
//
46
// - priority
47
// - child0 (weighted_target)
48
// - localityA (round_robin)
49
// - localityB (round_robin)
50
// - child1 (weighted_target)
51
// - localityC (round_robin)
52
// - localityD (round_robin)
53
//
54
// Now consider the following addresses:
55
// - 10.0.0.1:80 path=["child0", "localityA"]
56
// - 10.0.0.2:80 path=["child0", "localityB"]
57
// - 10.0.0.3:80 path=["child1", "localityC"]
58
// - 10.0.0.4:80 path=["child1", "localityD"]
59
//
60
// The priority policy will split this up into two lists, one for each
61
// of its children:
62
// - child0:
63
// - 10.0.0.1:80 path=["localityA"]
64
// - 10.0.0.2:80 path=["localityB"]
65
// - child1:
66
// - 10.0.0.3:80 path=["localityC"]
67
// - 10.0.0.4:80 path=["localityD"]
68
//
69
// The weighted_target policy for child0 will split its list up into two
70
// lists, one for each of its children:
71
// - localityA:
72
// - 10.0.0.1:80 path=[]
73
// - localityB:
74
// - 10.0.0.2:80 path=[]
75
//
76
// Similarly, the weighted_target policy for child1 will split its list
77
// up into two lists, one for each of its children:
78
// - localityC:
79
// - 10.0.0.3:80 path=[]
80
// - localityD:
81
// - 10.0.0.4:80 path=[]
82
83
namespace
grpc_core
{
84
85
// The attribute key to be used for hierarchical paths in ServerAddress.
86
extern
const
char
*
kHierarchicalPathAttributeKey
;
87
88
// Constructs an address attribute containing the hierarchical path
89
// to be associated with the address.
90
std::unique_ptr<ServerAddress::AttributeInterface>
91
MakeHierarchicalPathAttribute
(std::vector<std::string>
path
);
92
93
// A map from the next path element to the addresses that fall under
94
// that path element.
95
using
HierarchicalAddressMap
= std::map<std::string, ServerAddressList>;
96
97
// Splits up the addresses into a separate list for each child.
98
absl::StatusOr<HierarchicalAddressMap>
MakeHierarchicalAddressMap
(
99
const
absl::StatusOr<ServerAddressList>
& addresses);
100
101
}
// namespace grpc_core
102
103
#endif // GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_ADDRESS_FILTERING_H
grpc_core
Definition:
call_metric_recorder.h:31
grpc_core::kHierarchicalPathAttributeKey
const char * kHierarchicalPathAttributeKey
Definition:
address_filtering.cc:34
check_documentation.path
path
Definition:
check_documentation.py:57
grpc_core::MakeHierarchicalAddressMap
absl::StatusOr< HierarchicalAddressMap > MakeHierarchicalAddressMap(const absl::StatusOr< ServerAddressList > &addresses)
Definition:
address_filtering.cc:76
grpc_core::HierarchicalAddressMap
std::map< std::string, ServerAddressList > HierarchicalAddressMap
Definition:
address_filtering.h:95
grpc_core::MakeHierarchicalPathAttribute
std::unique_ptr< ServerAddress::AttributeInterface > MakeHierarchicalPathAttribute(std::vector< std::string > path)
Definition:
address_filtering.cc:72
server_address.h
absl::StatusOr
Definition:
abseil-cpp/absl/status/statusor.h:187
port_platform.h
grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:40