Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
RekGRpth committed Oct 28, 2024
1 parent d628f7c commit cded6ba
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 72 deletions.
38 changes: 15 additions & 23 deletions src/diskquota.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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)
{
Expand All @@ -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:
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/diskquota.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 12 additions & 17 deletions src/diskquota_utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down
7 changes: 2 additions & 5 deletions src/gp_activetable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
38 changes: 13 additions & 25 deletions src/quotamodel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand All @@ -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;
}

Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand All @@ -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;
}

/*
Expand Down

0 comments on commit cded6ba

Please sign in to comment.