summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuhammad Usama2015-01-30 11:12:47 +0000
committerMuhammad Usama2015-01-30 11:12:47 +0000
commite456a3259928efd84d0e4bf74197df08d8b9ee23 (patch)
treeeb13004bb33fb71a06ead88af324ec6f91ee7ea6
parenta413848101a6fadd7ce49478f3c6ac070732053c (diff)
Back porting the patch for fixing the behavior of "client_min_messages"
configuration parameter. This parameter controls the minimum message levels to be sent to the frontend. The problem was, Regardless of the value of the parameter all the messages with severity less than NOTICE level were not being forwarded to the client, reason was an invalid check in elog.c send_message_to_frontend() function. And secondly, the commit fixes a mistake in documentation regarding the valid values for this parameter. Severity levels PANIC and FATAL are always sent to the frontend and these two values are not valid configurations for the "client_min_messages", so removing the PANIC and FATAL as valid values from the documentation of client_min_messages.
-rw-r--r--doc/pgpool-en.html4
-rw-r--r--src/include/pool.h4
-rw-r--r--src/protocol/child.c104
-rw-r--r--src/utils/error/elog.c68
4 files changed, 99 insertions, 81 deletions
diff --git a/doc/pgpool-en.html b/doc/pgpool-en.html
index 01c135bca..0946df623 100644
--- a/doc/pgpool-en.html
+++ b/doc/pgpool-en.html
@@ -855,8 +855,8 @@ local0.* /var/log/pgpool.log
<p>
Controls which minimum message levels are sent to the client.
Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, LOG, NOTICE,
- WARNING, ERROR, FATAL, and PANIC. Each level includes all the
- levels that follow it. The default is NOTICE.
+ WARNING and ERROR. Each level includes all the levels that follow it.
+ The default is NOTICE.
</p>
<p>
You need to reload pgpool.conf if you change this value.
diff --git a/src/include/pool.h b/src/include/pool.h
index 66df92fc3..bb56cfe88 100644
--- a/src/include/pool.h
+++ b/src/include/pool.h
@@ -645,6 +645,10 @@ extern void cancel_request(CancelPacket *sp);
extern void check_stop_request(void);
extern void pool_initialize_private_backend_status(void);
extern bool is_session_connected(void);
+extern int send_to_pg_frontend(char* data, int len, bool flush);
+extern int pg_frontend_exists(void);
+extern int set_pg_frontend_blocking(bool blocking);
+extern int get_frontend_protocol_version(void);
/* pool_process_query.c */
extern void reset_variables(void);
diff --git a/src/protocol/child.c b/src/protocol/child.c
index 1c3f8faf0..b56bfd005 100644
--- a/src/protocol/child.c
+++ b/src/protocol/child.c
@@ -115,6 +115,7 @@ volatile sig_atomic_t got_sighup = 0;
char remote_host[NI_MAXHOST]; /* client host */
char remote_port[NI_MAXSERV]; /* client port */
+POOL_CONNECTION* volatile child_frontend = NULL;
/*
* child main loop
@@ -122,8 +123,6 @@ char remote_port[NI_MAXSERV]; /* client port */
void do_child(int *fds)
{
sigjmp_buf local_sigjmp_buf;
-
- POOL_CONNECTION* volatile frontend = NULL;
POOL_CONNECTION_POOL* volatile backend = NULL;
struct timeval now;
struct timezone tz;
@@ -209,13 +208,12 @@ void do_child(int *fds)
pool_reopen_passwd_file();
}
-
if (sigsetjmp(local_sigjmp_buf, 1) != 0)
{
- POOL_PROCESS_CONTEXT *session;
+ POOL_PROCESS_CONTEXT *session;
disable_authentication_timeout();
/* Since not using PG_TRY, must reset error stack by hand */
- error_context_stack = NULL;
+ error_context_stack = NULL;
EmitErrorReport();
/* process the cleanup in ProcessLoopContext which will get reset
@@ -225,37 +223,37 @@ void do_child(int *fds)
if (accepted)
connection_count_down();
-
- backend_cleanup(&frontend, backend);
- session = pool_get_process_context();
+ backend_cleanup(&child_frontend, backend);
- if(session)
- {
- /* Destroy session context */
- pool_session_context_destroy();
+ session = pool_get_process_context();
- /* Mark this connection pool is not connected from frontend */
- pool_coninfo_unset_frontend_connected(pool_get_process_context()->proc_id, pool_pool_index());
+ if(session)
+ {
+ /* Destroy session context */
+ pool_session_context_destroy();
- /* increment queries counter if necessary */
- if ( pool_config->child_max_connections > 0 )
- connections_count++;
+ /* Mark this connection pool is not connected from frontend */
+ pool_coninfo_unset_frontend_connected(pool_get_process_context()->proc_id, pool_pool_index());
- /* check if maximum connections count for this child reached */
- if ( ( pool_config->child_max_connections > 0 ) &&
- ( connections_count >= pool_config->child_max_connections ) )
- {
- ereport(LOG,
- (errmsg("child exiting, %d connections reached", pool_config->child_max_connections)));
+ /* increment queries counter if necessary */
+ if ( pool_config->child_max_connections > 0 )
+ connections_count++;
+
+ /* check if maximum connections count for this child reached */
+ if ( ( pool_config->child_max_connections > 0 ) &&
+ ( connections_count >= pool_config->child_max_connections ) )
+ {
+ ereport(LOG,
+ (errmsg("child exiting, %d connections reached", pool_config->child_max_connections)));
child_exit(2);
- }
+ }
}
- if(frontend)
+ if(child_frontend)
{
- pool_close(frontend);
- frontend = NULL;
+ pool_close(child_frontend);
+ child_frontend = NULL;
}
MemoryContextSwitchTo(TopMemoryContext);
@@ -306,10 +304,10 @@ void do_child(int *fds)
check_config_reload();
validate_backend_connectivity(front_end_fd);
- frontend = get_connection(front_end_fd, &saddr);
+ child_frontend = get_connection(front_end_fd, &saddr);
/* set frontend fd to blocking */
- pool_unset_nonblock(frontend->fd);
+ pool_unset_nonblock(child_frontend->fd);
/* reset busy flag */
idle = 0;
@@ -321,11 +319,11 @@ void do_child(int *fds)
backend_timer_expired = 0;
}
- backend = get_backend_connection(frontend);
+ backend = get_backend_connection(child_frontend);
if(!backend)
{
- pool_close(frontend);
- frontend = NULL;
+ pool_close(child_frontend);
+ child_frontend = NULL;
continue;
}
connected = 1;
@@ -340,7 +338,7 @@ void do_child(int *fds)
/*
* Initialize per session context
*/
- pool_init_session_context(frontend, backend);
+ pool_init_session_context(child_frontend, backend);
/*
* Mark this connection pool is connected from frontend
@@ -361,10 +359,10 @@ void do_child(int *fds)
MemoryContextSwitchTo(QueryContext);
MemoryContextResetAndDeleteChildren(QueryContext);
- status = pool_process_query(frontend, backend, 0);
+ status = pool_process_query(child_frontend, backend, 0);
if(status != POOL_CONTINUE)
{
- backend_cleanup(&frontend, backend);
+ backend_cleanup(&child_frontend, backend);
break;
}
}
@@ -2367,3 +2365,39 @@ static int choose_db_node_id(char *str)
}
return node_id;
}
+
+int send_to_pg_frontend(char* data, int len, bool flush)
+{
+ int ret;
+ if (processType != PT_CHILD || child_frontend == NULL)
+ return -1;
+ ret = pool_write_noerror(child_frontend, data, len);
+ if(flush && !ret)
+ ret = pool_flush_it(child_frontend);
+ return ret;
+}
+
+int set_pg_frontend_blocking(bool blocking)
+{
+ if (processType != PT_CHILD || child_frontend == NULL)
+ return -1;
+ if (blocking)
+ pool_unset_nonblock(child_frontend->fd);
+ else
+ pool_set_nonblock(child_frontend->fd);
+ return 0;
+}
+
+int get_frontend_protocol_version(void)
+{
+ if (processType != PT_CHILD || child_frontend == NULL)
+ return -1;
+ return child_frontend->protoVersion;
+}
+
+int pg_frontend_exists(void)
+{
+ if (processType != PT_CHILD || child_frontend == NULL)
+ return -1;
+ return 0;
+}
diff --git a/src/utils/error/elog.c b/src/utils/error/elog.c
index d8bef513e..f23b56112 100644
--- a/src/utils/error/elog.c
+++ b/src/utils/error/elog.c
@@ -146,7 +146,6 @@ static void write_syslog(int level, const char *line);
static void send_message_to_server_log(ErrorData *edata);
static void send_message_to_frontend(ErrorData *edata);
static void write_console(const char *line, int len);
-static void send_message_to_frontend(ErrorData *edata);
static void log_line_prefix(StringInfo buf, const char *line_prefix, ErrorData *edata);
static const char *process_log_prefix_padding(const char *p, int *ppadding);
#ifdef WIN32
@@ -198,25 +197,6 @@ in_error_recursion_trouble(void)
}
/*
- * One of those fallback steps is to stop trying to localize the error
- * message, since there's a significant probability that that's exactly
- * what's causing the recursion.
- */
-static inline const char *
-err_gettext(const char *str)
-{
-#ifdef ENABLE_NLS
- if (in_error_recursion_trouble())
- return str;
- else
- return gettext(str);
-#else
- return str;
-#endif
-}
-
-
-/*
* errstart --- begin an error-reporting cycle
*
* Create a stack entry and store the given parameters in it. Subsequently,
@@ -283,7 +263,7 @@ errstart(int elevel, const char *filename, int lineno,
output_to_server = is_log_level_output(elevel, pool_config->log_min_messages);
/* Determine whether message is enabled for client output */
- if (whereToSendOutput == DestRemote && elevel != COMMERROR)
+ if (elevel != COMMERROR)
{
/*
* client_min_messages is honored only after we complete the
@@ -1745,28 +1725,28 @@ write_console(const char *line, int len)
static void
send_message_to_frontend(ErrorData *edata)
{
- if(processType != PT_CHILD)
- return;
- if(edata->elevel < NOTICE)
- return;
+ int protoVersion;
- POOL_SESSION_CONTEXT *session = pool_get_session_context(true);
- if(!session || !session->frontend)
- return;
+ if (pg_frontend_exists() < 0 )
+ return;
- POOL_CONNECTION *frontend = session->frontend;
+ /*
+ * Do not forward the debug messages to client before session is initialized
+ */
+ if (edata->elevel < ERROR && pool_get_session_context(true) == NULL)
+ return;
- pool_set_nonblock(frontend->fd);
-
- if (frontend->protoVersion == PROTO_MAJOR_V2)
+ protoVersion = get_frontend_protocol_version();
+ set_pg_frontend_blocking(false);
+
+ if (protoVersion == PROTO_MAJOR_V2)
{
- char* message = edata->message?edata->message:"missing error text";
- pool_write_noerror(frontend, (edata->elevel < ERROR) ? "N" : "E", 1);
- pool_write_noerror(frontend, message, strlen(message));
- pool_write_noerror(frontend, "\n", 1);
- pool_flush_it(frontend);
+ char* message = edata->message?edata->message:"missing error text";
+ send_to_pg_frontend((edata->elevel < ERROR) ? "N" : "E", 1,false);
+ send_to_pg_frontend(message, strlen(message),false);
+ send_to_pg_frontend("\n", 1,true);
}
- else if (frontend->protoVersion == PROTO_MAJOR_V3)
+ else if (protoVersion == PROTO_MAJOR_V3)
{
/*
* Buffer length for each message part
@@ -1784,10 +1764,10 @@ send_message_to_frontend(ErrorData *edata)
int len;
int thislen;
int sendlen;
-
+
len = 0;
memset(data, 0, MAXDATA);
- pool_write_noerror(frontend, (edata->elevel < ERROR) ? "N" : "E", 1);
+ send_to_pg_frontend((edata->elevel < ERROR) ? "N" : "E", 1, false);
/* error level */
thislen = snprintf(msgbuf, MAXMSGBUF, "S%s", error_severity(edata->elevel));
@@ -1843,12 +1823,12 @@ send_message_to_frontend(ErrorData *edata)
sendlen = len;
len = htonl(len + 4);
- pool_write_noerror(frontend, &len, sizeof(len));
- pool_write_noerror(frontend, data, sendlen);
- pool_flush_it(frontend);
+ send_to_pg_frontend((char*)&len, sizeof(len), false);
+ send_to_pg_frontend(data, sendlen, true);
}
- pool_unset_nonblock(frontend->fd);
+
+ set_pg_frontend_blocking(true);
}
/*