@@ -29,11 +29,21 @@ std::string XdsVerifier::getRoute(const envoy::config::listener::v3::Listener& l
29
29
* @return true iff the route listener refers to is in all_routes_
30
30
*/
31
31
bool XdsVerifier::hasRoute (const envoy::config::listener::v3::Listener& listener) {
32
- return all_routes_. contains (getRoute (listener));
32
+ return hasRoute (getRoute (listener));
33
33
}
34
34
35
+ bool XdsVerifier::hasRoute (const std::string& name) { return all_routes_.contains (name); }
36
+
35
37
bool XdsVerifier::hasActiveRoute (const envoy::config::listener::v3::Listener& listener) {
36
- return active_routes_.contains (getRoute (listener));
38
+ return hasActiveRoute (getRoute (listener));
39
+ }
40
+
41
+ bool XdsVerifier::hasActiveRoute (const std::string& name) { return active_routes_.contains (name); }
42
+
43
+ bool XdsVerifier::hasListener (const std::string& name, ListenerState state) {
44
+ return std::any_of (listeners_.begin (), listeners_.end (), [&](const auto & rep) {
45
+ return rep.listener .name () == name && state == rep.state ;
46
+ });
37
47
}
38
48
39
49
/* *
@@ -68,7 +78,7 @@ void XdsVerifier::dumpState() {
68
78
* updated listener
69
79
*/
70
80
void XdsVerifier::listenerUpdated (const envoy::config::listener::v3::Listener& listener) {
71
- ENVOY_LOG_MISC (debug, " About to update listener {}" , listener.name ());
81
+ ENVOY_LOG_MISC (debug, " About to update listener {} to {} " , listener.name (), getRoute (listener ));
72
82
dumpState ();
73
83
74
84
if (std::any_of (listeners_.begin (), listeners_.end (), [&](auto & rep) {
@@ -79,17 +89,25 @@ void XdsVerifier::listenerUpdated(const envoy::config::listener::v3::Listener& l
79
89
return ;
80
90
}
81
91
82
- for (unsigned long i = 0 ; i < listeners_.size (); ++i) {
83
- const auto & rep = listeners_[i];
92
+ bool found = false ;
93
+ for (auto it = listeners_.begin (); it != listeners_.end ();) {
94
+ const auto & rep = *it;
95
+ ENVOY_LOG_MISC (debug, " checking {} for update" , rep.listener .name ());
84
96
if (rep.listener .name () == listener.name ()) {
85
- if (rep.state == ACTIVE) {
97
+ // if we're updating a warming/active listener, num_modified_ must be incremented
98
+ if (rep.state != DRAINING && !found) {
86
99
num_modified_++;
100
+ found = true ;
101
+ }
102
+
103
+ if (rep.state == ACTIVE) {
87
104
if (hasActiveRoute (listener)) {
88
105
// if the new listener is ready to take traffic, the old listener will be removed
89
106
// it seems to be directly removed without being added to the config dump as draining
90
107
ENVOY_LOG_MISC (debug, " Removing {} after update" , listener.name ());
91
108
num_active_--;
92
- listeners_.erase (listeners_.begin () + i);
109
+ it = listeners_.erase (it);
110
+ continue ;
93
111
} else {
94
112
// if the new listener has not gotten its route yet, the old listener will remain active
95
113
// until that happens
@@ -99,9 +117,12 @@ void XdsVerifier::listenerUpdated(const envoy::config::listener::v3::Listener& l
99
117
// if the old listener is warming, it will be removed and replaced with the new
100
118
ENVOY_LOG_MISC (debug, " Removed warming listener {}" , listener.name ());
101
119
num_warming_--;
102
- listeners_.erase (listeners_.begin () + i);
120
+ it = listeners_.erase (it);
121
+ // don't increment it
122
+ continue ;
103
123
}
104
124
}
125
+ ++it;
105
126
}
106
127
dumpState ();
107
128
listenerAdded (listener, true );
@@ -139,25 +160,28 @@ void XdsVerifier::listenerAdded(const envoy::config::listener::v3::Listener& lis
139
160
*/
140
161
void XdsVerifier::listenerRemoved (const std::string& name) {
141
162
bool found = false ;
142
- for (unsigned long i = 0 ; i < listeners_.size (); ++i) {
143
- auto & rep = listeners_[i];
144
- if (rep.listener .name () != name) {
145
- continue ;
146
- }
147
163
148
- if (rep.state == ACTIVE) {
149
- // the listener will be drained before being removed
150
- ENVOY_LOG_MISC (debug, " Changing {} to DRAINING" , name);
151
- num_removed_++;
152
- num_active_--;
153
- num_draining_++;
154
- rep.state = DRAINING;
155
- } else if (rep.state == WARMING) {
156
- // the listener will be removed immediately
157
- ENVOY_LOG_MISC (debug, " Removed warming listener {}" , name);
158
- listeners_.erase (listeners_.begin () + i);
159
- num_warming_--;
164
+ for (auto it = listeners_.begin (); it != listeners_.end ();) {
165
+ auto & rep = *it;
166
+ if (rep.listener .name () == name) {
167
+ if (rep.state == ACTIVE) {
168
+ // the listener will be drained before being removed
169
+ ENVOY_LOG_MISC (debug, " Changing {} to DRAINING" , name);
170
+ found = true ;
171
+ num_active_--;
172
+ num_draining_++;
173
+ rep.state = DRAINING;
174
+ } else if (rep.state == WARMING) {
175
+ // the listener will be removed immediately
176
+ ENVOY_LOG_MISC (debug, " Removed warming listener {}" , name);
177
+ found = true ;
178
+ num_warming_--;
179
+ it = listeners_.erase (it);
180
+ // don't increment it
181
+ continue ;
182
+ }
160
183
}
184
+ ++it;
161
185
}
162
186
163
187
if (found) {
@@ -236,7 +260,6 @@ void XdsVerifier::markForRemoval(ListenerRepresentation& rep) {
236
260
// mark it as removed to remove it after the loop so as not to invalidate the iterator in
237
261
// the caller function
238
262
old_rep.state = REMOVED;
239
- /* num_modified_++; */
240
263
num_active_--;
241
264
}
242
265
}
@@ -271,17 +294,19 @@ void XdsVerifier::routeAdded(const envoy::config::route::v3::RouteConfiguration&
271
294
// if an unreferenced route is sent in delta, it is ignored forever as it will not be sent in
272
295
// future RDS updates, whereas in SOTW it will be present in all future RDS updates, so if a
273
296
// listener that refers to it is added in the meantime, it will become active
297
+ if (!hasRoute (route.name ())) {
298
+ all_routes_.insert ({route.name (), route});
299
+ }
274
300
275
- // in delta, active_routes_ and all_routes_ should be the same as we only send one route at a
276
- // time, so it either becomes active or not
277
301
if (sotw_or_delta_ == DELTA && std::any_of (listeners_.begin (), listeners_.end (), [&](auto & rep) {
278
302
return getRoute (rep.listener ) == route.name ();
279
303
})) {
280
- active_routes_.insert ({route.name (), route});
281
- all_routes_.insert ({route.name (), route});
304
+ if (!hasActiveRoute (route.name ())) {
305
+ active_routes_.insert ({route.name (), route});
306
+ updateDeltaListeners (route);
307
+ }
282
308
updateDeltaListeners (route);
283
309
} else if (sotw_or_delta_ == SOTW) {
284
- all_routes_.insert ({route.name (), route});
285
310
updateSotwListeners ();
286
311
}
287
312
}
0 commit comments