Skip to content

Commit

Permalink
Replace usages of InterruptPending to the flag of query cancellation …
Browse files Browse the repository at this point in the history
…(#13148)

Currently some communication routines between master and segments
performing polling of messages from segments rely on InterruptPending
flag in detection of cancel or terminating events. This flag is used to
define some interruption in CHECK_FOR_INTERRUPTS() routine. Up to some
time this flag was closely assigned with some exceptional case, more
often with cancel or termination request. But as GPDB merges with newest
versions of PostgreSQL, there are more and more cases where interruption
begins to denote some not certainly causing error thing, e.g., periodic
check of connectivity with client. For this reason it becomes necessary
to redefine the usages of InterruptPending flag to no longer erroneously
evaluate the set InterruptPending flag as cancel request.

Current patch fixes four places of InterruptPending usage in waiting
loops of master-segments communication. Some waiting loops might last a
long time and injecting of CHECK_FOR_INTERRUPTS() call to there is
necessary to not postpone interruption requests to much. But in other
loops the waiting is short enough if connectivity between master and
segments is preserved, therefore the check on cancellation or
termination in those loops is enough. The case of connection abort or
hanging on segments side have to be handled in separate work since it
will require to rewrite the logic in waiting loop.

This PR is the prerequisite for https://github.com/greenplum-db/gpdb/pull/12223
  • Loading branch information
Maksim Milyutin authored and gfphoenix78 committed Oct 30, 2024
1 parent 9f5f638 commit 2365a97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/backend/tcop/postgres.c
Original file line number Diff line number Diff line change
Expand Up @@ -6336,3 +6336,10 @@ disable_client_wait_timeout_interrupt(void)
DisableClientWaitTimeoutInterrupt();
}

/*
* Whether request on cancel or termination have arrived?
*/
inline bool
CancelRequested() {
return InterruptPending && (ProcDiePending || QueryCancelPending);
}
9 changes: 1 addition & 8 deletions src/include/miscadmin.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ extern PGDLLIMPORT volatile int32 CritSectionCount;

/* in tcop/postgres.c */
extern void ProcessInterrupts(const char* filename, int lineno);
extern bool CancelRequested();

/* Hook get notified when QueryCancelPending or ProcDiePending is raised */
typedef void (*cancel_pending_hook_type) (void);
Expand Down Expand Up @@ -140,14 +141,6 @@ BackoffBackendTick(void)
}
}

/*
* Whether request on cancel or termination have arrived?
*/
static inline bool
CancelRequested()
{
return InterruptPending && (ProcDiePending || QueryCancelPending);
}

/* Test whether an interrupt is pending */
#ifndef WIN32
Expand Down

0 comments on commit 2365a97

Please sign in to comment.