pgpool2.git / summary / log / commit / refs
commit 1cd60b0597dedfb87dd1a8588a11e5dc4e9a3069
Author: Tatsuo Ishii <ishii@postgresql.org>
Date: Tue Mar 06 23:04:47 2012 +0000
Use pool_memory_context_switch_to() whenever possible.
pool_hba.c | 9 ++++-----
pool_process_query.c | 17 ++++++++---------
pool_proto_modules.c | 37 +++++++++++++++++++------------------
pool_query_context.c | 6 +++---
4 files changed, 34 insertions(+), 35 deletions(-)
diff --git a/pool_hba.c b/pool_hba.c
index dd5bdb901..be855121d 100644
--- a/pool_hba.c
+++ b/pool_hba.c
@@ -6,7 +6,7 @@
* pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
*
- * Portions Copyright (c) 2003-2010 PgPool Global Development Group
+ * Portions Copyright (c) 2003-2012 PgPool Global Development Group
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California *
* Permission to use, copy, modify, and distribute this software and
@@ -114,8 +114,7 @@ int load_hba(char *hbapath)
}
}
/* switch memory context */
- old_context = pool_memory;
- pool_memory = hba_memory_context;
+ old_context = pool_memory_context_switch_to(hba_memory_context);
if (hba_lines || hba_line_nums)
free_lines(&hba_lines, &hba_line_nums);
@@ -128,7 +127,7 @@ int load_hba(char *hbapath)
pool_memory_delete(hba_memory_context, 0);
/* switch to old memory context */
- pool_memory = old_context;
+ pool_memory_context_switch_to(old_context);
return -1;
}
@@ -142,7 +141,7 @@ int load_hba(char *hbapath)
hbaFileName = pstrdup(hbapath);
/* switch to old memory context */
- pool_memory = old_context;
+ pool_memory_context_switch_to(old_context);
return 0;
}
diff --git a/pool_process_query.c b/pool_process_query.c
index dd23c0bc0..94c3af8f5 100644
--- a/pool_process_query.c
+++ b/pool_process_query.c
@@ -3124,20 +3124,20 @@ bool is_partition_table(POOL_CONNECTION_POOL *backend, Node *node)
static char *get_insert_command_table_name(InsertStmt *node)
{
POOL_SESSION_CONTEXT *session_context;
- POOL_MEMORY_POOL *old_context = pool_memory;
+ POOL_MEMORY_POOL *old_context;
session_context = pool_get_session_context();
if (!session_context)
return NULL;
if (session_context->query_context)
- pool_memory = session_context->query_context->memory_context;
+ old_context = pool_memory_context_switch_to(session_context->query_context->memory_context);
else
- pool_memory = session_context->memory_context;
+ old_context = pool_memory_context_switch_to(session_context->memory_context);
char *table = nodeToString(node->relation);
- pool_memory = old_context;
+ pool_memory_context_switch_to(old_context);
pool_debug("get_insert_command_table_name: extracted table name: %s", table);
return table;
@@ -3312,7 +3312,7 @@ POOL_STATUS read_kind_from_backend(POOL_CONNECTION *frontend, POOL_CONNECTION_PO
int degenerate_node_num = 0; /* number of backends degeneration requested */
int degenerate_node[MAX_NUM_BACKENDS]; /* degeneration requested backend list */
- POOL_MEMORY_POOL *old_context = NULL;
+ POOL_MEMORY_POOL *old_context;
POOL_SESSION_CONTEXT *session_context = pool_get_session_context();
POOL_QUERY_CONTEXT *query_context = session_context->query_context;
@@ -3435,11 +3435,10 @@ POOL_STATUS read_kind_from_backend(POOL_CONNECTION *frontend, POOL_CONNECTION_PO
if (degenerate_node_num)
{
- old_context = pool_memory;
if (query_context)
- pool_memory = query_context->memory_context;
+ old_context = pool_memory_context_switch_to(query_context->memory_context);
else
- pool_memory = session_context->memory_context;
+ old_context = pool_memory_context_switch_to(session_context->memory_context);
String *msg = init_string("kind mismatch among backends. ");
@@ -3524,7 +3523,7 @@ POOL_STATUS read_kind_from_backend(POOL_CONNECTION *frontend, POOL_CONNECTION_PO
free_string(msg);
/* Switch to old memory context */
- pool_memory = old_context;
+ pool_memory_context_switch_to(old_context);
if (pool_config->replication_stop_on_mismatch)
{
diff --git a/pool_proto_modules.c b/pool_proto_modules.c
index 0ad818994..aebd8f1e6 100644
--- a/pool_proto_modules.c
+++ b/pool_proto_modules.c
@@ -177,8 +177,7 @@ POOL_STATUS SimpleQuery(POOL_CONNECTION *frontend,
/* switch memory context */
if (pool_memory == NULL)
pool_memory = pool_memory_create(PARSER_BLOCK_SIZE);
- old_context = pool_memory;
- pool_memory = query_context->memory_context;
+ old_context = pool_memory_context_switch_to(query_context->memory_context);
/* parse SQL string */
parse_tree_list = raw_parser(contents);
@@ -240,6 +239,7 @@ POOL_STATUS SimpleQuery(POOL_CONNECTION *frontend,
{
pool_query_context_destroy(query_context);
pool_set_skip_reading_from_backends();
+ pool_memory_context_switch_to(old_context);
return POOL_CONTINUE;
}
}
@@ -258,6 +258,7 @@ POOL_STATUS SimpleQuery(POOL_CONNECTION *frontend,
if (parallel)
{
pool_query_context_destroy(query_context);
+ pool_memory_context_switch_to(old_context);
return status;
}
}
@@ -571,7 +572,7 @@ POOL_STATUS SimpleQuery(POOL_CONNECTION *frontend,
}
/* switch memory context */
- pool_memory = old_context;
+ pool_memory_context_switch_to(old_context);
return POOL_CONTINUE;
}
@@ -760,8 +761,7 @@ POOL_STATUS Parse(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend,
/* switch memory context */
if (pool_memory == NULL)
pool_memory = pool_memory_create(PARSER_BLOCK_SIZE);
- old_context = pool_memory;
- pool_memory = query_context->memory_context;
+ old_context = pool_memory_context_switch_to(query_context->memory_context);
/* parse SQL string */
parse_tree_list = raw_parser(stmt);
@@ -881,7 +881,8 @@ POOL_STATUS Parse(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend,
query_context->rewritten_query = pstrdup("BEGIN");
}
}
- pool_memory = old_context;
+
+ pool_memory_context_switch_to(old_context);
if (REPLICATION)
{
@@ -1327,12 +1328,12 @@ POOL_STATUS ReadyForQuery(POOL_CONNECTION *frontend,
{
int i;
String *msg;
- POOL_MEMORY_POOL *old_context = pool_memory;
+ POOL_MEMORY_POOL *old_context;
if (session_context->query_context)
- pool_memory = session_context->query_context->memory_context;
+ old_context = pool_memory_context_switch_to(session_context->query_context->memory_context);
else
- pool_memory = session_context->memory_context;
+ old_context = pool_memory_context_switch_to(session_context->memory_context);
msg = init_string("ReadyForQuery: Degenerate backends:");
@@ -1354,7 +1355,7 @@ POOL_STATUS ReadyForQuery(POOL_CONNECTION *frontend,
pool_log("%s", msg->data);
free_string(msg);
- pool_memory = old_context;
+ pool_memory_context_switch_to(old_context);
degenerate_backend_set(victim_nodes, number_of_nodes);
child_exit(1);
@@ -1869,12 +1870,12 @@ POOL_STATUS CommandComplete(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *bac
if (session_context->mismatch_ntuples)
{
char msgbuf[128];
- POOL_MEMORY_POOL *old_context = pool_memory;
+ POOL_MEMORY_POOL *old_context;
if (session_context->query_context)
- pool_memory = session_context->query_context->memory_context;
+ old_context = pool_memory_context_switch_to(session_context->query_context->memory_context);
else
- pool_memory = session_context->memory_context;
+ old_context = pool_memory_context_switch_to(session_context->memory_context);
String *msg = init_string("pgpool detected difference of the number of inserted, updated or deleted tuples. Possible last query was: \"");
string_append_char(msg, query_string_buffer);
@@ -1895,7 +1896,7 @@ POOL_STATUS CommandComplete(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *bac
pool_log("%s", msg->data);
free_string(msg);
- pool_memory = old_context;
+ pool_memory_context_switch_to(old_context);
}
else
{
@@ -2924,7 +2925,7 @@ static int check_errors(POOL_CONNECTION_POOL *backend, int backend_id)
static void generate_error_message(char *prefix, int specific_error, char *query)
{
POOL_SESSION_CONTEXT *session_context;
- POOL_MEMORY_POOL *old_context = pool_memory;
+ POOL_MEMORY_POOL *old_context;
session_context = pool_get_session_context();
if (!session_context)
@@ -2948,16 +2949,16 @@ static void generate_error_message(char *prefix, int specific_error, char *query
specific_error--;
if (session_context->query_context)
- pool_memory = session_context->query_context->memory_context;
+ old_context = pool_memory_context_switch_to(session_context->query_context->memory_context);
else
- pool_memory = session_context->memory_context;
+ old_context = pool_memory_context_switch_to(session_context->memory_context);
msg = init_string(prefix);
string_append_char(msg, error_messages[specific_error]);
pool_error(msg->data, query);
free_string(msg);
- pool_memory = old_context;
+ pool_memory_context_switch_to(old_context);
}
/*
diff --git a/pool_query_context.c b/pool_query_context.c
index c762c9da9..bd9fc1797 100644
--- a/pool_query_context.c
+++ b/pool_query_context.c
@@ -334,11 +334,11 @@ void pool_where_to_send(POOL_QUERY_CONTEXT *query_context, char *query, Node *no
else if (MASTER_SLAVE)
{
POOL_DEST dest;
- POOL_MEMORY_POOL *old_context = pool_memory;
+ POOL_MEMORY_POOL *old_context;
- pool_memory = query_context->memory_context;
+ old_context = pool_memory_context_switch_to(query_context->memory_context);
dest = send_to_where(node, query);
- pool_memory = old_context;
+ pool_memory_context_switch_to(old_context);
pool_debug("send_to_where: %d query: %s", dest, query);
[parent: 0d7c8a3f3406]