From 4e81a71cb4ea65ab1d7c336c0d8a456334022823 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Wed, 30 Oct 2024 08:23:48 +0500 Subject: [PATCH 1/8] use enum and bit mask --- src/diskquota.c | 33 ++++++++++----------- src/diskquota.h | 16 +++++----- src/diskquota_utility.c | 66 +++++++++++++++++++++-------------------- src/gp_activetable.c | 8 ++--- src/quotamodel.c | 36 +++++++++++----------- 5 files changed, 79 insertions(+), 80 deletions(-) diff --git a/src/diskquota.c b/src/diskquota.c index 420a2b21..ace084be 100644 --- a/src/diskquota.c +++ b/src/diskquota.c @@ -958,7 +958,7 @@ disk_quota_launcher_main(Datum main_arg) static void create_monitor_db_table(void) { - SPI_state state; + int state; const char *sql; /* @@ -986,7 +986,7 @@ create_monitor_db_table(void) */ PG_TRY(); { - SPI_connect_wrapper(&state); + state = SPI_connect_wrapper(); /* debug_query_string need to be set for SPI_execute utility functions. */ debug_query_string = sql; @@ -1005,13 +1005,13 @@ create_monitor_db_table(void) HOLD_INTERRUPTS(); EmitErrorReport(); FlushErrorState(); - state.do_commit = false; + state |= is_abort; debug_query_string = NULL; /* Now we can allow interrupts again */ RESUME_INTERRUPTS(); } PG_END_TRY(); - SPI_finish_wrapper(&state); + SPI_finish_wrapper(state); debug_query_string = NULL; } @@ -1023,18 +1023,17 @@ create_monitor_db_table(void) static void init_database_list(void) { - SPI_state state; TupleDesc tupdesc; int num = 0; int ret; int i; + int state = SPI_connect_wrapper(); /* * Don't catch errors in start_workers_from_dblist. Since this is the * startup worker for diskquota launcher. If error happens, we just let * launcher exits. */ - SPI_connect_wrapper(&state); ret = SPI_execute("select dbid from diskquota_namespace.database_list;", true, 0); if (ret != SPI_OK_SELECT) @@ -1104,7 +1103,7 @@ init_database_list(void) update_monitor_db_mpp(dbEntry->dbid, ADD_DB_TO_MONITOR, LAUNCHER_SCHEMA); } } - SPI_finish_wrapper(&state); + SPI_finish_wrapper(state); /* TODO: clean invalid database */ if (num_db > diskquota_max_workers) DiskquotaLauncherShmem->isDynamicWorker = true; } @@ -1153,8 +1152,8 @@ process_extension_ddl_message() static void do_process_extension_ddl_message(MessageResult *code, ExtensionDDLMessage local_extension_ddl_message) { - SPI_state state; - int old_num_db = num_db; + int state; + int old_num_db = num_db; /* * Cache Errors during SPI functions, for example a segment may be down @@ -1163,7 +1162,7 @@ do_process_extension_ddl_message(MessageResult *code, ExtensionDDLMessage local_ */ PG_TRY(); { - SPI_connect_wrapper(&state); + state = SPI_connect_wrapper(); switch (local_extension_ddl_message.cmd) { @@ -1190,22 +1189,22 @@ do_process_extension_ddl_message(MessageResult *code, ExtensionDDLMessage local_ HOLD_INTERRUPTS(); EmitErrorReport(); FlushErrorState(); - state.do_commit = false; - num_db = old_num_db; + state |= is_abort; + num_db = old_num_db; RESUME_INTERRUPTS(); } PG_END_TRY(); - SPI_finish_wrapper(&state); + SPI_finish_wrapper(state); /* update something in memory after transaction committed */ - if (state.do_commit) + if (!(state & is_abort)) { PG_TRY(); { /* update_monitor_db_mpp runs sql to distribute dbid to segments */ Oid dbid = local_extension_ddl_message.dbid; - SPI_connect_wrapper(&state); + state = SPI_connect_wrapper(); switch (local_extension_ddl_message.cmd) { case CMD_CREATE_EXTENSION: @@ -1234,12 +1233,12 @@ do_process_extension_ddl_message(MessageResult *code, ExtensionDDLMessage local_ HOLD_INTERRUPTS(); EmitErrorReport(); FlushErrorState(); - state.do_commit = false; + state |= is_abort; RESUME_INTERRUPTS(); } PG_END_TRY(); - SPI_finish_wrapper(&state); + SPI_finish_wrapper(state); } DisconnectAndDestroyAllGangs(false); } diff --git a/src/diskquota.h b/src/diskquota.h index 97796588..c647c783 100644 --- a/src/diskquota.h +++ b/src/diskquota.h @@ -75,13 +75,13 @@ extern int diskquota_worker_timeout; #define DiskquotaGetRelstorage(classForm) (0) #endif /* GP_VERSION_NUM */ -typedef struct +enum { - bool is_connected; - bool is_active_snapshot_pushed; - bool do_commit; - bool is_under_transaction; -} SPI_state; + is_connected = 1 << 0, + is_active_snapshot_pushed = 1 << 1, + is_abort = 1 << 2, + is_under_transaction = 1 << 3, +}; typedef enum { @@ -327,6 +327,6 @@ extern HTAB *DiskquotaShmemInitHash(const char *name, long init_size, long max_s extern void refresh_monitored_dbid_cache(void); extern HASHACTION check_hash_fullness(HTAB *hashp, int max_size, const char *warning_message, TimestampTz *last_overflow_report); -void SPI_connect_wrapper(SPI_state *state); -void SPI_finish_wrapper(const SPI_state *state); +int SPI_connect_wrapper(void); +void SPI_finish_wrapper(int state); #endif diff --git a/src/diskquota_utility.c b/src/diskquota_utility.c index 649d7417..f530d6a0 100644 --- a/src/diskquota_utility.c +++ b/src/diskquota_utility.c @@ -1236,10 +1236,8 @@ set_per_segment_quota(PG_FUNCTION_ARGS) int worker_spi_get_extension_version(int *major, int *minor) { - SPI_state state; - int ret; - - SPI_connect_wrapper(&state); + int ret; + int state = SPI_connect_wrapper(); ret = SPI_execute("select extversion from pg_extension where extname = 'diskquota'", true, 0); @@ -1284,7 +1282,7 @@ worker_spi_get_extension_version(int *major, int *minor) ret = 0; out: - SPI_finish_wrapper(&state); + SPI_finish_wrapper(state); return ret; } @@ -1301,11 +1299,9 @@ worker_spi_get_extension_version(int *major, int *minor) List * get_rel_oid_list(bool is_init) { - SPI_state state; - List *oidlist = NIL; - int ret; - - SPI_connect_wrapper(&state); + List *oidlist = NIL; + int ret; + int state = SPI_connect_wrapper(); #define SELECT_FROM_PG_CATALOG_PG_CLASS "select oid from pg_catalog.pg_class where oid >= $1 and relkind in ('r', 'm')" @@ -1353,7 +1349,7 @@ get_rel_oid_list(bool is_init) MemoryContextSwitchTo(oldcontext); } } - SPI_finish_wrapper(&state); + SPI_finish_wrapper(state); return oidlist; } @@ -1715,47 +1711,53 @@ check_hash_fullness(HTAB *hashp, int max_size, const char *warning_message, Time return HASH_FIND; } -void -SPI_connect_wrapper(SPI_state *state) +int +SPI_connect_wrapper(void) { int rc; - - state->is_connected = false; - state->is_active_snapshot_pushed = false; - state->is_under_transaction = false; - state->do_commit = true; + int state = 0; SetCurrentStatementStartTimestamp(); + if (!IsTransactionState()) { StartTransactionCommand(); - state->is_under_transaction = true; + state |= is_under_transaction; } - if ((rc = SPI_connect()) != SPI_OK_CONNECT) - ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("[diskquota] SPI_connect failed"), - errdetail("%s", SPI_result_code_string(rc)))); - state->is_connected = true; - if (state->is_under_transaction) + + if (!SPI_context()) + { + if ((rc = SPI_connect()) != SPI_OK_CONNECT) + ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("[diskquota] SPI_connect failed"), + errdetail("%s", SPI_result_code_string(rc)))); + state |= is_connected; + } + + if (state & is_under_transaction) { PushActiveSnapshot(GetTransactionSnapshot()); - state->is_active_snapshot_pushed = true; + state |= is_active_snapshot_pushed; } + + return state; } void -SPI_finish_wrapper(const SPI_state *state) +SPI_finish_wrapper(int state) { int rc; - if (state->is_connected && (rc = SPI_finish()) != SPI_OK_FINISH) + if ((state & is_connected) && (rc = SPI_finish()) != SPI_OK_FINISH) ereport(WARNING, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("[diskquota] SPI_finish failed"), errdetail("%s", SPI_result_code_string(rc)))); - if (state->is_active_snapshot_pushed) PopActiveSnapshot(); - if (state->is_under_transaction) + + if (state & is_active_snapshot_pushed) PopActiveSnapshot(); + + if (state & is_under_transaction) { - if (state->do_commit) - CommitTransactionCommand(); - else + if (state & is_abort) AbortCurrentTransaction(); + else + CommitTransactionCommand(); } } diff --git a/src/gp_activetable.c b/src/gp_activetable.c index 53c89e35..7bc475b1 100644 --- a/src/gp_activetable.c +++ b/src/gp_activetable.c @@ -946,16 +946,14 @@ get_active_tables_oid(void) static void load_table_size(HTAB *local_table_stats_map) { - SPI_state state; TupleDesc tupdesc; int i; bool found; ActiveTableEntryCombined *quota_entry; SPIPlanPtr plan; Portal portal; - char *sql = "select tableid, size, segid from diskquota.table_size"; - - SPI_connect_wrapper(&state); + char *sql = "select tableid, size, segid from diskquota.table_size"; + int state = SPI_connect_wrapper(); if ((plan = SPI_prepare(sql, 0, NULL)) == NULL) ereport(ERROR, (errmsg("[diskquota] SPI_prepare(\"%s\") failed", sql))); @@ -1031,7 +1029,7 @@ load_table_size(HTAB *local_table_stats_map) SPI_freetuptable(SPI_tuptable); SPI_cursor_close(portal); SPI_freeplan(plan); - SPI_finish_wrapper(&state); + SPI_finish_wrapper(state); } /* diff --git a/src/quotamodel.c b/src/quotamodel.c index d646b832..156b581d 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -673,8 +673,8 @@ vacuum_disk_quota_model(uint32 id) bool check_diskquota_state_is_ready() { - SPI_state state; - bool is_ready = false; + int state; + bool is_ready = false; /* * Cache Errors during SPI functions, for example a segment may be down @@ -683,7 +683,7 @@ check_diskquota_state_is_ready() */ PG_TRY(); { - SPI_connect_wrapper(&state); + state = SPI_connect_wrapper(); is_ready = do_check_diskquota_state_is_ready(); } PG_CATCH(); @@ -692,12 +692,12 @@ check_diskquota_state_is_ready() HOLD_INTERRUPTS(); EmitErrorReport(); FlushErrorState(); - state.do_commit = false; + state |= is_abort; /* Now we can allow interrupts again */ RESUME_INTERRUPTS(); } PG_END_TRY(); - SPI_finish_wrapper(&state); + SPI_finish_wrapper(state); return is_ready; } @@ -1126,7 +1126,7 @@ calculate_table_disk_usage(bool is_init, HTAB *local_active_table_stat_map) static void delete_from_table_size_map(char *str) { - SPI_state state; + int state; StringInfoData delete_statement; int ret; @@ -1136,30 +1136,30 @@ delete_from_table_size_map(char *str) "delete from diskquota.table_size " "where (tableid, segid) in ( SELECT * FROM deleted_table );", str); - SPI_connect_wrapper(&state); - ret = SPI_execute(delete_statement.data, false, 0); + state = SPI_connect_wrapper(); + ret = SPI_execute(delete_statement.data, false, 0); if (ret != SPI_OK_DELETE) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("[diskquota] delete_from_table_size_map SPI_execute failed: error code %d", ret))); - SPI_finish_wrapper(&state); + SPI_finish_wrapper(state); pfree(delete_statement.data); } static void insert_into_table_size_map(char *str) { - SPI_state state; + int state; StringInfoData insert_statement; int ret; initStringInfo(&insert_statement); appendStringInfo(&insert_statement, "insert into diskquota.table_size values %s;", str); - SPI_connect_wrapper(&state); - ret = SPI_execute(insert_statement.data, false, 0); + state = SPI_connect_wrapper(); + ret = SPI_execute(insert_statement.data, false, 0); if (ret != SPI_OK_INSERT) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("[diskquota] insert_into_table_size_map SPI_execute failed: error code %d", ret))); - SPI_finish_wrapper(&state); + SPI_finish_wrapper(state); pfree(insert_statement.data); } @@ -1393,7 +1393,7 @@ truncateStringInfo(StringInfo str, int nchars) static bool load_quotas(void) { - SPI_state state; + int state; /* * Cache Errors during SPI functions, for example a segment may be down @@ -1402,7 +1402,7 @@ load_quotas(void) */ PG_TRY(); { - SPI_connect_wrapper(&state); + state = SPI_connect_wrapper(); do_load_quotas(); } PG_CATCH(); @@ -1411,13 +1411,13 @@ load_quotas(void) HOLD_INTERRUPTS(); EmitErrorReport(); FlushErrorState(); - state.do_commit = false; + state |= is_abort; /* Now we can allow interrupts again */ RESUME_INTERRUPTS(); } PG_END_TRY(); - SPI_finish_wrapper(&state); - return state.do_commit; + SPI_finish_wrapper(state); + return !(state & is_abort); } /* From 25684b4504e533a89e2bba05829ddfa519b582bf Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Wed, 30 Oct 2024 08:37:01 +0500 Subject: [PATCH 2/8] fix --- src/diskquota.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/diskquota.c b/src/diskquota.c index ace084be..7bb80de1 100644 --- a/src/diskquota.c +++ b/src/diskquota.c @@ -958,7 +958,7 @@ disk_quota_launcher_main(Datum main_arg) static void create_monitor_db_table(void) { - int state; + int state = 0; const char *sql; /* @@ -1152,7 +1152,7 @@ process_extension_ddl_message() static void do_process_extension_ddl_message(MessageResult *code, ExtensionDDLMessage local_extension_ddl_message) { - int state; + int state = 0; int old_num_db = num_db; /* From 0b49c7023843c6ec036e7bf9e9afe3f55a029824 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Wed, 30 Oct 2024 08:37:17 +0500 Subject: [PATCH 3/8] formet --- src/diskquota.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diskquota.c b/src/diskquota.c index 7bb80de1..7f0c846b 100644 --- a/src/diskquota.c +++ b/src/diskquota.c @@ -1152,7 +1152,7 @@ process_extension_ddl_message() static void do_process_extension_ddl_message(MessageResult *code, ExtensionDDLMessage local_extension_ddl_message) { - int state = 0; + int state = 0; int old_num_db = num_db; /* From 8652e1a97c460e84a166d1db57d283522d7fb405 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Wed, 30 Oct 2024 08:38:59 +0500 Subject: [PATCH 4/8] fix --- src/quotamodel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/quotamodel.c b/src/quotamodel.c index 156b581d..97642b22 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -673,7 +673,7 @@ vacuum_disk_quota_model(uint32 id) bool check_diskquota_state_is_ready() { - int state; + int state = 0; bool is_ready = false; /* @@ -1393,7 +1393,7 @@ truncateStringInfo(StringInfo str, int nchars) static bool load_quotas(void) { - int state; + int state = 0; /* * Cache Errors during SPI functions, for example a segment may be down From e41ea952fe8dec679845021ee54eceb8196928b8 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Wed, 30 Oct 2024 08:41:32 +0500 Subject: [PATCH 5/8] optimize --- src/quotamodel.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/quotamodel.c b/src/quotamodel.c index 97642b22..7838595f 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -1126,9 +1126,7 @@ calculate_table_disk_usage(bool is_init, HTAB *local_active_table_stat_map) static void delete_from_table_size_map(char *str) { - int state; StringInfoData delete_statement; - int ret; initStringInfo(&delete_statement); appendStringInfo(&delete_statement, @@ -1136,8 +1134,8 @@ delete_from_table_size_map(char *str) "delete from diskquota.table_size " "where (tableid, segid) in ( SELECT * FROM deleted_table );", str); - state = SPI_connect_wrapper(); - ret = SPI_execute(delete_statement.data, false, 0); + int state = SPI_connect_wrapper(); + int ret = SPI_execute(delete_statement.data, false, 0); if (ret != SPI_OK_DELETE) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("[diskquota] delete_from_table_size_map SPI_execute failed: error code %d", ret))); @@ -1148,14 +1146,12 @@ delete_from_table_size_map(char *str) static void insert_into_table_size_map(char *str) { - int state; StringInfoData insert_statement; - int ret; initStringInfo(&insert_statement); appendStringInfo(&insert_statement, "insert into diskquota.table_size values %s;", str); - state = SPI_connect_wrapper(); - ret = SPI_execute(insert_statement.data, false, 0); + int state = SPI_connect_wrapper(); + int ret = SPI_execute(insert_statement.data, false, 0); if (ret != SPI_OK_INSERT) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("[diskquota] insert_into_table_size_map SPI_execute failed: error code %d", ret))); From f64447a2ca8d6a6412d0f5fb5fe83fdebe91821e Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Wed, 30 Oct 2024 08:42:33 +0500 Subject: [PATCH 6/8] opmimize --- src/diskquota_utility.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/diskquota_utility.c b/src/diskquota_utility.c index f530d6a0..b87b3308 100644 --- a/src/diskquota_utility.c +++ b/src/diskquota_utility.c @@ -1236,10 +1236,8 @@ set_per_segment_quota(PG_FUNCTION_ARGS) int worker_spi_get_extension_version(int *major, int *minor) { - int ret; int state = SPI_connect_wrapper(); - - ret = SPI_execute("select extversion from pg_extension where extname = 'diskquota'", true, 0); + int ret = SPI_execute("select extversion from pg_extension where extname = 'diskquota'", true, 0); if (SPI_processed == 0) { From e26a435954f7072d01e53fd6310c4dae5ddad3d3 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Wed, 30 Oct 2024 09:38:30 +0500 Subject: [PATCH 7/8] format --- src/quotamodel.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/quotamodel.c b/src/quotamodel.c index 13e0bb7a..9962b30a 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -1122,13 +1122,13 @@ calculate_table_disk_usage(bool is_init, HTAB *local_active_table_stat_map) static void delete_from_table_size_map(ArrayBuildState *tableids, ArrayBuildState *segids) { - Datum tableid = makeArrayResult(tableids, CurrentMemoryContext); - Datum segid = makeArrayResult(segids, CurrentMemoryContext); + Datum tableid = makeArrayResult(tableids, CurrentMemoryContext); + Datum segid = makeArrayResult(segids, CurrentMemoryContext); int state = SPI_connect_wrapper(); - int ret = SPI_execute_with_args( - "delete from diskquota.table_size where (tableid, segid) in (select * from unnest($1, $2))", 2, - (Oid[]){OIDARRAYOID, INT2ARRAYOID}, (Datum[]){tableid, segid}, NULL, false, 0); + int ret = SPI_execute_with_args( + "delete from diskquota.table_size where (tableid, segid) in (select * from unnest($1, $2))", 2, + (Oid[]){OIDARRAYOID, INT2ARRAYOID}, (Datum[]){tableid, segid}, NULL, false, 0); if (ret != SPI_OK_DELETE) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("[diskquota] delete_from_table_size_map SPI_execute failed: error code %d", ret))); @@ -1140,23 +1140,23 @@ delete_from_table_size_map(ArrayBuildState *tableids, ArrayBuildState *segids) static void update_table_size_map(ArrayBuildState *tableids, ArrayBuildState *sizes, ArrayBuildState *segids) { - Datum tableid = makeArrayResult(tableids, CurrentMemoryContext); - Datum size = makeArrayResult(sizes, CurrentMemoryContext); - Datum segid = makeArrayResult(segids, CurrentMemoryContext); + Datum tableid = makeArrayResult(tableids, CurrentMemoryContext); + Datum size = makeArrayResult(sizes, CurrentMemoryContext); + Datum segid = makeArrayResult(segids, CurrentMemoryContext); int state = SPI_connect_wrapper(); - int ret = SPI_execute_with_args( - "delete from diskquota.table_size where (tableid, segid) in (select * from unnest($1, $2))", 2, - (Oid[]){OIDARRAYOID, INT2ARRAYOID}, (Datum[]){tableid, segid}, NULL, false, 0); + int ret = SPI_execute_with_args( + "delete from diskquota.table_size where (tableid, segid) in (select * from unnest($1, $2))", 2, + (Oid[]){OIDARRAYOID, INT2ARRAYOID}, (Datum[]){tableid, segid}, NULL, false, 0); if (ret != SPI_OK_DELETE) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("[diskquota] delete_from_table_size_map SPI_execute failed: error code %d", ret))); SPI_finish_wrapper(state); state = SPI_connect_wrapper(); - ret = SPI_execute_with_args("insert into diskquota.table_size select * from unnest($1, $2, $3)", 3, - (Oid[]){OIDARRAYOID, INT8ARRAYOID, INT2ARRAYOID}, (Datum[]){tableid, size, segid}, NULL, - false, 0); + ret = SPI_execute_with_args("insert into diskquota.table_size select * from unnest($1, $2, $3)", 3, + (Oid[]){OIDARRAYOID, INT8ARRAYOID, INT2ARRAYOID}, (Datum[]){tableid, size, segid}, NULL, + false, 0); if (ret != SPI_OK_INSERT) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("[diskquota] insert_into_table_size_map SPI_execute failed: error code %d", ret))); From f2e66f211363d365449d9bfc22d5489aab142156 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Wed, 30 Oct 2024 09:39:34 +0500 Subject: [PATCH 8/8] format --- src/quotamodel.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/quotamodel.c b/src/quotamodel.c index 9962b30a..5fe34718 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -1124,11 +1124,10 @@ delete_from_table_size_map(ArrayBuildState *tableids, ArrayBuildState *segids) { Datum tableid = makeArrayResult(tableids, CurrentMemoryContext); Datum segid = makeArrayResult(segids, CurrentMemoryContext); - - int state = SPI_connect_wrapper(); - int ret = SPI_execute_with_args( - "delete from diskquota.table_size where (tableid, segid) in (select * from unnest($1, $2))", 2, - (Oid[]){OIDARRAYOID, INT2ARRAYOID}, (Datum[]){tableid, segid}, NULL, false, 0); + int state = SPI_connect_wrapper(); + int ret = SPI_execute_with_args( + "delete from diskquota.table_size where (tableid, segid) in (select * from unnest($1, $2))", 2, + (Oid[]){OIDARRAYOID, INT2ARRAYOID}, (Datum[]){tableid, segid}, NULL, false, 0); if (ret != SPI_OK_DELETE) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("[diskquota] delete_from_table_size_map SPI_execute failed: error code %d", ret))); @@ -1143,11 +1142,10 @@ update_table_size_map(ArrayBuildState *tableids, ArrayBuildState *sizes, ArrayBu Datum tableid = makeArrayResult(tableids, CurrentMemoryContext); Datum size = makeArrayResult(sizes, CurrentMemoryContext); Datum segid = makeArrayResult(segids, CurrentMemoryContext); - - int state = SPI_connect_wrapper(); - int ret = SPI_execute_with_args( - "delete from diskquota.table_size where (tableid, segid) in (select * from unnest($1, $2))", 2, - (Oid[]){OIDARRAYOID, INT2ARRAYOID}, (Datum[]){tableid, segid}, NULL, false, 0); + int state = SPI_connect_wrapper(); + int ret = SPI_execute_with_args( + "delete from diskquota.table_size where (tableid, segid) in (select * from unnest($1, $2))", 2, + (Oid[]){OIDARRAYOID, INT2ARRAYOID}, (Datum[]){tableid, segid}, NULL, false, 0); if (ret != SPI_OK_DELETE) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("[diskquota] delete_from_table_size_map SPI_execute failed: error code %d", ret)));