pgpool2.git / summary / log / commit / refs
commit 5dee760e2d7d1142cae31ccf72238ff27a1cb915
Author: Tatsuo Ishii <ishii at sraoss.co.jp>
Date: Sun Jun 06 11:14:18 2010 +0000
Remove in_progress global variable.
pool_process_query.c | 17 ++++++-----------
pool_proto_modules.c | 4 +---
pool_proto_modules.h | 1 -
pool_query_context.c | 8 ++++----
pool_rewrite_query.c | 7 ++++---
pool_session_context.c | 42 ++++++++++++++++++++++++++++++++++++++++++
pool_session_context.h | 5 +++--
7 files changed, 60 insertions(+), 24 deletions(-)
diff --git a/pool_process_query.c b/pool_process_query.c
index f9eea4ff9..607037aa3 100644
--- a/pool_process_query.c
+++ b/pool_process_query.c
@@ -208,7 +208,7 @@ POOL_STATUS pool_process_query(POOL_CONNECTION *frontend,
/*
* Do not read a message from frontend while backends process a query.
*/
- if (!reset_request && !in_progress)
+ if (!reset_request && !pool_is_query_in_progress())
{
FD_SET(frontend->fd, &readmask);
FD_SET(frontend->fd, &exceptmask);
@@ -349,7 +349,7 @@ POOL_STATUS pool_process_query(POOL_CONNECTION *frontend,
if (was_error)
continue;
- if (!reset_request && !in_progress)
+ if (!reset_request && !pool_is_query_in_progress())
{
if (FD_ISSET(frontend->fd, &exceptmask))
return POOL_END;
@@ -372,7 +372,7 @@ POOL_STATUS pool_process_query(POOL_CONNECTION *frontend,
}
else
{
- if (!pool_read_buffer_is_empty(frontend) && !in_progress)
+ if (!pool_read_buffer_is_empty(frontend) && !pool_is_query_in_progress())
{
/* We do not read anything from frontend after receiving X packet.
* Just emit log message. This will guard us from buggy frontend.
@@ -623,7 +623,7 @@ POOL_STATUS pool_parallel_exec(POOL_CONNECTION *frontend,
{
pool_debug("process reporting");
process_reporting(frontend, backend);
- in_progress = 0;
+ pool_unset_query_in_progress();
return POOL_CONTINUE;
}
@@ -1191,8 +1191,6 @@ POOL_STATUS SimpleForwardToFrontend(char kind, POOL_CONNECTION *frontend, POOL_C
int delete_or_update = 0;
char kind1;
POOL_STATUS ret;
- POOL_SESSION_CONTEXT *session_context = pool_get_session_context();
- POOL_QUERY_CONTEXT *query_context = session_context->query_context;
/*
* Check if packet kind == 'C'(Command complete), '1'(Parse
@@ -1281,9 +1279,6 @@ POOL_STATUS SimpleForwardToFrontend(char kind, POOL_CONNECTION *frontend, POOL_C
{
if (VALID_BACKEND(i) && !IS_MASTER_NODE_ID(i))
{
- if (session_context->in_progress && !pool_is_node_to_be_sent(query_context, i))
- continue;
-
status = pool_read(CONNECTION(backend, i), &len, sizeof(len));
if (status < 0)
{
@@ -1904,7 +1899,7 @@ POOL_STATUS ParameterStatus(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *bac
*/
void reset_variables(void)
{
- in_progress = 0;
+ pool_unset_query_in_progress();
/* End load balance mode */
if (in_load_balance)
@@ -3447,7 +3442,7 @@ static int is_cache_empty(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backe
if (pool_ssl_pending(frontend))
return 0;
- if (!pool_read_buffer_is_empty(frontend) && !in_progress)
+ if (!pool_read_buffer_is_empty(frontend) && !pool_is_query_in_progress())
return 0;
for (i=0;i<NUM_BACKENDS;i++)
diff --git a/pool_proto_modules.c b/pool_proto_modules.c
index 3acae46da..fc2be9c76 100644
--- a/pool_proto_modules.c
+++ b/pool_proto_modules.c
@@ -60,7 +60,6 @@ int replication_was_enabled; /* replication mode was enabled */
int master_slave_was_enabled; /* master/slave mode was enabled */
int internal_transaction_started; /* to issue table lock command a transaction
has been started internally */
-int in_progress = 0; /* indicates while doing something after receiving Query */
int mismatch_ntuples; /* number of updated tuples */
char *copy_table = NULL; /* copy table name */
char *copy_schema = NULL; /* copy table name */
@@ -1301,7 +1300,7 @@ POOL_STATUS ReadyForQuery(POOL_CONNECTION *frontend,
pool_flush(frontend);
}
- in_progress = 0;
+ pool_unset_query_in_progress();
/* end load balance mode */
if (in_load_balance)
@@ -1545,7 +1544,6 @@ POOL_STATUS ProcessFrontendResponse(POOL_CONNECTION *frontend,
return POOL_END;
case 'Q': /* Query message*/
- in_progress = 1;
allow_close_transaction = 1;
status = SimpleQuery(frontend, backend, NULL);
break;
diff --git a/pool_proto_modules.h b/pool_proto_modules.h
index ecc2c93fb..544603480 100644
--- a/pool_proto_modules.h
+++ b/pool_proto_modules.h
@@ -59,7 +59,6 @@ extern int replication_was_enabled; /* replication mode was enabled */
extern int master_slave_was_enabled; /* master/slave mode was enabled */
extern int internal_transaction_started; /* to issue table lock command a transaction
has been started internally */
-extern int in_progress; /* indicates while doing something after receiving Query */
extern int mismatch_ntuples; /* number of updated tuples */
extern char *copy_table; /* copy table name */
extern char *copy_schema; /* copy table name */
diff --git a/pool_query_context.c b/pool_query_context.c
index 2779df3e7..3dda8b255 100644
--- a/pool_query_context.c
+++ b/pool_query_context.c
@@ -57,7 +57,7 @@ void pool_query_context_destroy(POOL_QUERY_CONTEXT *query_context)
if (query_context)
{
session_context = pool_get_session_context();
- session_context->in_progress = false;
+ pool_unset_query_in_progress();
session_context->query_context = NULL;
free(query_context);
}
@@ -75,7 +75,7 @@ void pool_start_query(POOL_QUERY_CONTEXT *query_context, char *query, Node *node
session_context = pool_get_session_context();
query_context->original_query = query;
query_context->parse_tree = node;
- session_context->in_progress = true;
+ pool_set_query_in_progress();
session_context->query_context = query_context;
}
}
@@ -173,7 +173,7 @@ bool pool_is_node_to_be_sent(POOL_QUERY_CONTEXT *query_context, int node_id)
}
/*
- * Return if the DB node is needed to send query.
+ * Return true if the DB node is needed to send query.
* Intended to be called from VALID_BACKEND
*/
bool pool_is_node_to_be_sent_in_current_query(int node_id)
@@ -184,7 +184,7 @@ bool pool_is_node_to_be_sent_in_current_query(int node_id)
if (!sc)
return true;
- if (sc->in_progress && sc->query_context)
+ if (pool_is_query_in_progress() && sc->query_context)
{
return pool_is_node_to_be_sent(sc->query_context, node_id);
}
diff --git a/pool_rewrite_query.c b/pool_rewrite_query.c
index eb3c83239..cc7866298 100644
--- a/pool_rewrite_query.c
+++ b/pool_rewrite_query.c
@@ -26,6 +26,7 @@
#include "pool_config.h"
#include "pool_rewrite_query.h"
#include "pool_proto_modules.h"
+#include "pool_session_context.h"
#include <string.h>
#include <errno.h>
@@ -685,7 +686,7 @@ POOL_STATUS pool_do_parallel_query(POOL_CONNECTION *frontend,
*/
POOL_STATUS stats = pool_parallel_exec(frontend,backend,r_query->rewrite_query, node,true);
free_parser();
- in_progress = 0;
+ pool_unset_query_in_progress();
return stats;
}
else if(!r_query->is_pg_catalog)
@@ -697,14 +698,14 @@ POOL_STATUS pool_do_parallel_query(POOL_CONNECTION *frontend,
free_parser();
if(r_query->r_code != INSERT_DIST_NO_RULE) {
- in_progress = 0;
+ pool_unset_query_in_progress();
return r_query->status;
}
}
else if(r_query->type == T_SelectStmt)
{
free_parser();
- in_progress = 0;
+ pool_unset_query_in_progress();
return r_query->status;
}
}
diff --git a/pool_session_context.c b/pool_session_context.c
index b48ab5d67..81c78589e 100644
--- a/pool_session_context.c
+++ b/pool_session_context.c
@@ -95,3 +95,45 @@ int pool_get_local_session_id(void)
return session_context->process_context->local_session_id;
}
+
+/*
+ * Return true if query is in progress
+ */
+bool pool_is_query_in_progress(void)
+{
+ if (!session_context)
+ {
+ pool_error("pool_is_query_in_progress: session context is not initialized");
+ return false;
+ }
+
+ return session_context->in_progress;
+}
+
+/*
+ * Set query is in progress
+ */
+void pool_set_query_in_progress(void)
+{
+ if (!session_context)
+ {
+ pool_error("pool_set_query_in_progress: session context is not initialized");
+ return;
+ }
+
+ session_context->in_progress = true;
+}
+
+/*
+ * Un set query is in progress
+ */
+void pool_unset_query_in_progress(void)
+{
+ if (!session_context)
+ {
+ pool_error("pool_unset_query_in_progress: session context is not initialized");
+ return;
+ }
+
+ session_context->in_progress = false;
+}
diff --git a/pool_session_context.h b/pool_session_context.h
index e1922c2cb..c64ef0c97 100644
--- a/pool_session_context.h
+++ b/pool_session_context.h
@@ -53,7 +53,6 @@ typedef struct {
int master_slave_was_enabled; /* master/slave mode was enabled */
int internal_transaction_started; /* to issue table lock command a transaction
has been started internally */
- int in_progress = 0; /* indicates while doing something after receiving Query */
int mismatch_ntuples; /* number of updated tuples */
char *copy_table = NULL; /* copy table name */
char *copy_schema = NULL; /* copy table name */
@@ -95,7 +94,6 @@ typedef struct {
char *parsed_query = NULL;
- bool in_progress; /* true if we are busy and do not accept input from frontend */
int load_balance_node_id; /* selected load balance node id */
bool received_write_query; /* have we recived a write query in this transaction? */
bool send_ready_for_query; /* ok to send ReadyForQuery */
@@ -112,5 +110,8 @@ typedef struct {
extern void pool_init_session_context(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend);
extern POOL_SESSION_CONTEXT *pool_get_session_context(void);
extern int pool_get_local_session_id(void);
+extern bool pool_is_query_in_progress(void);
+extern void pool_set_query_in_progress(void);
+extern void pool_unset_query_in_progress(void);
#endif /* POOL_SESSION_CONTEXT_H */
[parent: e17294173623]