Skip to content

Commit

Permalink
Remove offset from node structure, use macro instead
Browse files Browse the repository at this point in the history
  • Loading branch information
jajik committed Aug 21, 2024
1 parent a9c9571 commit e593041
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 27 deletions.
2 changes: 1 addition & 1 deletion native/include/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct nodemess
typedef struct nodemess nodemess_t;

#define SIZEOFSCORE 1700 /* at least size of the proxy_worker_stat structure */
#define NODEOFFSET (APR_ALIGN_DEFAULT(sizeof(nodemess_t) + sizeof(apr_time_t)))

/**
* Status of the node as read/store in httpd
Expand All @@ -78,7 +79,6 @@ struct nodeinfo
nodemess_t mess;
/* filled by httpd */
apr_time_t updatetime; /* time of last received message */
unsigned long offset; /* offset to the proxy_worker_stat structure */
char stat[SIZEOFSCORE]; /* to store the status */
};
typedef struct nodeinfo nodeinfo_t;
Expand Down
6 changes: 1 addition & 5 deletions native/mod_manager/mod_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,6 @@ static char *process_config(request_rec *r, char **ptr, int *errtype)
} else {
/* Here that is the tricky part, we will insert_update the whole node including proxy_worker_shared */
char *pptr;
unsigned long offset;

ap_log_error(APLOG_MARK, APLOG_WARNING, 0, r->server,
"process_config: worker %d (%s) exists and IS NOT OK!!!", id, nodeinfo.mess.JVMRoute);
Expand Down Expand Up @@ -1466,10 +1465,7 @@ static char *process_config(request_rec *r, char **ptr, int *errtype)
ap_assert(worker->s->port != 0);
/* XXX: really needed? offset logic OK here, we save the worker information (see mod_proxy_cluster) */
pptr = (char *)&nodeinfo;
offset = sizeof(nodemess_t) + sizeof(apr_time_t) +
sizeof(unsigned long); /* nodeinfo.offset doesn't contain the information */
offset = APR_ALIGN_DEFAULT(offset);
pptr = pptr + offset;
pptr = pptr + NODEOFFSET;
memcpy(pptr, worker->s, sizeof(proxy_worker_shared)); /* restore the information we are going to reuse */
ap_assert(the_conf);
}
Expand Down
13 changes: 0 additions & 13 deletions native/mod_manager/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,9 @@ static apr_status_t update(void *mem, void *data, apr_pool_t *pool)
(void)pool;

if (strcmp(in->mess.JVMRoute, ou->mess.JVMRoute) == 0) {
/*
* The node information is made of several pieces:
* Information from the cluster (nodemess_t).
* updatetime (time of last received message).
* offset (of the area shared with the proxy logic).
* stat (shared area with the proxy logic we shouldn't modify it here).
*/
in->mess.id = ou->mess.id;
memcpy(ou, in, sizeof(nodemess_t));
ou->updatetime = apr_time_now();
ou->offset = sizeof(nodemess_t) + sizeof(apr_time_t) + sizeof(unsigned long);
ou->offset = APR_ALIGN_DEFAULT(ou->offset);
return APR_EEXIST; /* it exists so we are done */
}
return APR_SUCCESS;
Expand Down Expand Up @@ -135,10 +126,6 @@ apr_status_t insert_update_node(mem_t *s, nodeinfo_t *node, int *id, int clean)
ou->mess.id = *id;
ou->updatetime = now;

/* set of offset to the proxy_worker_stat */
ou->offset = sizeof(nodemess_t) + sizeof(apr_time_t) + sizeof(unsigned long);
ou->offset = APR_ALIGN_DEFAULT(ou->offset);

/* blank the proxy status information */
if (clean) {
memset(&(ou->stat), '\0', SIZEOFSCORE);
Expand Down
16 changes: 8 additions & 8 deletions native/mod_proxy_cluster/mod_proxy_cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ static apr_status_t create_worker_reuse(proxy_server_conf *conf, const char *ptr
}

/* Check if the shared memory goes to the right place */
ptr = ptr_node + node->offset;
ptr = ptr_node + NODEOFFSET;
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "create_worker: reusing worker (id %d) for %s", node->mess.id,
url);
if (helper->index == node->mess.id && worker->s == (proxy_worker_shared *)ptr) {
Expand Down Expand Up @@ -363,7 +363,7 @@ static apr_status_t create_worker_reuse(proxy_server_conf *conf, const char *ptr
#else
worker->s->name);
#endif
ptr = ptr_node + node->offset;
ptr = ptr_node + NODEOFFSET;
*shared = worker->s;
worker->s = (proxy_worker_shared *)ptr;
worker->s->was_malloced = 0; /* Prevent mod_proxy to free it */
Expand Down Expand Up @@ -542,7 +542,7 @@ static apr_status_t create_worker(proxy_server_conf *conf, proxy_balancer *balan
* 1 - the worker was created.
* 2 - we are reusing a removed worker.
*/
ptr = ptr_node + node->offset;
ptr = ptr_node + NODEOFFSET;
shared = worker->s;
worker->s = (proxy_worker_shared *)ptr;
helper->isinnodes = 1;
Expand Down Expand Up @@ -836,7 +836,7 @@ static void remove_workers_node(nodeinfo_t *node, proxy_server_conf *conf, apr_p
int i;
proxy_cluster_helper *helper;
proxy_worker_shared *stat;
char *pptr = (char *)node + node->offset;
char *pptr = (char *)node + NODEOFFSET;

proxy_worker *worker = get_worker_from_id_stat(conf, node->mess.id, (proxy_worker_shared *)pptr, node);
(void)pool;
Expand Down Expand Up @@ -1481,7 +1481,7 @@ static void update_workers_lbstatus(proxy_server_conf *conf, apr_pool_t *pool, s
proxy_worker_shared *stat;
char *ptr = (char *)ou;

ptr = ptr + ou->offset;
ptr = ptr + NODEOFFSET;
stat = (proxy_worker_shared *)ptr;
elected = stat->elected;
read = stat->read;
Expand Down Expand Up @@ -1664,7 +1664,7 @@ static proxy_worker *internal_process_worker(proxy_worker *worker, int checking_
if (read_node_worker(worker->s->index, &node, worker) != APR_SUCCESS) {
return NULL; /* Can't read node */
}
if (worker->s != (proxy_worker_shared *)((char *)node + node->offset)) {
if (worker->s != (proxy_worker_shared *)((char *)node + NODEOFFSET)) {
return NULL; /* wrong shared memory address */
}

Expand Down Expand Up @@ -1852,7 +1852,7 @@ static int proxy_node_isup(request_rec *r, int id, int load)

/* Calculate the address of our shared memory that corresponds to the stat info of the worker */
ptr = (char *)node;
stat = (proxy_worker_shared *)(ptr + node->offset);
stat = (proxy_worker_shared *)(ptr + NODEOFFSET);

/* create the balancers and workers (that could be the first time) */
ap_assert(node_storage->lock_nodes() == APR_SUCCESS);
Expand Down Expand Up @@ -2131,7 +2131,7 @@ static void reenable_proxy_worker(server_rec *server, nodeinfo_t *node, proxy_wo
helper->isinnodes = 1;
/* XXX: BAD IDEA!! helper->index = node->mess.id; */
ptr = (char *)node;
worker->s = (proxy_worker_shared *)(ptr + node->offset);
worker->s = (proxy_worker_shared *)(ptr + NODEOFFSET);
/* merge the "new" node information */
init_proxy_worker(server, nodeinfo, worker, the_conf);
}
Expand Down

0 comments on commit e593041

Please sign in to comment.