From a6843ef1a4ca8f8187f5b70d21b46460635a5487 Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Tue, 27 Jul 2010 23:26:52 +0000 Subject: [PATCH] Re-enable transaction isolation level is serializable case. In this case we need to send SELECTs to primary only to keep serializable semantics. --- pool_process_query.c | 8 ++++++++ pool_proto_modules.c | 45 +++----------------------------------------- pool_query_context.c | 8 +++++--- 3 files changed, 16 insertions(+), 45 deletions(-) diff --git a/pool_process_query.c b/pool_process_query.c index f3248f97a..04d8be24f 100644 --- a/pool_process_query.c +++ b/pool_process_query.c @@ -1073,6 +1073,14 @@ POOL_STATUS SimpleForwardToFrontend(char kind, POOL_CONNECTION *frontend, return POOL_END; } + /* + * Check if packet kind == 'C'(Command complete), '1'(Parse + * complete), '3'(Close complete). If so, remember that we + * succeeded in executing command. + */ + if (kind == 'C' || kind == '1' || kind == '2' || kind == '3') + pool_set_command_success(); + #ifdef NOT_USED /* * Check if packet kind == 'C'(Command complete), '1'(Parse diff --git a/pool_proto_modules.c b/pool_proto_modules.c index 5132b81f1..922575ced 100644 --- a/pool_proto_modules.c +++ b/pool_proto_modules.c @@ -1316,44 +1316,6 @@ POOL_STATUS ReadyForQuery(POOL_CONNECTION *frontend, if ((len = pool_read_message_length(backend)) < 0) return POOL_END; -#ifdef NOT_USED - pool_debug("ReadyForQuery: message length: %d", len); - - /* - * Do not check transaction state in master/slave mode. - * Because SET, PREPARE, DEALLOCATE are replicated. - * If these queries are executed inside a transaction block, - * transation state will be inconsistent. But it is no problem. - */ - if (master_slave_dml) - { - char kind, kind1; - - if (pool_read(MASTER(backend), &kind, sizeof(kind))) - return POOL_END; - - for (i = 0; i < NUM_BACKENDS; i++) - { - if (!VALID_BACKEND(i) || IS_MASTER_NODE_ID(i)) - continue; - - if (pool_read(CONNECTION(backend, i), &kind1, sizeof(kind))) - return POOL_END; - } - state = kind; - } - else - { - state = pool_read_kind(backend); - if (state < 0) - return POOL_END; - } - - /* set transaction state */ - pool_debug("ReadyForQuery: transaction state: %c", state); - -#endif - /* * Set transaction state for each node */ @@ -1393,10 +1355,10 @@ POOL_STATUS ReadyForQuery(POOL_CONNECTION *frontend, pool_flush(frontend); } -#ifdef NOT_USED if (pool_is_query_in_progress() && pool_is_command_success()) -#endif +#ifdef NOT_USED if (pool_is_query_in_progress()) +#endif { Node *node; char *query; @@ -1417,7 +1379,6 @@ POOL_STATUS ReadyForQuery(POOL_CONNECTION *frontend, pool_unset_transaction_isolation(); } -#ifdef NOT_USED /* * SET TRANSACTION ISOLATION LEVEL SERIALIZABLE or SET * SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL @@ -1427,7 +1388,7 @@ POOL_STATUS ReadyForQuery(POOL_CONNECTION *frontend, { pool_set_transaction_isolation(POOL_SERIALIZABLE); } -#endif + /* * If 2PC commands, automatically close transaction on standbys since * 2PC commands close transaction on primary. diff --git a/pool_query_context.c b/pool_query_context.c index 80a3b0614..943ed9af5 100644 --- a/pool_query_context.c +++ b/pool_query_context.c @@ -337,7 +337,6 @@ void pool_where_to_send(POOL_QUERY_CONTEXT *query_context, char *query, Node *no is_select_query(node, query) && MAJOR(backend) == PROTO_MAJOR_V3) { -#ifdef NOT_USED /* * If (we are outside of an explicit transaction) OR * (the transaction has not issued a write query yet, AND @@ -347,7 +346,7 @@ void pool_where_to_send(POOL_QUERY_CONTEXT *query_context, char *query, Node *no if (TSTATE(backend, MASTER_NODE_ID) == 'I' || (!pool_is_writing_transaction() && pool_get_transaction_isolation() != POOL_SERIALIZABLE)) -#endif +#ifdef NOT_USED /* * If we are outside of an explicit transaction OR * the transaction has not issued a write query yet, @@ -355,6 +354,7 @@ void pool_where_to_send(POOL_QUERY_CONTEXT *query_context, char *query, Node *no */ if (TSTATE(backend, MASTER_NODE_ID) == 'I' || !pool_is_writing_transaction()) +#endif { BackendInfo *bkinfo = pool_get_node_info(session_context->load_balance_node_id); @@ -1023,6 +1023,7 @@ char *pool_get_query_string(void) * SET TRANSACTION ISOLATION LEVEL SERIALIZABLE or * SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE or * SET transaction_isolation TO 'serializable' + * SET default_transaction_isolation TO 'serializable' */ bool is_set_transaction_serializable(Node *node, char *query) { @@ -1060,7 +1061,8 @@ bool is_set_transaction_serializable(Node *node, char *query) foreach(list_item, options) { DefElem *opt = (DefElem *) lfirst(list_item); - if (!strcmp("transaction_isolation", opt->defname)) + if (!strcmp("transaction_isolation", opt->defname) || + !strcmp("default_transaction_isolation", opt->defname)) { A_Const *v = (A_Const *)opt->arg; -- 2.39.5