pgpool2.git / summary / log / commit / refs

commit    0b2082bb1f5b07cd801a0d66faa9f0a32f1b3b48
Author:   Tatsuo Ishii <ishii at sraoss.co.jp>
Date:     Wed Jun 02 06:52:34 2010 +0000

    Introduce process context module


Makefile.am | 3 +- Makefile.in | 6 ++-- child.c | 4 +++ pool.h | 2 -- pool_connection_pool.c | 3 +- pool_process_context.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++ pool_process_context.h | 52 +++++++++++++++++++++++++++++++++ 7 files changed, 142 insertions(+), 6 deletions(-) diff --git a/Makefile.am b/Makefile.am index 4e9819eab..5fa9fe73b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,7 +13,8 @@ pgpool_SOURCES = pool.h pool_type.h version.h pgpool.conf.sample \ ps_status.c strlcpy.c recovery.c pool_relcache.c pool_relcache.h pool_process_reporting.c \ pool_ssl.c pool_timestamp.c pool_timestamp.h \ pool_proto_modules.c pool_proto_modules.h \ - pool_lobj.c pool_lobj.h + pool_lobj.c pool_lobj.h \ + pool_process_context.c pool_process_context.h pg_md5_SOURCES = pg_md5.c md5.c md5.h diff --git a/Makefile.in b/Makefile.in index bfdf5cc75..618fa5c6b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -75,7 +75,7 @@ am_pgpool_OBJECTS = main.$(OBJEXT) child.$(OBJEXT) pool_auth.$(OBJEXT) \ strlcpy.$(OBJEXT) recovery.$(OBJEXT) pool_relcache.$(OBJEXT) \ pool_process_reporting.$(OBJEXT) pool_ssl.$(OBJEXT) \ pool_timestamp.$(OBJEXT) pool_proto_modules.$(OBJEXT) \ - pool_lobj.$(OBJEXT) + pool_lobj.$(OBJEXT) pool_process_context.$(OBJEXT) pgpool_OBJECTS = $(am_pgpool_OBJECTS) pgpool_DEPENDENCIES = parser/libsql-parser.a pcp/libpcp.la \ parser/nodes.o @@ -246,7 +246,8 @@ pgpool_SOURCES = pool.h pool_type.h version.h pgpool.conf.sample \ ps_status.c strlcpy.c recovery.c pool_relcache.c pool_relcache.h pool_process_reporting.c \ pool_ssl.c pool_timestamp.c pool_timestamp.h \ pool_proto_modules.c pool_proto_modules.h \ - pool_lobj.c pool_lobj.h + pool_lobj.c pool_lobj.h \ + pool_process_context.c pool_process_context.h pg_md5_SOURCES = pg_md5.c md5.c md5.h sysconf_DATA = pgpool.conf.sample pcp.conf.sample pool_hba.conf.sample \ @@ -408,6 +409,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pool_lobj.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pool_params.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pool_path.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pool_process_context.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pool_process_query.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pool_process_reporting.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pool_proto_modules.Po@am__quote@ diff --git a/child.c b/child.c index be0651b60..4dceaed46 100644 --- a/child.c +++ b/child.c @@ -50,6 +50,7 @@ #endif #include "pool.h" +#include "pool_process_context.h" #include "pool_config.h" #include "pool_ip.h" #include "md5.h" @@ -128,6 +129,9 @@ void do_child(int unix_fd, int inet_fd) } #endif + /* Initialize per process context */ + pool_init_process_context(); + /* initialize random seed */ gettimeofday(&now, &tz); srandom((unsigned int) now.tv_usec); diff --git a/pool.h b/pool.h index dafa0113e..3586095d2 100644 --- a/pool.h +++ b/pool.h @@ -280,8 +280,6 @@ typedef struct { #define CONN_COUNTER_SEM 0 #define REQUEST_INFO_SEM 1 -#define MY_PROCESS_INFO (process_info[my_proc_id]) - /* * number specified when semaphore is locked/unlocked */ diff --git a/pool_connection_pool.c b/pool_connection_pool.c index ce33e0dbe..4c6700653 100644 --- a/pool_connection_pool.c +++ b/pool_connection_pool.c @@ -45,6 +45,7 @@ #include "pool.h" #include "pool_stream.h" #include "pool_config.h" +#include "pool_process_context.h" POOL_CONNECTION_POOL *pool_connection_pool; /* connection pool */ volatile sig_atomic_t backend_timer_expired = 0; /* flag for connection closed timer is expired */ @@ -70,7 +71,7 @@ int pool_init_cp(void) for (i = 0; i < pool_config->max_pool; i++) { - pool_connection_pool[i].info = &(MY_PROCESS_INFO.connection_info[i]); + pool_connection_pool[i].info = &(pool_get_my_process_info()->connection_info[i]); memset(pool_connection_pool[i].info, 0, sizeof(ConnectionInfo) * MAX_NUM_BACKENDS); } return 0; diff --git a/pool_process_context.c b/pool_process_context.c new file mode 100644 index 000000000..6eaa56a79 --- /dev/null +++ b/pool_process_context.c @@ -0,0 +1,78 @@ +/* -*-pgsql-c-*- */ +/* + * + * $Header$ + * + * pgpool: a language independent connection pool server for PostgreSQL + * written by Tatsuo Ishii + * + * Copyright (c) 2003-2010 PgPool Global Development Group + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby + * granted, provided that the above copyright notice appear in all + * copies and that both that copyright notice and this permission + * notice appear in supporting documentation, and that the name of the + * author not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. The author makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + */ + +#include "pool.h" +#include "pool_process_context.h" +#include "pool_config.h" /* remove me afterwards */ + +static POOL_PROCESS_CONTEXT process_context_d; +static POOL_PROCESS_CONTEXT *process_context; + +/* + * Initialize per process context + */ +void pool_init_process_context(void) +{ + process_context = &process_context_d; + + if (!process_info) + { + pool_error("pool_init_process_context: process_info is not set"); + child_exit(1); + } + process_context->process_info = process_info; + + if (!pool_config->backend_desc) + { + pool_error("pool_init_process_context: backend_desc is not set"); + child_exit(1); + } + process_context->backend_desc = pool_config->backend_desc; +} + +/* + * Return process context + */ +POOL_PROCESS_CONTEXT *pool_get_process_context(void) +{ + if (!process_context) + { + pool_error("pool_get_process_context: Process context is not initialized"); + } + return process_context; +} + +/* + * Return my process info + */ +ProcessInfo *pool_get_my_process_info(void) +{ + if (!process_context) + { + pool_error("pool_get_my_process_info: Process context is not initialized"); + return NULL; + } + + return &process_context->process_info[process_context->proc_id]; +} + diff --git a/pool_process_context.h b/pool_process_context.h new file mode 100644 index 000000000..373d3ee87 --- /dev/null +++ b/pool_process_context.h @@ -0,0 +1,52 @@ +/* -*-pgsql-c-*- */ +/* + * + * $Header$ + * + * pgpool: a language independent connection pool server for PostgreSQL + * written by Tatsuo Ishii + * + * Copyright (c) 2003-2010 PgPool Global Development Group + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby + * granted, provided that the above copyright notice appear in all + * copies and that both that copyright notice and this permission + * notice appear in supporting documentation, and that the name of the + * author not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. The author makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * pool_process_context.h.: process context information + * + */ + +#ifndef POOL_PROCESS_CONTEXT_H +#define POOL_PROCESS_CONTEXT_H +#include "pool.h" + +/* + * Child process context: + * Manages per pgpool child process context + */ +typedef struct { + /* + * process start time, info on connection to backend etc. + */ + ProcessInfo *process_info; + int proc_id; /* Index to process table(ProcessInfo) (!= UNIX's PID) */ + + /* + * PostgreSQL server description. Placed on shared memory. + * Includes backend up/down info, hostname, data directory etc. + */ + BackendDesc *backend_desc; +} POOL_PROCESS_CONTEXT; + +extern void pool_init_process_context(void); +extern POOL_PROCESS_CONTEXT *pool_get_process_context(void); +extern ProcessInfo *pool_get_my_process_info(void); + +#endif /* POOL_PROCESS_CONTEXT_H */ [parent: 043e3afc20df]