pgpool2.git / summary / log / commit / refs
commit ded3fa823f59b661ed06cb446fa38902b92a3970
Author: Muhammad Usama <m.usama@gmail.com>
Date: Tue Aug 05 15:05:09 2014 +0000
Back porting coverity issues fix patch from master branch.
Fix coverity issue:1111377 Unchecked return value
Fix coverity issue:1111381 Logically dead code
Fix coverity issue:1222992 Unchecked return value
Fix coverity issue:1222993 Unchecked return value
Fix coverity issue:1222996 Printf arg type mismatch
Fix coverity issue:1222997 Printf arg type mismatch
For the coverity issue 1222996 and 1222997 the return type of NameListToString function
is changed from string* to char*, and defination of the which is the return type of the function in PostgreSQL source.
and appropriate changes have been made in the code to incorporate this function return type change.
For coverity issue:1222992 1222993 the return type of do_query() function is changed to void from POOL_STATUS.
The function’s return value became insignificant after the introduction of elog API,
After the API do_query() only returns in a successful scenarios and throws an ereport
in case of any error within the function.
src/auth/pool_auth.c | 5 ---
src/context/pool_session_context.c | 19 ++++++++-
src/include/parser/pool_string.h | 2 +-
src/include/pool.h | 2 +-
src/main/pgpool_main.c | 48 ++++++++++++++++-------
src/parser/outfuncs.c | 56 +++++++++++++++------------
src/protocol/child.c | 5 ++-
src/protocol/pool_process_query.c | 55 +++++++++++---------------
src/query_cache/pool_memqcache.c | 9 +----
src/rewrite/pool_lobj.c | 7 +---
src/rewrite/pool_timestamp.c | 17 +-------
src/streaming_replication/pool_worker_child.c | 27 ++++++++-----
src/test/timestamp/main.c | 4 +-
src/utils/pool_relcache.c | 42 ++++++++++++--------
14 files changed, 157 insertions(+), 141 deletions(-)
diff --git a/src/auth/pool_auth.c b/src/auth/pool_auth.c
index b7c543a5a..f78cfc77a 100644
--- a/src/auth/pool_auth.c
+++ b/src/auth/pool_auth.c
@@ -357,11 +357,6 @@ int pool_do_auth(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *cp)
*/
if (protoMajor == PROTO_MAJOR_V3)
{
- if (kind != 'K')
- ereport(ERROR,
- (errmsg("authentication failed"),
- errdetail("invalid find \"%c\" when expecting \"K\"",kind)));
-
if ((length = pool_read_message_length(cp)) != 12)
{
ereport(ERROR,
diff --git a/src/context/pool_session_context.c b/src/context/pool_session_context.c
index 18cc73abb..8644b1cfb 100644
--- a/src/context/pool_session_context.c
+++ b/src/context/pool_session_context.c
@@ -33,7 +33,7 @@
static POOL_SESSION_CONTEXT session_context_d;
static POOL_SESSION_CONTEXT *session_context = NULL;
-
+static void GetTranIsolationErrorCb(void *arg);
static void init_sent_message_list(void);
/*
@@ -725,6 +725,7 @@ POOL_TRANSACTION_ISOLATION pool_get_transaction_isolation(void)
{
POOL_SELECT_RESULT *res;
POOL_TRANSACTION_ISOLATION ret;
+ ErrorContextCallback callback;
if (!session_context)
{
@@ -735,11 +736,21 @@ POOL_TRANSACTION_ISOLATION pool_get_transaction_isolation(void)
/* It seems cached result is usable. Return it. */
if (session_context->transaction_isolation != POOL_UNKNOWN)
return session_context->transaction_isolation;
+ /*
+ * Register a error context callback to throw proper context message
+ */
+ callback.callback = GetTranIsolationErrorCb;
+ callback.arg = NULL;
+ callback.previous = error_context_stack;
+ error_context_stack = &callback;
/* No cached data is available. Ask backend. */
+
do_query(MASTER(session_context->backend),
"SELECT current_setting('transaction_isolation')", &res, MAJOR(session_context->backend));
+ error_context_stack = callback.previous;
+
if (res->numrows <= 0)
{
pool_error("pool_get_transaction_isolation: do_query returns no rows");
@@ -782,6 +793,12 @@ POOL_TRANSACTION_ISOLATION pool_get_transaction_isolation(void)
return ret;
}
+static void GetTranIsolationErrorCb(void *arg)
+{
+ errcontext("While getting transaction isolation");
+}
+
+
/*
* The command in progress has not succeeded yet.
*/
diff --git a/src/include/parser/pool_string.h b/src/include/parser/pool_string.h
index f5fc9aa04..886cb320b 100644
--- a/src/include/parser/pool_string.h
+++ b/src/include/parser/pool_string.h
@@ -28,7 +28,7 @@ typedef struct
char *data;
} String;
-extern String *NameListToString(List *names);
+extern char *NameListToString(List *names);
extern String *init_string(char *str);
extern void string_append_string(String *string, String *append_data);
extern void string_append_char(String *string, char *append_data);
diff --git a/src/include/pool.h b/src/include/pool.h
index c60247749..196ce2a8e 100644
--- a/src/include/pool.h
+++ b/src/include/pool.h
@@ -651,7 +651,7 @@ extern void per_node_error_log(POOL_CONNECTION_POOL *backend, int node_id, char
extern int pool_extract_error_message(bool read_kind, POOL_CONNECTION *backend, int major, bool unread, char **message);
extern POOL_STATUS do_command(POOL_CONNECTION *frontend, POOL_CONNECTION *backend,
char *query, int protoMajor, int pid, int key, int no_ready_for_query);
-extern POOL_STATUS do_query(POOL_CONNECTION *backend, char *query, POOL_SELECT_RESULT **result, int major);
+extern void do_query(POOL_CONNECTION *backend, char *query, POOL_SELECT_RESULT **result, int major);
extern void free_select_result(POOL_SELECT_RESULT *result);
extern int compare(const void *p1, const void *p2);
extern POOL_STATUS do_error_execute_command(POOL_CONNECTION_POOL *backend, int node_id, int major);
diff --git a/src/main/pgpool_main.c b/src/main/pgpool_main.c
index 75b040355..c123ff1ed 100644
--- a/src/main/pgpool_main.c
+++ b/src/main/pgpool_main.c
@@ -2137,29 +2137,47 @@ static bool
pool_config->sr_check_password, true);
if (s)
{
+ MemoryContext oldContext = CurrentMemoryContext;
con = s->con;
- do_query(con, "SELECT pg_is_in_recovery()",
- &res, PROTO_MAJOR_V3);
- if (res->numrows <= 0)
+
+ PG_TRY();
{
- ereport(LOG,
- (errmsg("verify_backend_node_status: do_query returns no rows")));
- }
- if (res->data[0] == NULL)
- {
- ereport(LOG,
- (errmsg("verify_backend_node_status: do_query returns no data")));
+ do_query(con, "SELECT pg_is_in_recovery()",
+ &res, PROTO_MAJOR_V3);
}
- if (res->nullflags[0] == -1)
+ PG_CATCH();
{
+ /* ignore the error message */
+ res = NULL;
+ MemoryContextSwitchTo(oldContext);
+ FlushErrorState();
ereport(LOG,
- (errmsg("verify_backend_node_status: do_query returns NULL")));
+ (errmsg("verify_backend_node_status: do_query failed")));
}
- if (res->data[0] && !strcmp(res->data[0], "t"))
+ PG_END_TRY();
+ if(res)
{
- *is_standby = true;
+ if (res->numrows <= 0)
+ {
+ ereport(LOG,
+ (errmsg("verify_backend_node_status: do_query returns no rows")));
+ }
+ if (res->data[0] == NULL)
+ {
+ ereport(LOG,
+ (errmsg("verify_backend_node_status: do_query returns no data")));
+ }
+ if (res->nullflags[0] == -1)
+ {
+ ereport(LOG,
+ (errmsg("verify_backend_node_status: do_query returns NULL")));
+ }
+ if (res->data[0] && !strcmp(res->data[0], "t"))
+ {
+ *is_standby = true;
+ }
+ free_select_result(res);
}
- free_select_result(res);
discard_persistent_db_connection(s);
return true;
}
diff --git a/src/parser/outfuncs.c b/src/parser/outfuncs.c
index de220b41c..4f8829a87 100644
--- a/src/parser/outfuncs.c
+++ b/src/parser/outfuncs.c
@@ -24,6 +24,7 @@
#include <limits.h>
#include "pool_type.h"
#include "utils/palloc.h"
+#include "utils/elog.h"
#include "parser.h"
#include "pool_string.h"
#include "pg_list.h"
@@ -188,42 +189,44 @@ static void _outCurrentOfExpr(String *str, CurrentOfExpr *node);
/*
- * Shamelessly copied from backend/catalog/namespace.c
- *
+ * Borrowed from backend/catalog/namespace.c
* NameListToString
- * Utility routine to convert a qualified-name list into a string.
+ * Utility routine to convert a qualified-name list into a string.
+ *
+ * This is used primarily to form error messages, and so we do not quote
+ * the list elements, for the sake of legibility.
*
* In most scenarios the list elements should always be Value strings,
* but we also allow A_Star for the convenience of ColumnRef processing.
*/
-String *NameListToString(List *names)
+char *
+NameListToString(List *names)
{
- String *str;
- ListCell *l;
- char *p;
+ StringInfoData string;
+ ListCell *l;
- str = init_string("");
-
- foreach(l, names)
- {
- Node *name = (Node *) lfirst(l);
+ initStringInfo(&string);
- if (l != list_head(names))
- string_append_char(str, ".");
+ foreach(l, names)
+ {
+ Node *name = (Node *) lfirst(l);
- if (IsA(name, String))
- string_append_char(str, strVal(name));
- else if (IsA(name, A_Star))
- string_append_char(str, "*");
- }
+ if (l != list_head(names))
+ appendStringInfoChar(&string, '.');
- p = palloc(str->len+1);
- memcpy(p, str->data, str->len);
- *(p+str->len) = '\0';
+ if (IsA(name, String))
+ appendStringInfoString(&string, strVal(name));
+ else if (IsA(name, A_Star))
+ appendStringInfoString(&string, "*");
+ else
+ elog(ERROR, "unexpected node type in name list: %d",
+ (int) nodeTag(name));
+ }
- return str;
+ return string.data;
}
+
static char *escape_string(char *str)
{
int len = strlen(str), i, j;
@@ -3648,7 +3651,7 @@ _outDropStmt(String *str, DropStmt *node)
string_append_char(str, strVal(llast(objname)));
string_append_char(str, " ON ");
string_append_char(str, NameListToString(list_truncate(list_copy(objname),
- list_length(objname) - 1))->data);
+ list_length(objname) - 1)));
break;
case OBJECT_OPERATOR:
@@ -3663,7 +3666,10 @@ _outDropStmt(String *str, DropStmt *node)
objname = lfirst(list_head(node->objects));
string_append_char(str, strVal(llast(objname)));
string_append_char(str, " USING ");
- _outNode(str, NameListToString(list_truncate(list_copy(objname), list_length(objname) - 1)));
+ string_append_char(str, "'");
+ string_append_char(str, escape_string(NameListToString(list_truncate(list_copy(objname), list_length(objname) - 1))));
+ string_append_char(str, "'");
+
break;
case OBJECT_CAST:
diff --git a/src/protocol/child.c b/src/protocol/child.c
index 92e6f62dd..6a2a4612b 100644
--- a/src/protocol/child.c
+++ b/src/protocol/child.c
@@ -1646,8 +1646,9 @@ static void init_system_db_connection(void)
{
if (pool_config->parallel_mode)
{
- system_db_connect();
- if (PQstatus(system_db_info->pgconn) != CONNECTION_OK)
+ int nRet;
+ nRet = system_db_connect();
+ if (nRet || PQstatus(system_db_info->pgconn) != CONNECTION_OK)
{
ereport(ERROR,
(errmsg("failed to make persistent system db connection"),
diff --git a/src/protocol/pool_process_query.c b/src/protocol/pool_process_query.c
index 073d5ba18..ecbc695fa 100644
--- a/src/protocol/pool_process_query.c
+++ b/src/protocol/pool_process_query.c
@@ -2258,8 +2258,10 @@ void free_select_result(POOL_SELECT_RESULT *result)
* can be SELECT or any other type of query. However at this moment,
* the only client calls this function other than SELECT is
* insert_lock(), and the qury is either LOCK or SELECT for UPDATE.
+ * Note: After the introduction of elog API the return type of do_query is changed
+ * to void. and now ereport is thrown in case of error occured within the function
*/
-POOL_STATUS do_query(POOL_CONNECTION *backend, char *query, POOL_SELECT_RESULT **result, int major)
+void do_query(POOL_CONNECTION *backend, char *query, POOL_SELECT_RESULT **result, int major)
{
#define DO_QUERY_ALLOC_NUM 1024 /* memory allocation unit for POOL_SELECT_RESULT */
@@ -2505,7 +2507,7 @@ POOL_STATUS do_query(POOL_CONNECTION *backend, char *query, POOL_SELECT_RESULT *
case 'Z': /* Ready for query */
pool_debug("do_query: Ready for query");
if (!doing_extended)
- return POOL_CONTINUE;
+ return;
break;
case 'C': /* Command Complete */
@@ -2723,7 +2725,6 @@ POOL_STATUS do_query(POOL_CONNECTION *backend, char *query, POOL_SELECT_RESULT *
break;
}
}
- return POOL_CONTINUE;
}
/*
@@ -2848,7 +2849,6 @@ POOL_STATUS insert_lock(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend
char *table, *p;
int len = 0;
char qbuf[1024];
- POOL_STATUS status;
int i, deadlock_detected = 0;
char *adsrc;
char seq_rel_name[MAX_NAME_LEN+1];
@@ -2858,6 +2858,7 @@ POOL_STATUS insert_lock(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend
regmatch_t pmatch[nmatch];
static POOL_RELCACHE *relcache;
POOL_SELECT_RESULT *result;
+ POOL_STATUS status = POOL_CONTINUE;
/* insert_lock can be used in V3 only */
if (MAJOR(backend) != PROTO_MAJOR_V3)
@@ -2986,9 +2987,7 @@ POOL_STATUS insert_lock(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend
{
if (pool_get_session_context(true) && pool_is_doing_extended_query_message())
{
- status = do_query(MASTER(backend), qbuf, &result, MAJOR(backend));
- if (result)
- free_select_result(result);
+ do_query(MASTER(backend), qbuf, &result, MAJOR(backend));
}
else
{
@@ -2998,15 +2997,13 @@ POOL_STATUS insert_lock(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend
}
else if (lock_kind == 2)
{
- status = do_query(MASTER(backend), qbuf, &result, MAJOR(backend));
- if (result)
- free_select_result(result);
+ do_query(MASTER(backend), qbuf, &result, MAJOR(backend));
}
else
{
POOL_SELECT_RESULT *result;
/* issue row lock command */
- status = do_query(MASTER(backend), qbuf, &result, MAJOR(backend));
+ do_query(MASTER(backend), qbuf, &result, MAJOR(backend));
if (status == POOL_CONTINUE)
{
/* does oid exist in insert_lock table? */
@@ -3022,15 +3019,13 @@ POOL_STATUS insert_lock(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend
per_node_statement_log(backend, MASTER_NODE_ID, qbuf);
/* issue row lock command */
- status = do_query(MASTER(backend), qbuf, &result, MAJOR(backend));
- if (status == POOL_CONTINUE)
- {
- if (!(result && result->data[0] && !strcmp(result->data[0], "1")))
- ereport(FATAL,
- (return_code(2),
- errmsg("failed to get insert lock"),
- errdetail("unexpected data from backend")));
- }
+ do_query(MASTER(backend), qbuf, &result, MAJOR(backend));
+
+ if (!(result && result->data[0] && !strcmp(result->data[0], "1")))
+ ereport(FATAL,
+ (return_code(2),
+ errmsg("failed to get insert lock"),
+ errdetail("unexpected data from backend")));
}
}
}
@@ -3047,7 +3042,7 @@ POOL_STATUS insert_lock(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend
if (pool_get_session_context(true) && pool_is_doing_extended_query_message())
{
- status = do_query(MASTER(backend), qbuf, &result, MAJOR(backend));
+ do_query(MASTER(backend), qbuf, &result, MAJOR(backend));
if (result)
free_select_result(result);
}
@@ -3080,7 +3075,7 @@ POOL_STATUS insert_lock(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend
per_node_statement_log(backend, i, qbuf);
if (pool_get_session_context(true) && pool_is_doing_extended_query_message())
{
- status = do_query(MASTER(backend), qbuf, &result, MAJOR(backend));
+ do_query(MASTER(backend), qbuf, &result, MAJOR(backend));
if (result)
free_select_result(result);
}
@@ -3094,9 +3089,7 @@ POOL_STATUS insert_lock(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend
{
POOL_SELECT_RESULT *result;
per_node_statement_log(backend, i, qbuf);
- status = do_query(CONNECTION(backend,i), qbuf, &result, MAJOR(backend));
- if (result)
- free_select_result(result);
+ do_query(CONNECTION(backend,i), qbuf, &result, MAJOR(backend));
}
}
@@ -3208,7 +3201,6 @@ static bool has_lock_target(POOL_CONNECTION *frontend,
{
char *suffix;
char qbuf[QUERY_STRING_BUFFER_LEN];
- POOL_STATUS status;
POOL_SELECT_RESULT *result;
suffix = lock ? " FOR UPDATE" : "";
@@ -3226,14 +3218,11 @@ static bool has_lock_target(POOL_CONNECTION *frontend,
}
per_node_statement_log(backend, MASTER_NODE_ID, qbuf);
- status = do_query(MASTER(backend), qbuf, &result, MAJOR(backend));
- if (status == POOL_CONTINUE)
+ do_query(MASTER(backend), qbuf, &result, MAJOR(backend));
+ if (result && result->data[0] && !strcmp(result->data[0], "1"))
{
- if (result && result->data[0] && !strcmp(result->data[0], "1"))
- {
- free_select_result(result);
- return true;
- }
+ free_select_result(result);
+ return true;
}
if (result)
diff --git a/src/query_cache/pool_memqcache.c b/src/query_cache/pool_memqcache.c
index aeb1841bd..b39ad9bc3 100644
--- a/src/query_cache/pool_memqcache.c
+++ b/src/query_cache/pool_memqcache.c
@@ -1205,14 +1205,7 @@ int pool_get_database_oid_from_dbname(char *dbname)
backend = pool_get_session_context(false)->backend;
snprintf(query, sizeof(query), DATABASE_TO_OID_QUERY, dbname);
- status = do_query(MASTER(backend), query, &res, MAJOR(backend));
-
- if (status != POOL_CONTINUE)
- {
- pool_debug("pool_discard_oid_maps_by_db: Failed.");
- free_select_result(res);
- return 0;
- }
+ do_query(MASTER(backend), query, &res, MAJOR(backend));
if (res->numrows != 1)
{
diff --git a/src/rewrite/pool_lobj.c b/src/rewrite/pool_lobj.c
index 1587f72cd..271b6fa1f 100644
--- a/src/rewrite/pool_lobj.c
+++ b/src/rewrite/pool_lobj.c
@@ -181,12 +181,7 @@ char *pool_rewrite_lo_creat(char kind, char *packet, int packet_len,
/* get max lobj id */
per_node_statement_log(backend, MASTER_NODE_ID, GET_MAX_LOBJ_KEY);
- status = do_query(MASTER(backend), GET_MAX_LOBJ_KEY, &result, MAJOR(backend));
- if (status == POOL_END)
- {
- pool_error("pool_rewrite_lo_creat: do_query failed");
- return NULL;
- }
+ do_query(MASTER(backend), GET_MAX_LOBJ_KEY, &result, MAJOR(backend));
if (!result)
{
diff --git a/src/rewrite/pool_timestamp.c b/src/rewrite/pool_timestamp.c
index cf2ef33a7..6f930a8d5 100644
--- a/src/rewrite/pool_timestamp.c
+++ b/src/rewrite/pool_timestamp.c
@@ -306,16 +306,9 @@ static char *
get_current_timestamp(POOL_CONNECTION_POOL *backend)
{
POOL_SELECT_RESULT *res;
- POOL_STATUS status;
static char timestamp[64];
- status = do_query(MASTER(backend), "SELECT now()", &res, MAJOR(backend));
- if (status != POOL_CONTINUE)
- {
- pool_error("get_current_timestamp: do_query failed");
- free_select_result(res);
- return NULL;
- }
+ do_query(MASTER(backend), "SELECT now()", &res, MAJOR(backend));
if (res->numrows != 1)
{
@@ -884,13 +877,7 @@ static A_Const *makeStringConstFromQuery(POOL_CONNECTION_POOL *backend, char *ex
char *str;
snprintf(query, sizeof(query), "SELECT %s", expression);
- status = do_query(MASTER(backend), query, &res, MAJOR(backend));
- if (status != POOL_CONTINUE)
- {
- pool_error("makeStringConstFromQuery: do_query failed");
- free_select_result(res);
- return NULL;
- }
+ do_query(MASTER(backend), query, &res, MAJOR(backend));
if (res->numrows != 1)
{
diff --git a/src/streaming_replication/pool_worker_child.c b/src/streaming_replication/pool_worker_child.c
index d824d94e2..3bc8396a0 100644
--- a/src/streaming_replication/pool_worker_child.c
+++ b/src/streaming_replication/pool_worker_child.c
@@ -73,6 +73,7 @@ static volatile sig_atomic_t restart_request = 0;
static void establish_persistent_connection(void);
static void discard_persistent_connection(void);
static void check_replication_time_lag(void);
+static void CheckReplicationTimeLagErrorCb(void *arg);
static unsigned long long int text_to_lsn(char *text);
static RETSIGTYPE my_signal_handler(int sig);
static RETSIGTYPE reload_config_handler(int sig);
@@ -232,12 +233,12 @@ static void check_replication_time_lag(void)
{
int i;
int active_nodes = 0;
- POOL_STATUS sts;
POOL_SELECT_RESULT *res;
unsigned long long int lsn[MAX_NUM_BACKENDS];
char *query;
BackendInfo *bkinfo;
unsigned long long int lag;
+ ErrorContextCallback callback;
if (NUM_BACKENDS <= 1)
{
@@ -265,6 +266,14 @@ static void check_replication_time_lag(void)
return;
}
+ /*
+ * Register a error context callback to throw proper context message
+ */
+ callback.callback = CheckReplicationTimeLagErrorCb;
+ callback.arg = NULL;
+ callback.previous = error_context_stack;
+ error_context_stack = &callback;
+
for (i=0;i<NUM_BACKENDS;i++)
{
if (!VALID_BACKEND(i))
@@ -288,14 +297,8 @@ static void check_replication_time_lag(void)
query = "SELECT pg_last_xlog_replay_location()";
}
- sts = do_query(slots[i]->con, query, &res, PROTO_MAJOR_V3);
- if (sts != POOL_CONTINUE)
- {
- if (res)
- free_select_result(res);
- pool_error("check_replication_time_lag: %s failed", query);
- return;
- }
+ do_query(slots[i]->con, query, &res, PROTO_MAJOR_V3);
+
if (!res)
{
ereport(ERROR,
@@ -361,8 +364,14 @@ static void check_replication_time_lag(void)
}
}
}
+
+ error_context_stack = callback.previous;
}
+static void CheckReplicationTimeLagErrorCb(void *arg)
+{
+ errcontext("While checking replication time lag");
+}
/*
* Convert logid/recoff style text to 64bit log location (LSN)
*/
diff --git a/src/test/timestamp/main.c b/src/test/timestamp/main.c
index c821ccd86..4745cd6b2 100644
--- a/src/test/timestamp/main.c
+++ b/src/test/timestamp/main.c
@@ -65,8 +65,7 @@ pool_search_relcache(POOL_RELCACHE *relcache, POOL_CONNECTION_POOL *backend, cha
return (void *) &(rc[1]);
}
-POOL_STATUS
-do_query(POOL_CONNECTION *backend, char *query, POOL_SELECT_RESULT **result, int major) {
+void do_query(POOL_CONNECTION *backend, char *query, POOL_SELECT_RESULT **result, int major) {
static POOL_SELECT_RESULT res;
static char *data[1] = {
"2009-01-01 23:59:59.123456+09"
@@ -76,7 +75,6 @@ do_query(POOL_CONNECTION *backend, char *query, POOL_SELECT_RESULT **result, int
res.data = data;
*result = &res;
- return POOL_CONTINUE;
}
int
diff --git a/src/utils/pool_relcache.c b/src/utils/pool_relcache.c
index ae96edd9d..6bf48ddde 100644
--- a/src/utils/pool_relcache.c
+++ b/src/utils/pool_relcache.c
@@ -29,7 +29,11 @@
#include "utils/pool_relcache.h"
#include "context/pool_session_context.h"
#include "pool_config.h"
+#include "utils/palloc.h"
+#include "utils/memutils.h"
+#include "utils/elog.h"
+static void SearchRelCacheErrorCb(void *arg);
/*
* Create relation cache
*/
@@ -103,20 +107,16 @@ void *pool_search_relcache(POOL_RELCACHE *relcache, POOL_CONNECTION_POOL *backen
int local_session_id;
time_t now;
void *result;
+ ErrorContextCallback callback;
/* Eliminate double quotes */
- rel = malloc(strlen(table)+1);
- if (!rel)
- {
- pool_error("pool_search_relcache: malloc failed");
- return NULL;
- }
+ rel = palloc(strlen(table)+1);
local_session_id = pool_get_local_session_id();
if (local_session_id < 0)
{
pool_error("pool_search_relcache: pool_get_local_session_id failed");
- free(rel);
+ pfree(rel);
return NULL;
}
@@ -160,7 +160,7 @@ void *pool_search_relcache(POOL_RELCACHE *relcache, POOL_CONNECTION_POOL *backen
/* Found */
if (relcache->cache[i].refcnt < INT_MAX)
relcache->cache[i].refcnt++;
- free(rel);
+ pfree(rel);
return relcache->cache[i].data;
}
}
@@ -170,14 +170,17 @@ void *pool_search_relcache(POOL_RELCACHE *relcache, POOL_CONNECTION_POOL *backen
per_node_statement_log(backend, MASTER_NODE_ID, query);
- if (do_query(MASTER(backend), query, &res, MAJOR(backend)) != POOL_CONTINUE)
- {
- pool_error("pool_search_relcache: do_query failed");
- if (res)
- free_select_result(res);
- free(rel);
- return NULL;
- }
+ /*
+ * Register a error context callback to throw proper context message
+ */
+ callback.callback = SearchRelCacheErrorCb;
+ callback.arg = NULL;
+ callback.previous = error_context_stack;
+ error_context_stack = &callback;
+
+ do_query(MASTER(backend), query, &res, MAJOR(backend));
+
+ error_context_stack = callback.previous;
/*
* Look for replacement in cache
@@ -238,12 +241,17 @@ void *pool_search_relcache(POOL_RELCACHE *relcache, POOL_CONNECTION_POOL *backen
(*relcache->unregister_func)(relcache->cache[index].data);
relcache->cache[index].data = result;
}
- free(rel);
+ pfree(rel);
free_select_result(res);
return result;
}
+static void SearchRelCacheErrorCb(void *arg)
+{
+ errcontext("While searching system catalog, When relcache is missed");
+}
+
/*
* Standard register/unregister function for "SELECT count(*)" type
* query. Returns row count.
[parent: e5e4115c0fd6]