diff --git a/src/diskquota.c b/src/diskquota.c index 3a852d25..496196b5 100644 --- a/src/diskquota.c +++ b/src/diskquota.c @@ -958,11 +958,8 @@ disk_quota_launcher_main(Datum main_arg) static void create_monitor_db_table(void) { + bool connected, pushed_active_snap, commit, transaction; const char *sql; - bool connected = false; - bool pushed_active_snap = false; - bool ret = true; - bool transaction = true; /* * Create function diskquota.diskquota_fetch_table_stat in launcher @@ -989,7 +986,7 @@ create_monitor_db_table(void) */ PG_TRY(); { - SPI_connect_my(&connected, &pushed_active_snap, &ret, &transaction); + SPI_connect_my(&connected, &pushed_active_snap, &commit, &transaction); /* debug_query_string need to be set for SPI_execute utility functions. */ debug_query_string = sql; @@ -1008,13 +1005,13 @@ create_monitor_db_table(void) HOLD_INTERRUPTS(); EmitErrorReport(); FlushErrorState(); - ret = false; + commit = false; debug_query_string = NULL; /* Now we can allow interrupts again */ RESUME_INTERRUPTS(); } PG_END_TRY(); - SPI_finish_my(connected, pushed_active_snap, ret, transaction); + SPI_finish_my(connected, pushed_active_snap, commit, transaction); debug_query_string = NULL; } @@ -1026,12 +1023,9 @@ create_monitor_db_table(void) static void init_database_list(void) { + bool connected, pushed_active_snap, commit, transaction; TupleDesc tupdesc; - bool connected = false; - bool pushed_active_snap = false; - bool commit = true; - bool transaction = true; - int num = 0; + int num = 0; int ret; int i; @@ -1159,11 +1153,8 @@ process_extension_ddl_message() static void do_process_extension_ddl_message(MessageResult *code, ExtensionDDLMessage local_extension_ddl_message) { - int old_num_db = num_db; - bool connected = false; - bool pushed_active_snap = false; - bool ret = true; - bool transaction = true; + bool connected, pushed_active_snap, commit, transaction; + int old_num_db = num_db; /* * Cache Errors during SPI functions, for example a segment may be down @@ -1172,7 +1163,7 @@ do_process_extension_ddl_message(MessageResult *code, ExtensionDDLMessage local_ */ PG_TRY(); { - SPI_connect_my(&connected, &pushed_active_snap, &ret, &transaction); + SPI_connect_my(&connected, &pushed_active_snap, &commit, &transaction); switch (local_extension_ddl_message.cmd) { @@ -1199,22 +1190,22 @@ do_process_extension_ddl_message(MessageResult *code, ExtensionDDLMessage local_ HOLD_INTERRUPTS(); EmitErrorReport(); FlushErrorState(); - ret = false; + commit = false; num_db = old_num_db; RESUME_INTERRUPTS(); } PG_END_TRY(); - SPI_finish_my(connected, pushed_active_snap, ret, transaction); + SPI_finish_my(connected, pushed_active_snap, commit, transaction); /* update something in memory after transaction committed */ - if (ret) + if (commit) { PG_TRY(); { /* update_monitor_db_mpp runs sql to distribute dbid to segments */ Oid dbid = local_extension_ddl_message.dbid; - SPI_connect_my(&connected, &pushed_active_snap, &ret, &transaction); + SPI_connect_my(&connected, &pushed_active_snap, &commit, &transaction); switch (local_extension_ddl_message.cmd) { case CMD_CREATE_EXTENSION: @@ -1243,11 +1234,12 @@ do_process_extension_ddl_message(MessageResult *code, ExtensionDDLMessage local_ HOLD_INTERRUPTS(); EmitErrorReport(); FlushErrorState(); + commit = false; RESUME_INTERRUPTS(); } PG_END_TRY(); - SPI_finish_my(connected, pushed_active_snap, ret, transaction); + SPI_finish_my(connected, pushed_active_snap, commit, transaction); } DisconnectAndDestroyAllGangs(false); } diff --git a/src/diskquota.h b/src/diskquota.h index 7ec1e26c..3c2f52f0 100644 --- a/src/diskquota.h +++ b/src/diskquota.h @@ -319,6 +319,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_my(bool *connected, bool *pushed_active_snap, bool *ret, bool *transaction); -void SPI_finish_my(bool connected, bool pushed_active_snap, bool ret, bool transaction); +void SPI_connect_my(bool *connected, bool *pushed_active_snap, bool *commit, bool *transaction); +void SPI_finish_my(bool connected, bool pushed_active_snap, bool commit, bool transaction); #endif diff --git a/src/diskquota_utility.c b/src/diskquota_utility.c index fc06d754..67f8266d 100644 --- a/src/diskquota_utility.c +++ b/src/diskquota_utility.c @@ -1235,10 +1235,7 @@ set_per_segment_quota(PG_FUNCTION_ARGS) int worker_spi_get_extension_version(int *major, int *minor) { - bool connected = false; - bool pushed_active_snap = false; - bool commit = true; - bool transaction = true; + bool connected, pushed_active_snap, commit, transaction; int ret; SPI_connect_my(&connected, &pushed_active_snap, &commit, &transaction); @@ -1303,12 +1300,9 @@ worker_spi_get_extension_version(int *major, int *minor) List * get_rel_oid_list(bool is_init) { + bool connected, pushed_active_snap, commit, transaction; List *oidlist = NIL; int ret; - bool connected = false; - bool pushed_active_snap = false; - bool commit = true; - bool transaction = true; SPI_connect_my(&connected, &pushed_active_snap, &commit, &transaction); @@ -1721,15 +1715,16 @@ check_hash_fullness(HTAB *hashp, int max_size, const char *warning_message, Time } void -SPI_connect_my(bool *connected, bool *pushed_active_snap, bool *ret, bool *transaction) +SPI_connect_my(bool *connected, bool *pushed_active_snap, bool *commit, bool *transaction) { int rc; + + *connected = false; + *pushed_active_snap = false; + *transaction = false; + *commit = true; SetCurrentStatementStartTimestamp(); - if (IsTransactionState()) - { - *transaction = false; - } - else + if (!IsTransactionState()) { StartTransactionCommand(); *transaction = true; @@ -1740,20 +1735,20 @@ SPI_connect_my(bool *connected, bool *pushed_active_snap, bool *ret, bool *trans *connected = true; PushActiveSnapshot(GetTransactionSnapshot()); *pushed_active_snap = true; - *ret = true; } void -SPI_finish_my(bool connected, bool pushed_active_snap, bool ret, bool transaction) +SPI_finish_my(bool connected, bool pushed_active_snap, bool commit, bool transaction) { int rc; + if (pushed_active_snap) PopActiveSnapshot(); if (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 (transaction) { - if (ret) + if (commit) CommitTransactionCommand(); else AbortCurrentTransaction(); diff --git a/src/gp_activetable.c b/src/gp_activetable.c index 742d3425..d6d9b18f 100644 --- a/src/gp_activetable.c +++ b/src/gp_activetable.c @@ -946,17 +946,14 @@ get_active_tables_oid(void) static void load_table_size(HTAB *local_table_stats_map) { + bool connected, pushed_active_snap, commit, transaction; TupleDesc tupdesc; int i; bool found; ActiveTableEntryCombined *quota_entry; SPIPlanPtr plan; Portal portal; - char *sql = "select tableid, size, segid from diskquota.table_size"; - bool connected = false; - bool pushed_active_snap = false; - bool commit = true; - bool transaction = true; + char *sql = "select tableid, size, segid from diskquota.table_size"; SPI_connect_my(&connected, &pushed_active_snap, &commit, &transaction); diff --git a/src/quotamodel.c b/src/quotamodel.c index 2718fc53..28358b53 100644 --- a/src/quotamodel.c +++ b/src/quotamodel.c @@ -673,11 +673,8 @@ vacuum_disk_quota_model(uint32 id) bool check_diskquota_state_is_ready() { - bool is_ready = false; - bool connected = false; - bool pushed_active_snap = false; - bool ret = true; - bool transaction = true; + bool connected, pushed_active_snap, commit, transaction; + bool is_ready = false; /* * Cache Errors during SPI functions, for example a segment may be down @@ -686,7 +683,7 @@ check_diskquota_state_is_ready() */ PG_TRY(); { - SPI_connect_my(&connected, &pushed_active_snap, &ret, &transaction); + SPI_connect_my(&connected, &pushed_active_snap, &commit, &transaction); is_ready = do_check_diskquota_state_is_ready(); } PG_CATCH(); @@ -695,12 +692,12 @@ check_diskquota_state_is_ready() HOLD_INTERRUPTS(); EmitErrorReport(); FlushErrorState(); - ret = false; + commit = false; /* Now we can allow interrupts again */ RESUME_INTERRUPTS(); } PG_END_TRY(); - SPI_finish_my(connected, pushed_active_snap, ret, transaction); + SPI_finish_my(connected, pushed_active_snap, commit, transaction); return is_ready; } @@ -1125,12 +1122,9 @@ calculate_table_disk_usage(bool is_init, HTAB *local_active_table_stat_map) static void delete_from_table_size_map(char *str) { + bool connected, pushed_active_snap, commit, transaction; StringInfoData delete_statement; int ret; - bool connected = false; - bool pushed_active_snap = false; - bool commit = true; - bool transaction = true; initStringInfo(&delete_statement); appendStringInfo(&delete_statement, @@ -1150,12 +1144,9 @@ delete_from_table_size_map(char *str) static void insert_into_table_size_map(char *str) { + bool connected, pushed_active_snap, commit, transaction; StringInfoData insert_statement; int ret; - bool connected = false; - bool pushed_active_snap = false; - bool commit = true; - bool transaction = true; initStringInfo(&insert_statement); appendStringInfo(&insert_statement, "insert into diskquota.table_size values %s;", str); @@ -1214,7 +1205,7 @@ flush_to_table_size(void) } } /* update the table size by delete+insert in table table_size */ - else // if (TableSizeEntryGetFlushFlag(tsentry, i)) + else if (TableSizeEntryGetFlushFlag(tsentry, i)) { appendStringInfo(&delete_statement, "%s(%u,%d)", (delete_entries_num == 0) ? " " : ", ", tsentry->key.reloid, i); @@ -1398,10 +1389,7 @@ truncateStringInfo(StringInfo str, int nchars) static bool load_quotas(void) { - bool connected = false; - bool pushed_active_snap = false; - bool ret = true; - bool transaction = true; + bool connected, pushed_active_snap, commit, transaction; /* * Cache Errors during SPI functions, for example a segment may be down @@ -1410,7 +1398,7 @@ load_quotas(void) */ PG_TRY(); { - SPI_connect_my(&connected, &pushed_active_snap, &ret, &transaction); + SPI_connect_my(&connected, &pushed_active_snap, &commit, &transaction); do_load_quotas(); } PG_CATCH(); @@ -1419,13 +1407,13 @@ load_quotas(void) HOLD_INTERRUPTS(); EmitErrorReport(); FlushErrorState(); - ret = false; + commit = false; /* Now we can allow interrupts again */ RESUME_INTERRUPTS(); } PG_END_TRY(); - SPI_finish_my(connected, pushed_active_snap, ret, transaction); - return ret; + SPI_finish_my(connected, pushed_active_snap, commit, transaction); + return commit; } /*