Skip to content

Commit 644bceb

Browse files
authored
Merge pull request #328 from jajik/issue-325
Add missing balancer sync to lbmethod_cluster, minor tweaks
2 parents 899fd9e + 5cc2f7f commit 644bceb

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

native/balancers/mod_lbmethod_cluster.c

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ static proxy_worker *internal_find_best_byrequests(request_rec *r, const proxy_b
3636
proxy_worker *mycandidate = NULL;
3737
int i;
3838

39-
for (i = 0; i < balancer->workers->nelts; i++, ptr = ptr + sizew) {
39+
for (i = 0; i < balancer->workers->nelts; i++) {
4040
const nodeinfo_t *node;
4141
int id;
42-
proxy_worker **run = (proxy_worker **)ptr;
43-
proxy_worker *worker = *run;
42+
proxy_worker *worker = *((proxy_worker **)(ptr + i * sizew));
4443

4544
if (!PROXY_WORKER_IS_USABLE(worker)) {
4645
continue;
@@ -90,7 +89,9 @@ static proxy_worker *find_best(proxy_balancer *balancer, request_rec *r)
9089
}
9190

9291
if (!node_table) {
92+
ap_assert(node_storage->lock_nodes() == APR_SUCCESS);
9393
node_table = read_node_table(r->pool, node_storage, 0);
94+
node_storage->unlock_nodes();
9495
}
9596

9697
node_storage->lock_nodes();
@@ -131,15 +132,25 @@ static const proxy_balancer_method cluster = {"cluster", &find_best, NULL, &rese
131132
*/
132133
static int lbmethod_cluster_trans(request_rec *r)
133134
{
135+
proxy_vhost_table *vhost_table;
136+
proxy_context_table *context_table;
137+
proxy_balancer_table *balancer_table;
138+
proxy_node_table *node_table;
139+
134140
const char *balancer;
135141
void *sconf = r->server->module_config;
136142
const char *use_uri = r->uri;
137143
proxy_server_conf *conf = (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
138144
proxy_dir_conf *dconf = ap_get_module_config(r->per_dir_config, &proxy_module);
139-
proxy_vhost_table *vhost_table = read_vhost_table(r->pool, host_storage, 0);
140-
proxy_context_table *context_table = read_context_table(r->pool, context_storage, 0);
141-
proxy_balancer_table *balancer_table = read_balancer_table(r->pool, balancer_storage, 0);
142-
proxy_node_table *node_table = read_node_table(r->pool, node_storage, 0);
145+
146+
ap_assert(node_storage->lock_nodes() == APR_SUCCESS);
147+
148+
vhost_table = read_vhost_table(r->pool, host_storage, 0);
149+
context_table = read_context_table(r->pool, context_storage, 0);
150+
balancer_table = read_balancer_table(r->pool, balancer_storage, 0);
151+
node_table = read_node_table(r->pool, node_storage, 0);
152+
153+
node_storage->unlock_nodes();
143154

144155
ap_log_error(APLOG_MARK, APLOG_TRACE4, 0, r->server,
145156
"lbmethod_cluster_trans: for %d %s %s uri: %s args: %s unparsed_uri: %s", r->proxyreq, r->filename,
@@ -238,7 +249,6 @@ static void remove_removed_node(server_rec *s, apr_pool_t *pool, apr_time_t now,
238249

239250
static apr_status_t mc_watchdog_callback(int state, void *data, apr_pool_t *pool)
240251
{
241-
apr_status_t rv = APR_SUCCESS;
242252
server_rec *s = (server_rec *)data;
243253
proxy_node_table *node_table;
244254
apr_time_t now;
@@ -249,7 +259,9 @@ static apr_status_t mc_watchdog_callback(int state, void *data, apr_pool_t *pool
249259

250260
case AP_WATCHDOG_STATE_RUNNING:
251261
/* loop thru all workers */
262+
ap_assert(node_storage->lock_nodes() == APR_SUCCESS);
252263
node_table = read_node_table(pool, node_storage, 0);
264+
node_storage->unlock_nodes();
253265
now = apr_time_now();
254266
if (s) {
255267
int i;
@@ -267,12 +279,11 @@ static apr_status_t mc_watchdog_callback(int state, void *data, apr_pool_t *pool
267279
for (n = 0; n < balancer->workers->nelts; n++) {
268280
nodeinfo_t *node;
269281
int id;
270-
worker = *workers;
282+
worker = *(workers + n);
271283
node = table_get_node_route(node_table, worker->s->route, &id);
272284
if (node != NULL) {
273285
if (node->mess.remove) {
274286
/* Already marked for removal */
275-
workers++;
276287
continue;
277288
}
278289
if (node->mess.updatetimelb < (now - lbstatus_recalc_time)) {
@@ -284,13 +295,11 @@ static apr_status_t mc_watchdog_callback(int state, void *data, apr_pool_t *pool
284295
node_storage->lock_nodes();
285296
if (node_storage->read_node(id, &ou) != APR_SUCCESS) {
286297
node_storage->unlock_nodes();
287-
workers++;
288298
continue;
289299
}
290300
if (ou->mess.remove) {
291301
/* the stored node is already marked for removal */
292302
node_storage->unlock_nodes();
293-
workers++;
294303
continue;
295304
}
296305
ou->mess.updatetimelb = now;
@@ -318,7 +327,6 @@ static apr_status_t mc_watchdog_callback(int state, void *data, apr_pool_t *pool
318327
node_storage->unlock_nodes();
319328
}
320329
}
321-
workers++;
322330
}
323331
}
324332

@@ -333,7 +341,8 @@ static apr_status_t mc_watchdog_callback(int state, void *data, apr_pool_t *pool
333341
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "lbmethod_cluster_watchdog_callback STOPPING");
334342
break;
335343
}
336-
return rv;
344+
345+
return APR_SUCCESS;
337346
}
338347

339348
static int lbmethod_cluster_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)

native/mod_manager/mod_manager.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,9 @@ static const proxy_worker_shared *read_shared_by_node(request_rec *r, nodeinfo_t
12241224
if (strcmp(balancer->s->name, name)) {
12251225
continue;
12261226
}
1227+
/* Sync the shared memory for balancer */
1228+
ap_proxy_sync_balancer(balancer, r->server, conf);
1229+
12271230
workers = (proxy_worker **)balancer->workers->elts;
12281231
for (j = 0; j < balancer->workers->nelts; j++, workers++) {
12291232
proxy_worker *worker = *workers;

0 commit comments

Comments
 (0)