Skip to content

Commit 3c95ad7

Browse files
committed
Add hook in pg_signal_backend()
The purpose of the hook is to facilitate Lakebase's behavior of not allowing customers to cancel queries on replicas. Lakebase exposes a single endpoint to customers unlike Neon, where there is an endpoint for the primary and all replicas. Lakebase has had customer issues where they do the following: # On connection 1 SELECT pid from pg_stat_activity WHERE ...; # On connection 2 SELECT pg_cancel_backend(pid) -- Where pid is from connection 1 Connection 2 is not guaranteed to go to the same endpoint, so a customer may call pg_cancel_backend() on the wrong endpoint. Commonly, this will end up in an error because the PID does not exist, but in rare cases PIDs will align across endpoints, and the customer will cancel a query they didn't want to cancel. Whether we want to keep this hook indefinitely requires talking to product, and explaining the situation. Signed-off-by: Tristan Partin <tristan.partin@databricks.com>
1 parent 04c7d4f commit 3c95ad7

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/backend/storage/ipc/signalfuncs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@
2020
#include "miscadmin.h"
2121
#include "pgstat.h"
2222
#include "postmaster/syslogger.h"
23+
#include "storage/ipc.h"
2324
#include "storage/pmsignal.h"
2425
#include "storage/proc.h"
2526
#include "storage/procarray.h"
2627
#include "utils/acl.h"
2728
#include "utils/fmgrprotos.h"
2829

2930

31+
pg_signal_backend_hook_type pg_signal_backend_hook = NULL;
32+
3033
/*
3134
* Send a signal to another backend.
3235
*
@@ -50,6 +53,9 @@ pg_signal_backend(int pid, int sig)
5053
{
5154
PGPROC *proc = BackendPidGetProc(pid);
5255

56+
if (pg_signal_backend_hook)
57+
pg_signal_backend_hook();
58+
5359
/*
5460
* BackendPidGetProc returns NULL if the pid isn't valid; but by the time
5561
* we reach kill(), a process for which we get a valid proc here might

src/include/storage/ipc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
typedef void (*pg_on_exit_callback) (int code, Datum arg);
2222
typedef void (*shmem_startup_hook_type) (void);
2323

24+
/* NEON: The hook is called when a backend is about to be signaled. */
25+
typedef void (*pg_signal_backend_hook_type) ();
26+
extern PGDLLIMPORT pg_signal_backend_hook_type pg_signal_backend_hook;
27+
2428
/*----------
2529
* API for handling cleanup that must occur during either ereport(ERROR)
2630
* or ereport(FATAL) exits from a block of code. (Typical examples are

0 commit comments

Comments
 (0)