Skip to content

Commit

Permalink
mv
Browse files Browse the repository at this point in the history
  • Loading branch information
RekGRpth committed Nov 26, 2023
1 parent d164288 commit 5142089
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
23 changes: 21 additions & 2 deletions dest.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static void EndCommandMy(const char *commandTag, CommandDest dest) {

#include <postgres.c>

void task_execute(void) {
static void dest_execute(void) {
MemoryContext oldMemoryContext = MemoryContextSwitchTo(MessageContext);
MemoryContextResetAndDeleteChildren(MessageContext);
InvalidateCatalogSnapshotConditionally();
Expand All @@ -172,7 +172,7 @@ void task_execute(void) {
if (IsTransactionState()) ereport(ERROR, (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION), errmsg("still active sql transaction")));
}

void task_catch(void) {
static void dest_catch(void) {
HOLD_INTERRUPTS();
disable_all_timeouts(false);
QueryCancelPending = false;
Expand All @@ -195,3 +195,22 @@ void task_catch(void) {
xact_started = false;
RESUME_INTERRUPTS();
}

bool dest_timeout(void) {
int StatementTimeoutMy = StatementTimeout;
if (task_work(&task)) return true;
elog(DEBUG1, "id = %li, timeout = %i, input = %s, count = %i", task.shared->id, task.timeout, task.input, task.count);
set_ps_display_my("timeout");
StatementTimeout = task.timeout;
PG_TRY();
if (!task.active) ereport(ERROR, (errcode(ERRCODE_QUERY_CANCELED), errmsg("task not active")));
dest_execute();
PG_CATCH();
dest_catch();
PG_END_TRY();
StatementTimeout = StatementTimeoutMy;
pgstat_report_stat(false);
pgstat_report_activity(STATE_IDLE, NULL);
set_ps_display_my("idle");
return task_done(&task);
}
3 changes: 1 addition & 2 deletions include.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ typedef struct Task {
void (*socket) (struct Task *t);
} Task;

bool dest_timeout(void);
bool init_oid_is_string(Oid oid);
bool is_log_level_output(int elevel, int log_min_level);
bool lock_data_user_hash(Oid data, Oid user, int hash);
Expand Down Expand Up @@ -190,9 +191,7 @@ void SPI_cursor_fetch_my(const char *src, Portal portal, bool forward, long coun
void SPI_execute_plan_my(const char *src, SPIPlanPtr plan, Datum *values, const char *nulls, int res);
void SPI_execute_with_args_my(const char *src, int nargs, Oid *argtypes, Datum *values, const char *nulls, int res);
void SPI_finish_my(void);
void task_catch(void);
void task_error(ErrorData *edata);
void task_execute(void);
void task_free(Task *t);
void taskshared_free(int slot);
void workshared_free(int slot);
Expand Down
21 changes: 1 addition & 20 deletions task.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,25 +320,6 @@ static void task_latch(void) {
CHECK_FOR_INTERRUPTS();
}

static bool task_timeout(void) {
int StatementTimeoutMy = StatementTimeout;
if (task_work(&task)) return true;
elog(DEBUG1, "id = %li, timeout = %i, input = %s, count = %i", task.shared->id, task.timeout, task.input, task.count);
set_ps_display_my("timeout");
StatementTimeout = task.timeout;
PG_TRY();
if (!task.active) ereport(ERROR, (errcode(ERRCODE_QUERY_CANCELED), errmsg("task not active")));
task_execute();
PG_CATCH();
task_catch();
PG_END_TRY();
StatementTimeout = StatementTimeoutMy;
pgstat_report_stat(false);
pgstat_report_activity(STATE_IDLE, NULL);
set_ps_display_my("idle");
return task_done(&task);
}

void task_free(Task *t) {
if (t->error.data) { pfree(t->error.data); t->error.data = NULL; t->error.len = 0; }
if (t->group) { pfree(t->group); t->group = NULL; }
Expand Down Expand Up @@ -385,7 +366,7 @@ void task_main(Datum arg) {
int rc = WaitLatchMy(MyLatch, WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH, 0);
if (rc & WL_POSTMASTER_DEATH) ShutdownRequestPending = true;
if (rc & WL_LATCH_SET) task_latch();
if (rc & WL_TIMEOUT) if (task_timeout()) ShutdownRequestPending = true;
if (rc & WL_TIMEOUT) if (dest_timeout()) ShutdownRequestPending = true;
}
if (!unlock_table_pid_hash(work.shared->oid, task.pid, task.shared->hash)) elog(WARNING, "!unlock_table_pid_hash(%i, %i, %i)", work.shared->oid, task.pid, task.shared->hash);
}

0 comments on commit 5142089

Please sign in to comment.