diff options
author | Pavan Deolasee | 2015-11-17 11:07:11 +0000 |
---|---|---|
committer | Pavan Deolasee | 2015-11-17 11:07:11 +0000 |
commit | b8c220b4d99dfb0517512371ade3d2c165dc7e03 (patch) | |
tree | 1e527995e733efdc01d3f5d9e07a8eaa38b349dc | |
parent | 114e8de2330dc74f4bc41bc185b2c4cc5dff5bec (diff) |
Cancel queries on remote connections upon transaction abort
-rw-r--r-- | src/backend/pgxc/pool/execRemote.c | 12 | ||||
-rw-r--r-- | src/backend/pgxc/pool/poolmgr.c | 9 | ||||
-rw-r--r-- | src/include/pgxc/poolutils.h | 3 |
3 files changed, 24 insertions, 0 deletions
diff --git a/src/backend/pgxc/pool/execRemote.c b/src/backend/pgxc/pool/execRemote.c index a92f5aef68..2c9e5b9203 100644 --- a/src/backend/pgxc/pool/execRemote.c +++ b/src/backend/pgxc/pool/execRemote.c @@ -3678,6 +3678,9 @@ PreAbort_Remote(void) PGXCNodeAllHandles *all_handles; PGXCNodeHandle *clean_nodes[NumCoords + NumDataNodes]; int node_count = 0; + int cancel_dn_count = 0, cancel_co_count = 0; + int cancel_dn_list[NumDataNodes]; + int cancel_co_list[NumCoords]; int i; struct rusage start_r; struct timeval start_t; @@ -3703,6 +3706,7 @@ PreAbort_Remote(void) */ handle->combiner = NULL; clean_nodes[node_count++] = handle; + cancel_co_list[cancel_co_count++] = i; } } @@ -3721,6 +3725,7 @@ PreAbort_Remote(void) */ handle->combiner = NULL; clean_nodes[node_count++] = handle; + cancel_dn_list[cancel_dn_count++] = i; } else if (handle->state == DN_CONNECTION_STATE_COPY_IN || handle->state == DN_CONNECTION_STATE_COPY_OUT) @@ -3732,10 +3737,17 @@ PreAbort_Remote(void) */ handle->combiner = NULL; clean_nodes[node_count++] = handle; + cancel_dn_list[cancel_dn_count++] = i; } } /* + * Cancel running queries on the datanodes and the coordinators. + */ + PoolManagerCancelQuery(cancel_dn_count, cancel_dn_list, cancel_co_count, + cancel_co_list); + + /* * Now read and discard any data from the connections found "dirty" */ if (node_count > 0) diff --git a/src/backend/pgxc/pool/poolmgr.c b/src/backend/pgxc/pool/poolmgr.c index 04bcd101d4..4a756424a4 100644 --- a/src/backend/pgxc/pool/poolmgr.c +++ b/src/backend/pgxc/pool/poolmgr.c @@ -1169,6 +1169,9 @@ agent_handle_input(PoolAgent * agent, StringInfo s) cancel_query_on_connections(agent, datanodelist, coordlist); list_free(datanodelist); list_free(coordlist); + + /* Send success result */ + pool_sendres(&agent->port, QUERY_CANCEL_COMPLETED); break; case 'o': /* Lock/unlock pooler */ pool_getmessage(&agent->port, s, 8); @@ -1476,6 +1479,12 @@ PoolManagerCancelQuery(int dn_count, int* dn_list, int co_count, int* co_list) } pool_putmessage(&poolHandle->port, 'h', (char *) buf, (2 + dn_count + co_count) * sizeof(uint32)); pool_flush(&poolHandle->port); + + /* Receive result message */ + if (pool_recvres(&poolHandle->port) != QUERY_CANCEL_COMPLETED) + ereport(WARNING, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("Query cancel not completed"))); } /* diff --git a/src/include/pgxc/poolutils.h b/src/include/pgxc/poolutils.h index cd261ac521..1b88b34e35 100644 --- a/src/include/pgxc/poolutils.h +++ b/src/include/pgxc/poolutils.h @@ -25,6 +25,9 @@ #define CLEAN_CONNECTION_TX_REMAIN 2 #define CLEAN_CONNECTION_EOF -1 +/* Results for query cancel */ +#define QUERY_CANCEL_COMPLETED 0 + /* Results for pooler connection info check */ #define POOL_CHECK_SUCCESS 0 #define POOL_CHECK_FAILED 1 |