Re: Extensible sync handler registration (register_sync_handler)

From: Greg Lamberson <greg(at)lamco(dot)io>
To: Yash Jadhav <yash(dot)jadhav8008(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Extensible sync handler registration (register_sync_handler)
Date: 2026-11-26 17:39:09
Message-ID: 179571474976.160020.16455603992977117608@lamco.io
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Yash,

Thanks for finding the crash with a NULL sync_unlinkfiletag and for
thinking through how to handle it. Since your question was really about
which check to write, I've written it into v3 so it can make this
commitfest, and I've credited you for the report and the review.

I'd go with rejecting such requests, but where they're queued rather
than at registration. A NULL sync_unlinkfiletag or sync_filetagmatches
has to stay legal at registration: The built-in CLOG, commit_ts and
multixact handlers define only sync_syncfiletag, and the patch documents
that for the same reason. What isn't legal is queueing an unlink or
filter request for such a handler, and RegisterSyncRequest() is where
that happens. v3 raises an ERROR there naming the handler and the
missing callback, so the extension's bug shows up in the backend that
caused it and the request never reaches the checkpointer.

That leaves one way around the check: ForwardSyncRequest() is exported,
so an extension could queue a request without going through
RegisterSyncRequest(). For that case RememberSyncRequest() logs a
WARNING and drops the request. An ERROR there would make the
checkpointer lose the rest of the batch it was absorbing, other
handlers' fsync requests included, and a crash (your option 2) restarts
the whole cluster for one extension's mistake. Dropping it does lose
that unlink, as you say, but only on a path that already went around the
API, and the WARNING names the handler. Since the request never enters
pendingUnlinks, SyncPostCheckpoint() can't meet a NULL callback.

v3 attached. Changes since v2:

- 0001: The checks above in RegisterSyncRequest() and
RememberSyncRequest(), with the header comments and the SGML page
updated to match, and Reported-by and Reviewed-by lines for you.
- 0002: Rebased onto current master past the test_wait_lsn entries. The
test module now registers a second handler with only sync_syncfiletag,
like CLOG, and the TAP test checks that unlink and filter requests to
it fail with the new error, that forwarded ones are dropped with the
warning, and that the checkpointer keeps running throughout.

Both patches apply to master as of today (d5fb939db80) with git am, and
the module's TAP test and the main regression suite pass with assertions
enabled.

Regards,
Greg

Attachment Content-Type Size
v3-0001-Make-sync.c-syncsw-extensible-via-register_sync_h.patch text/x-patch 29.2 KB
v3-0002-Add-test-module-for-sync-handler-registration.patch text/x-patch 20.4 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message koussaymehdouani 2026-11-26 18:19:01 Re: Fix direct conversion tables for single-byte Cyrillic encodings (Bug #19831)
Previous Message Manu 2026-11-26 17:35:39 Re: Allow progress tracking of sub-commands