Hi,
I am still trying to replace the scoreboard by shared memory to store
the shared information of the workers, I am now thinking to get this by
adding modules like the "prototype" I have enclosed (that is a patch
against trunk).
Does this look to be the right way to go? Or has someone a better idea?
I am also thinking in using #defines so that the whole thing could be
optional (defaulting to actual code).
BTW: The mod_proxy_store_score.c is just to tell: The very first
mod_proxy_storage module I want to write will use... the scoreboard as
common area ;-)
Cheers
Jean-Frederic
Index: mod_proxy_store_score.c
===================================================================
--- mod_proxy_store_score.c (revision 0)
+++ mod_proxy_store_score.c (revision 0)
@@ -0,0 +1,58 @@
+/* Copyright 1999-2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* Comarea for the mod_proxy modules */
+#define CORE_PRIVATE
+
+#include "mod_proxy.h"
+#include "mod_proxy_store.h"
+// #include "mod_core.h"
+
+static void setstatus(proxy_worker *worker, int status)
+{
+}
+static int getstatus(proxy_worker *worker)
+{
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
+ "getstatus of the worker: %s", worker->name);
+ return 0;
+}
+
+static const proxy_storage_method storage = {
+ &setstatus,
+ &getstatus
+};
+
+static void child_init(apr_pool_t *p, server_rec *s)
+{
+}
+
+static void ap_proxy_store_score_register_hook(apr_pool_t *p)
+{
+ ap_hook_child_init(child_init, NULL, NULL, APR_HOOK_MIDDLE);
+ ap_register_provider(p, PROXY_STORAGE, "score", "0", &storage);
+}
+
+module AP_MODULE_DECLARE_DATA proxy_store_score_module = {
+ STANDARD20_MODULE_STUFF,
+ NULL, /* create per-directory config structure */
+ NULL, /* merge per-directory config structures */
+ NULL, /* create per-server config structure */
+ NULL, /* merge per-server config structures */
+ NULL, /* command apr_table_t */
+ ap_proxy_store_score_register_hook /* register hooks */
+};
+
Index: mod_proxy_store.h
===================================================================
--- mod_proxy_store.h (revision 0)
+++ mod_proxy_store.h (revision 0)
@@ -0,0 +1,6 @@
+#define PROXY_STORAGE "proxystorage"
+struct proxy_storage_method {
+ void (*setstatus)(proxy_worker *worker, int status);
+ int (*getstatus)(proxy_worker *worker);
+};
+typedef struct proxy_storage_method proxy_storage_method;
Index: config.m4
===================================================================
--- config.m4 (revision 421342)
+++ config.m4 (working copy)
@@ -19,6 +19,7 @@
proxy_fcgi_objs="mod_proxy_fcgi.lo"
proxy_ajp_objs="mod_proxy_ajp.lo ajp_header.lo ajp_link.lo ajp_msg.lo"
proxy_balancer_objs="mod_proxy_balancer.lo"
+proxy_store_score="mod_proxy_store_score.lo"
case "$host" in
*os2*)
@@ -39,6 +40,7 @@
APACHE_MODULE(proxy_fcgi, Apache proxy FastCGI module, $proxy_fcgi_objs, ,
$proxy_mods_enable)
APACHE_MODULE(proxy_ajp, Apache proxy AJP module, $proxy_ajp_objs, ,
$proxy_mods_enable)
APACHE_MODULE(proxy_balancer, Apache proxy BALANCER module,
$proxy_balancer_objs, , $proxy_mods_enable)
+APACHE_MODULE(proxy_store_score, Apache proxy score board storage module,
$proxy_store_score_objs, , $proxy_mods_enable)
APR_ADDTO(INCLUDES, [-I\$(top_srcdir)/$modpath_current/../generators])
Index: mod_proxy.c
===================================================================
--- mod_proxy.c (revision 421342)
+++ mod_proxy.c (working copy)
@@ -17,6 +17,7 @@
#define CORE_PRIVATE
#include "mod_proxy.h"
+#include "mod_proxy_store.h"
#include "mod_core.h"
#include "apr_optional.h"
#include "scoreboard.h"
@@ -38,6 +39,11 @@
#endif
/*
+ * Storage for the comarea
+ */
+static const proxy_storage_method *storage = NULL;
+
+/*
* A Web proxy module. Stages:
*
* translate_name: set filename to proxy:<URL>
@@ -1075,6 +1081,14 @@
const char *err = ap_proxy_add_worker(&worker, cmd->pool, conf, r);
if (err)
return apr_pstrcat(cmd->temp_pool, "ProxyPass ", err, NULL);
+ if (storage) {
+ worker->context = (void *) storage;
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
+ "add_pass: storage %d", storage);
+ }
+ else
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
+ "add_pass: storage NULL");
} else {
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server,
"worker %s already used by another worker",
worker->name);
@@ -1475,6 +1489,14 @@
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server,
"worker %s already used by another worker",
worker->name);
}
+ if (storage) {
+ worker->context = (void *) storage;
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
+ "add_member: storage %d", storage);
+ }
+ else
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
+ "add_member: storage NULL");
PROXY_COPY_CONF_PARAMS(worker, conf);
arr = apr_table_elts(params);
@@ -1814,6 +1836,10 @@
char fbuf[50];
ap_rvputs(r, "<tr>\n<td>", worker->scheme, "</td>", NULL);
ap_rvputs(r, "<td>", worker->hostname, "</td><td>", NULL);
+ if (worker->context) {
+ proxy_storage_method *store = (proxy_storage_method *)
worker->context;
+ store->getstatus(worker);
+ }
if (worker->s->status & PROXY_WORKER_DISABLED)
ap_rputs("Dis", r);
else if (worker->s->status & PROXY_WORKER_IN_ERROR)
@@ -1911,6 +1937,13 @@
APR_HOOK_MIDDLE);
/* Reset workers count on gracefull restart */
proxy_lb_workers = 0;
+ storage = ap_lookup_provider(PROXY_STORAGE, "score", "0");
+ if (storage)
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
+ "proxy_pre_config: storage %d", storage);
+ else
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
+ "proxy_pre_config: storage NULL");
return OK;
}