Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
RekGRpth committed Oct 31, 2024
1 parent 0bae1e1 commit dbfa9ab
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 46 deletions.
26 changes: 13 additions & 13 deletions src/diskquota.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ is_altering_extension_to_default_version(char *version)
{
int spi_ret;
bool ret = false;
bool connected = SPI_connect_wrapper();
bool connected = SPI_connect_if_not_yet();
spi_ret = SPI_execute("select default_version from pg_available_extensions where name ='diskquota'", true, 0);
if (spi_ret != SPI_OK_SELECT)
elog(ERROR, "[diskquota] failed to select diskquota default version during diskquota update.");
Expand All @@ -194,7 +194,7 @@ is_altering_extension_to_default_version(char *version)
if (strcmp(version, default_version) == 0) ret = true;
}
}
SPI_finish_wrapper(connected);
SPI_finish_if_connected(connected);
return ret;
}

Expand Down Expand Up @@ -990,7 +990,7 @@ create_monitor_db_table(void)
*/
PG_TRY();
{
connected = SPI_connect_wrapper();
connected = SPI_connect_if_not_yet();
PushActiveSnapshot(GetTransactionSnapshot());
pushed_active_snap = true;

Expand All @@ -1017,7 +1017,7 @@ create_monitor_db_table(void)
RESUME_INTERRUPTS();
}
PG_END_TRY();
SPI_finish_wrapper(connected);
SPI_finish_if_connected(connected);
if (pushed_active_snap) PopActiveSnapshot();
if (ret)
CommitTransactionCommand();
Expand Down Expand Up @@ -1047,7 +1047,7 @@ init_database_list(void)
StartTransactionCommand();
PushActiveSnapshot(GetTransactionSnapshot());

bool connected = SPI_connect_wrapper();
bool connected = SPI_connect_if_not_yet();
ret = SPI_execute("select dbid from diskquota_namespace.database_list;", true, 0);
if (ret != SPI_OK_SELECT)
{
Expand Down Expand Up @@ -1107,7 +1107,7 @@ init_database_list(void)
}
}
num_db = num;
SPI_finish_wrapper(connected);
SPI_finish_if_connected(connected);
/* As update_monitor_db_mpp needs to execute sql, so can not put in the loop above */
for (int i = 0; i < diskquota_max_monitored_databases; i++)
{
Expand Down Expand Up @@ -1345,7 +1345,7 @@ add_dbid_to_database_list(Oid dbid)

Oid argt[1] = {OIDOID};
Datum argv[1] = {ObjectIdGetDatum(dbid)};
bool connected = SPI_connect_wrapper();
bool connected = SPI_connect_if_not_yet();

ret = SPI_execute_with_args("select * from diskquota_namespace.database_list where dbid = $1", 1, argt, argv, NULL,
true, 0);
Expand Down Expand Up @@ -1378,7 +1378,7 @@ add_dbid_to_database_list(Oid dbid)
}

ret:
SPI_finish_wrapper(connected);
SPI_finish_if_connected(connected);
}

/*
Expand All @@ -1389,7 +1389,7 @@ static void
del_dbid_from_database_list(Oid dbid)
{
int ret;
bool connected = SPI_connect_wrapper();
bool connected = SPI_connect_if_not_yet();

/* errors will be cached in outer function */
ret = SPI_execute_with_args("delete from diskquota_namespace.database_list where dbid = $1", 1,
Expand All @@ -1407,7 +1407,7 @@ del_dbid_from_database_list(Oid dbid)
strerror(saved_errno), ret)));
}

SPI_finish_wrapper(connected);
SPI_finish_if_connected(connected);
}

/*
Expand Down Expand Up @@ -1601,7 +1601,7 @@ static const char *
diskquota_status_schema_version()
{
static char ret_version[64];
bool connected = SPI_connect_wrapper();
bool connected = SPI_connect_if_not_yet();
int ret = SPI_execute("select extversion from pg_extension where extname = 'diskquota'", true, 0);

if (ret != SPI_OK_SELECT || SPI_processed != 1)
Expand Down Expand Up @@ -1629,11 +1629,11 @@ diskquota_status_schema_version()

StrNCpy(ret_version, version, sizeof(ret_version) - 1);

SPI_finish_wrapper(connected);
SPI_finish_if_connected(connected);
return ret_version;

fail:
SPI_finish_wrapper(connected);
SPI_finish_if_connected(connected);
return "";
}

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);
bool SPI_connect_wrapper(void);
void SPI_finish_wrapper(bool connected);
bool SPI_connect_if_not_yet(void);
void SPI_finish_if_connected(bool connected);
#endif
36 changes: 18 additions & 18 deletions src/diskquota_utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ init_table_size_table(PG_FUNCTION_ARGS)
* They do not work on entry db since we do not support dispatching
* from entry-db currently.
*/
bool connected = SPI_connect_wrapper();
bool connected = SPI_connect_if_not_yet();

/* delete all the table size info in table_size if exist. */
ret = SPI_execute("truncate table diskquota.table_size", false, 0);
Expand Down Expand Up @@ -200,7 +200,7 @@ init_table_size_table(PG_FUNCTION_ARGS)
NULL, false, 0);
if (ret != SPI_OK_UPDATE) elog(ERROR, "cannot update state table: error code %d", ret);

SPI_finish_wrapper(connected);
SPI_finish_if_connected(connected);
PG_RETURN_VOID();
}

Expand Down Expand Up @@ -479,7 +479,7 @@ is_database_empty(void)
* If error happens in is_database_empty, just return error messages to
* the client side. So there is no need to catch the error.
*/
bool connected = SPI_connect_wrapper();
bool connected = SPI_connect_if_not_yet();

ret = SPI_execute(
"INSERT INTO diskquota.state SELECT (count(relname) = 0)::int "
Expand Down Expand Up @@ -516,7 +516,7 @@ is_database_empty(void)
/*
* And finish our transaction.
*/
SPI_finish_wrapper(connected);
SPI_finish_if_connected(connected);
return is_empty;
}

Expand Down Expand Up @@ -810,7 +810,7 @@ set_quota_config_internal(Oid targetoid, int64 quota_limit_mb, QuotaType type, f
/* Report error if diskquota is not ready. */
do_check_diskquota_state_is_ready();

bool connected = SPI_connect_wrapper();
bool connected = SPI_connect_if_not_yet();
/*
* If error happens in set_quota_config_internal, just return error messages to
* the client side. So there is no need to catch the error.
Expand Down Expand Up @@ -912,7 +912,7 @@ set_quota_config_internal(Oid targetoid, int64 quota_limit_mb, QuotaType type, f
}
}

SPI_finish_wrapper(connected);
SPI_finish_if_connected(connected);
}

static int
Expand All @@ -922,7 +922,7 @@ set_target_internal(Oid primaryoid, Oid spcoid, int64 quota_limit_mb, QuotaType
int row_id = -1;
bool is_null = false;
Datum v;
bool connected = SPI_connect_wrapper();
bool connected = SPI_connect_if_not_yet();
/*
* If error happens in set_target_internal, just return error messages to
* the client side. So there is no need to catch the error.
Expand Down Expand Up @@ -1004,7 +1004,7 @@ set_target_internal(Oid primaryoid, Oid spcoid, int64 quota_limit_mb, QuotaType
row_id = DatumGetInt32(v);
}

SPI_finish_wrapper(connected);
SPI_finish_if_connected(connected);

/* No need to update the target table */

Expand Down Expand Up @@ -1153,7 +1153,7 @@ set_per_segment_quota(PG_FUNCTION_ARGS)
ereportif(ratio == 0, ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("per segment quota ratio can not be set to 0")));

bool connected = SPI_connect_wrapper();
bool connected = SPI_connect_if_not_yet();
/*
* lock table quota_config table in exlusive mode
*
Expand Down Expand Up @@ -1206,15 +1206,15 @@ set_per_segment_quota(PG_FUNCTION_ARGS)
/*
* And finish our transaction.
*/
SPI_finish_wrapper(connected);
SPI_finish_if_connected(connected);
PG_RETURN_VOID();
}

int
worker_spi_get_extension_version(int *major, int *minor)
{
StartTransactionCommand();
bool connected = SPI_connect_wrapper();
bool connected = SPI_connect_if_not_yet();
PushActiveSnapshot(GetTransactionSnapshot());

int ret = SPI_execute("select extversion from pg_extension where extname = 'diskquota'", true, 0);
Expand Down Expand Up @@ -1260,7 +1260,7 @@ worker_spi_get_extension_version(int *major, int *minor)
ret = 0;

out:
SPI_finish_wrapper(connected);
SPI_finish_if_connected(connected);
PopActiveSnapshot();
CommitTransactionCommand();

Expand All @@ -1280,7 +1280,7 @@ List *
get_rel_oid_list(bool is_init)
{
List *oidlist = NIL;
bool connected = SPI_connect_wrapper();
bool connected = SPI_connect_if_not_yet();

#define SELECT_FROM_PG_CATALOG_PG_CLASS "select oid from pg_catalog.pg_class where oid >= $1 and relkind in ('r', 'm')"

Expand Down Expand Up @@ -1328,7 +1328,7 @@ get_rel_oid_list(bool is_init)
MemoryContextSwitchTo(oldcontext);
}
}
SPI_finish_wrapper(connected);
SPI_finish_if_connected(connected);
return oidlist;
}

Expand Down Expand Up @@ -1567,7 +1567,7 @@ get_per_segment_ratio(Oid spcoid)

if (!OidIsValid(spcoid)) return segratio;

bool connected = SPI_connect_wrapper();
bool connected = SPI_connect_if_not_yet();
/*
* using row share lock to lock TABLESPACE_QUTAO
* row to avoid concurrently updating the segratio
Expand Down Expand Up @@ -1601,7 +1601,7 @@ get_per_segment_ratio(Oid spcoid)
segratio = DatumGetFloat4(dat);
}
}
SPI_finish_wrapper(connected);
SPI_finish_if_connected(connected);
return segratio;
}

Expand Down Expand Up @@ -1693,7 +1693,7 @@ check_hash_fullness(HTAB *hashp, int max_size, const char *warning_message, Time
}

bool
SPI_connect_wrapper(void)
SPI_connect_if_not_yet(void)
{
if (SPI_context()) return false;

Expand All @@ -1707,7 +1707,7 @@ SPI_connect_wrapper(void)
}

void
SPI_finish_wrapper(bool connected)
SPI_finish_if_connected(bool connected)
{
if (!connected || !SPI_context()) return;

Expand Down
6 changes: 3 additions & 3 deletions src/gp_activetable.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ diskquota_fetch_table_stat(PG_FUNCTION_ARGS)
MemoryContext oldcontext;
TupleDesc tupdesc;

SPI_finish_wrapper(SPI_connect_wrapper());
SPI_finish_if_connected(SPI_connect_if_not_yet());

/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
Expand Down Expand Up @@ -948,7 +948,7 @@ load_table_size(HTAB *local_table_stats_map)
SPIPlanPtr plan;
Portal portal;
char *sql = "select tableid, size, segid from diskquota.table_size";
bool connected = SPI_connect_wrapper();
bool connected = SPI_connect_if_not_yet();

if ((plan = SPI_prepare(sql, 0, NULL)) == NULL)
ereport(ERROR, (errmsg("[diskquota] SPI_prepare(\"%s\") failed", sql)));
Expand Down Expand Up @@ -1024,7 +1024,7 @@ load_table_size(HTAB *local_table_stats_map)
SPI_freetuptable(SPI_tuptable);
SPI_cursor_close(portal);
SPI_freeplan(plan);
SPI_finish_wrapper(connected);
SPI_finish_if_connected(connected);
}

/*
Expand Down
20 changes: 10 additions & 10 deletions src/quotamodel.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ do_check_diskquota_state_is_ready(void)
{
int ret;
TupleDesc tupdesc;
bool connected = SPI_connect_wrapper();
bool connected = SPI_connect_if_not_yet();
ret = SPI_execute("select state from diskquota.state", true, 0);
ereportif(ret != SPI_OK_SELECT, ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
Expand Down Expand Up @@ -752,7 +752,7 @@ do_check_diskquota_state_is_ready(void)
state = isnull ? DISKQUOTA_UNKNOWN_STATE : DatumGetInt32(dat);
bool is_ready = state == DISKQUOTA_READY_STATE;

SPI_finish_wrapper(connected);
SPI_finish_if_connected(connected);

if (!is_ready && !diskquota_is_readiness_logged())
{
Expand Down Expand Up @@ -1147,12 +1147,12 @@ delete_from_table_size_map(char *str)
"delete from diskquota.table_size "
"where (tableid, segid) in ( SELECT * FROM deleted_table );",
str);
bool connected = SPI_connect_wrapper();
bool connected = SPI_connect_if_not_yet();
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)));
SPI_finish_wrapper(connected);
SPI_finish_if_connected(connected);
pfree(delete_statement.data);
}

Expand All @@ -1163,12 +1163,12 @@ insert_into_table_size_map(char *str)

initStringInfo(&insert_statement);
appendStringInfo(&insert_statement, "insert into diskquota.table_size values %s;", str);
bool connected = SPI_connect_wrapper();
bool connected = SPI_connect_if_not_yet();
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)));
SPI_finish_wrapper(connected);
SPI_finish_if_connected(connected);
pfree(insert_statement.data);
}

Expand Down Expand Up @@ -1455,7 +1455,7 @@ do_load_quotas(void)
*/
clean_all_quota_limit();

bool connected = SPI_connect_wrapper();
bool connected = SPI_connect_if_not_yet();
/*
* read quotas from diskquota.quota_config and target table
*/
Expand Down Expand Up @@ -1537,7 +1537,7 @@ do_load_quotas(void)
}
}

SPI_finish_wrapper(connected);
SPI_finish_if_connected(connected);
}

/*
Expand Down Expand Up @@ -2282,9 +2282,9 @@ update_monitor_db_mpp(Oid dbid, FetchTableStatType action, const char *schema)
"SELECT %s.diskquota_fetch_table_stat(%d, '{%d}'::oid[]) FROM gp_dist_random('gp_id')", schema,
action, dbid);
/* Add current database to the monitored db cache on all segments */
bool connected = SPI_connect_wrapper();
bool connected = SPI_connect_if_not_yet();
int ret = SPI_execute(sql_command.data, true, 0);
SPI_finish_wrapper(connected);
SPI_finish_if_connected(connected);
pfree(sql_command.data);

ereportif(ret != SPI_OK_SELECT, ERROR,
Expand Down

0 comments on commit dbfa9ab

Please sign in to comment.