Skip to content

Commit

Permalink
Merge pull request #114 from jajik/deduplication
Browse files Browse the repository at this point in the history
Deduplication
  • Loading branch information
jajik authored Aug 3, 2023
2 parents 8dd8c22 + d47583d commit df4ea2a
Show file tree
Hide file tree
Showing 22 changed files with 194 additions and 120 deletions.
2 changes: 2 additions & 0 deletions native/balancers/mod_lbmethod_cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "context.h"
#include "balancer.h"

#include "common.h"

#include "mod_proxy_cluster.h"

#define LB_CLUSTER_WATHCHDOG_NAME ("_lb_cluster_")
Expand Down
12 changes: 12 additions & 0 deletions native/common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Common routines
*/

#include "common.h"

#include "httpd.h"
#include "http_config.h"
#include "http_log.h"
Expand Down Expand Up @@ -781,6 +783,16 @@ const char *get_context_host_balancer(request_rec *r, proxy_vhost_table *vhost_t
return NULL;
}

apr_status_t loc_get_id(void *mem, void *data, apr_pool_t *pool)
{
struct counter *count = (struct counter *)data;
int *ou = (int *)mem;
(void)pool;
*count->values = *ou;
count->values++;
count->count++;
return APR_SUCCESS;
}

/*
* Return the node cotenxt Check that the worker will handle the host/context.
Expand Down
3 changes: 2 additions & 1 deletion native/include/balancer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ typedef struct mem mem_t;
/* status of the balancer as read/store in httpd. */
struct balancerinfo
{
/* NOTE: Due to `loc_get_id`, struct MUST begin with id */
int id; /* id in table */
char balancer[BALANCERSZ]; /* Name of the balancer */
int StickySession; /* 0 : Don't use, 1: Use it */
char StickySessionCookie[COOKNAMESZ];
Expand All @@ -59,7 +61,6 @@ struct balancerinfo
int Maxattempts;

apr_time_t updatetime; /* time of last received message */
int id; /* id in table */
};
typedef struct balancerinfo balancerinfo_t;

Expand Down
137 changes: 137 additions & 0 deletions native/include/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* Common routines
*/

#include "mod_proxy.h"

#include "ap_slotmem.h"

#include "domain.h"
#include "node.h"
#include "host.h"
#include "node.h"
#include "context.h"
#include "mod_proxy_cluster.h"


struct counter
{
unsigned count;
int *values;
};

apr_status_t loc_get_id(void *mem, void *data, apr_pool_t *pool);


/* Read the virtual host table from shared memory */
proxy_vhost_table *read_vhost_table(apr_pool_t *pool, struct host_storage_method *host_storage, int for_cache);

/* Update the virtual host table from shared memory to populate a cached table */
proxy_vhost_table *update_vhost_table_cached(proxy_vhost_table *vhost_table,
const struct host_storage_method *host_storage);

/* Read the context table from shared memory */
proxy_context_table *read_context_table(apr_pool_t *pool, const struct context_storage_method *context_storage,
int for_cache);

/* Update the context table from shared memory to populate a cached table */
proxy_context_table *update_context_table_cached(proxy_context_table *context_table,
const struct context_storage_method *context_storage);

/* Read the balancer table from shared memory */
proxy_balancer_table *read_balancer_table(apr_pool_t *pool, const struct balancer_storage_method *balancer_storage,
int for_cache);

/* Update the balancer table from shared memory to populate a cached table */
proxy_balancer_table *update_balancer_table_cached(proxy_balancer_table *balancer_table,
const struct balancer_storage_method *balancer_storage);

/* Read the node table from shared memory */
proxy_node_table *read_node_table(apr_pool_t *pool, const struct node_storage_method *node_storage, int for_cache);

/* Update the node table from shared memory to populate a cached table*/
proxy_node_table *update_node_table_cached(proxy_node_table *node_table,
const struct node_storage_method *node_storage);

/*
* Read the cookie corresponding to name
* @param r request.
* @param name name of the cookie
* @param in tells if cookie should read from the request or the response
* @return the value of the cookie
*/
char *get_cookie_param(request_rec *r, const char *name, int in);

/**
* Retrieve the parameter with the given name
* Something like 'JSESSIONID=12345...N'
*
* TODO: Should use the mod_proxy_balancer one
*/
char *get_path_param(apr_pool_t *pool, char *url, const char *name);

/**
* Check that the request has a sessionid with a route
* @param r the request_rec.
* @param stickyval the cookie or/and parameter name.
* @param uri part of the URL to for the session parameter.
* @param sticky_used the string that was used to find the route
*/
char *cluster_get_sessionid(request_rec *r, const char *stickyval, char *uri, char **sticky_used);

/**
* Check that the request has a sessionid (even invalid)
* @param r the request_rec.
* @param nodeid the node id.
* @param route (if received)
* @return 1 is it finds a sessionid 0 otherwise.
*/
int hassession_byname(request_rec *r, int nodeid, const char *route, const proxy_node_table *node_table);

/**
* Find the best nodes for a request (check host and context (and balancer))
* @param r the request_rec
* @param balancer the balancer (balancer to use in that case we check it).
* @param route from the sessionid if we have one.
* @param use_alias compare alias with server_name
* @return a pointer to a list of nodes.
*/
node_context *find_node_context_host(request_rec *r, const proxy_balancer *balancer, const char *route, int use_alias,
const proxy_vhost_table *vhost_table, const proxy_context_table *context_table,
const proxy_node_table *node_table);

/**
* Find the balancer corresponding to the node information
*/
const char *get_route_balancer(request_rec *r, const proxy_server_conf *conf, const proxy_vhost_table *vhost_table,
const proxy_context_table *context_table, const proxy_balancer_table *balancer_table,
const proxy_node_table *node_table, int use_alias);

/* Read a node from the table using its it */
const nodeinfo_t *table_get_node(const proxy_node_table *node_table, int id);

/* Get a node from the table using the route */
nodeinfo_t *table_get_node_route(proxy_node_table *node_table, char *route, int *id);

/**
* Search the balancer that corresponds to the pair context/host
* @param r the request_rec.
* @vhost_table table of host virtual hosts.
* @context_table table of contexts.
* @return the balancer name or NULL if not found.
*/
const char *get_context_host_balancer(request_rec *r, proxy_vhost_table *vhost_table,
proxy_context_table *context_table, proxy_node_table *node_table, int use_alias);

apr_status_t loc_get_id(void *mem, void *data, apr_pool_t *pool);

/*
* Return the node cotenxt Check that the worker will handle the host/context.
* de
* The id of the worker is used to find the (slot) node in the shared
* memory.
* (See get_context_host_balancer too).
*/
const node_context *context_host_ok(request_rec *r, const proxy_balancer *balancer, int node, int use_alias,
const proxy_vhost_table *vhost_table, const proxy_context_table *context_table,
const proxy_node_table *node_table);
3 changes: 2 additions & 1 deletion native/include/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ typedef struct mem mem_t;
/* status of the context as read/store in httpd. */
struct contextinfo
{
/* NOTE: Due to `loc_get_id`, struct MUST begin with id */
int id; /* id in table */
char context[CONTEXTSZ + 1]; /* Context where the application is mapped. */
int vhost; /* id of the correspond virtual host in hosts table */
int node; /* id of the correspond node in nodes table */
int status; /* status: ENABLED/DISABLED/STOPPED */
int nbrequests; /* number of request been processed */

apr_time_t updatetime; /* time of last received message */
int id; /* id in table */
};
typedef struct contextinfo contextinfo_t;

Expand Down
3 changes: 2 additions & 1 deletion native/include/domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ typedef struct mem mem_t;
/* status of the domain as read/store in httpd. */
struct domaininfo
{
/* NOTE: Due to `loc_get_id`, struct MUST begin with id */
int id; /* id in table */
char domain[DOMAINNDSZ]; /* domain value */
char JVMRoute[JVMROUTESZ]; /* corresponding node */
char balancer[BALANCERSZ]; /* name of the balancer */

apr_time_t updatetime; /* time of last received message */
int id; /* id in table */
};
typedef struct domaininfo domaininfo_t;

Expand Down
3 changes: 2 additions & 1 deletion native/include/host.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ typedef struct mem mem_t;
/* status of the host as read/store in httpd. */
struct hostinfo
{
/* NOTE: Due to `loc_get_id`, struct MUST begin with id */
int id; /* id in table */
char host[HOSTALIASZ + 1]; /* Alias element of the virtual host */
int vhost; /* id of the correspond virtual host */
int node; /* id of the node containing the virtual host */

apr_time_t updatetime; /* time of last received message */
int id; /* id in table */
};
typedef struct hostinfo hostinfo_t;

Expand Down
41 changes: 2 additions & 39 deletions native/include/mod_proxy_cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#ifndef MOD_PROXY_CLUSTER_H
#define MOD_PROXY_CLUSTER_H

#include "balancer.h"

#define MOD_CLUSTER_EXPOSED_VERSION "mod_cluster/2.0.0.Alpha1-SNAPSHOT"

/* We don't care about versions older then 2.4.x, i.e., MODULE_MAGIC_NUMBER_MAJOR < 20120211 */
Expand Down Expand Up @@ -133,43 +135,4 @@ struct node_context
};
typedef struct node_context node_context;

/* common routines */
proxy_vhost_table *read_vhost_table(apr_pool_t *pool, struct host_storage_method *host_storage, int for_cache);
proxy_context_table *read_context_table(apr_pool_t *pool, const struct context_storage_method *context_storage,
int for_cache);
proxy_balancer_table *read_balancer_table(apr_pool_t *pool, const struct balancer_storage_method *balancer_storage,
int for_cache);
proxy_node_table *read_node_table(apr_pool_t *pool, const struct node_storage_method *node_storage, int for_cache);
proxy_vhost_table *update_vhost_table_cached(proxy_vhost_table *proxy_vhost_table,
const struct host_storage_method *host_storage);
proxy_context_table *update_context_table_cached(proxy_context_table *context_table,
const struct context_storage_method *context_storage);
proxy_balancer_table *update_balancer_table_cached(proxy_balancer_table *balancer_table,
const struct balancer_storage_method *balancer_storage);
proxy_node_table *update_node_table_cached(proxy_node_table *node_table,
const struct node_storage_method *node_storage);

const char *get_route_balancer(request_rec *r, const proxy_server_conf *conf, const proxy_vhost_table *vhost_table,
const proxy_context_table *context_table, const proxy_balancer_table *balancer_table,
const proxy_node_table *node_table, int use_alias);

const char *get_context_host_balancer(request_rec *r, proxy_vhost_table *vhost_table,
proxy_context_table *context_table, proxy_node_table *node_table, int use_alias);

const nodeinfo_t *table_get_node(const proxy_node_table *node_table, int id);
char *cluster_get_sessionid(request_rec *r, const char *stickyval, char *uri, char **sticky_used);
char *get_cookie_param(request_rec *r, const char *name, int in);
char *get_path_param(apr_pool_t *pool, char *url, const char *name);
node_context *find_node_context_host(request_rec *r, const proxy_balancer *balancer, const char *route, int use_alias,
const proxy_vhost_table *vhost_table, const proxy_context_table *context_table,
const proxy_node_table *node_table);
int hassession_byname(request_rec *r, int nodeid, const char *route, const proxy_node_table *node_table);

nodeinfo_t *table_get_node_route(proxy_node_table *node_table, char *route, int *id);

const node_context *context_host_ok(request_rec *r, const proxy_balancer *balancer, int node, int use_alias,
const proxy_vhost_table *vhost_table, const proxy_context_table *context_table,
const proxy_node_table *node_table);


#endif /*MOD_PROXY_CLUSTER_H*/
5 changes: 4 additions & 1 deletion native/include/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ typedef struct mem mem_t;
/* configuration of the node received from jboss cluster. */
struct nodemess
{
/* NOTE: Due to `loc_get_id`, struct MUST begin with id */
int id; /* id in table and worker id */

/* balancer info */
char balancer[BALANCERSZ]; /* name of the balancer */
char JVMRoute[JVMROUTESZ];
char Domain[DOMAINNDSZ];
Expand All @@ -72,7 +76,6 @@ struct nodemess
apr_time_t timeout;

/* part updated in httpd */
int id; /* id in table and worker id */
apr_time_t updatetimelb; /* time of last update of the lbstatus value */
int num_failure_idle; /* number of time the cping/cpong failed while calculating the lbstatus value */
apr_size_t oldelected; /* value of s->elected when calculating the lbstatus */
Expand Down
3 changes: 2 additions & 1 deletion native/include/sessionid.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ typedef struct mem mem_t;
/* status of the sessionid as read/store in httpd. */
struct sessionidinfo
{
/* NOTE: Due to `loc_get_id`, struct MUST begin with id */
int id; /* id in table */
char sessionid[SESSIONIDSZ + 1]; /* Sessionid value */
char JVMRoute[JVMROUTESZ + 1]; /* corresponding node */

apr_time_t updatetime; /* time of last received message */
int id; /* id in table */
};
typedef struct sessionidinfo sessionidinfo_t;

Expand Down
8 changes: 7 additions & 1 deletion native/mod_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ SET(MOD_MANAGER_SRCS ${PROJECT_SOURCE_DIR}/mod_manager.c
${PROJECT_SOURCE_DIR}/host.c
${PROJECT_SOURCE_DIR}/node.c
${PROJECT_SOURCE_DIR}/sessionid.c
${PROJECT_SOURCE_DIR}/../common/common.c
)

INCLUDE_DIRECTORIES("${PROJECT_BINARY_DIR}")
Expand All @@ -24,4 +25,9 @@ INCLUDE_DIRECTORIES("${PROJECT_INCLUDE_DIR}")
ADD_LIBRARY(mod_manager MODULE ${MOD_MANAGER_SRCS})
SET_TARGET_PROPERTIES(mod_manager PROPERTIES PREFIX "")
SET_TARGET_PROPERTIES(mod_manager PROPERTIES SUFFIX ".so")
TARGET_LINK_LIBRARIES(mod_manager ${APR_LIBRARIES} ${APRUTIL_LIBRARIES} ${APACHE_LIBRARY})

IF(WIN32)
TARGET_LINK_LIBRARIES(mod_manager ${PROXY_LIBRARY} ${APR_LIBRARIES} ${APRUTIL_LIBRARIES} ${APACHE_LIBRARY})
ELSE()
TARGET_LINK_LIBRARIES(mod_manager ${APR_LIBRARIES} ${APRUTIL_LIBRARIES} ${APACHE_LIBRARY})
ENDIF()
6 changes: 3 additions & 3 deletions native/mod_manager/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ all: mod_manager.so
mod_manager.so: mod_manager.la
$(top_builddir)/build/instdso.sh SH_LIBTOOL='$(LIBTOOL)' mod_manager.la `pwd`

mod_manager.la: mod_manager.slo node.slo context.slo host.slo balancer.slo sessionid.slo domain.slo
$(SH_LINK) -rpath $(libexecdir) -module -avoid-version mod_manager.lo node.lo context.lo host.lo balancer.lo sessionid.lo domain.lo
mod_manager.la: mod_manager.slo node.slo context.slo host.slo balancer.slo sessionid.slo domain.slo ../common/common.slo
$(SH_LINK) -rpath $(libexecdir) -module -avoid-version mod_manager.lo node.lo context.lo host.lo balancer.lo sessionid.lo domain.lo common.lo

clean:
rm -f *.o *.lo *.slo *.so
rm -f *.o *.lo *.slo *.so ../common/common.slo
rm -rf .libs
13 changes: 2 additions & 11 deletions native/mod_manager/balancer.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#include "ap_slotmem.h"
#include "balancer.h"

#include "common.h"

#include "mod_manager.h"

static mem_t *create_attach_mem_balancer(char *string, unsigned *num, int type, int create, apr_pool_t *p,
Expand Down Expand Up @@ -191,17 +193,6 @@ apr_status_t remove_balancer(mem_t *s, balancerinfo_t *balancer)
return rv;
}

static apr_status_t loc_get_id(void *mem, void *data, apr_pool_t *pool)
{
struct counter *count = (struct counter *)data;
balancerinfo_t *ou = (balancerinfo_t *)mem;
(void)pool;
*count->values = ou->id;
count->values++;
count->count++;
return APR_SUCCESS;
}

/*
* get the ids for the used (not free) balancers in the table
* @param pointer to the shared table.
Expand Down
Loading

0 comments on commit df4ea2a

Please sign in to comment.