Skip to content

Commit f2c6f61

Browse files
author
Commitfest Bot
committed
[CF 7322] v1 - Cache invalidation for I/O Workers
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/7322 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/CAE8JnxM4g539F3=kfanASsgU7USZ3Hkc5uOad+0+9_J3360o5w@mail.gmail.com Author(s): Alexandre Felipe
2 parents 9e17d25 + d712479 commit f2c6f61

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

src/backend/storage/aio/method_worker.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
#include "storage/lwlock.h"
4545
#include "storage/pmsignal.h"
4646
#include "storage/proc.h"
47+
#include "storage/sinvaladt.h"
4748
#include "storage/shmem.h"
49+
#include "storage/smgr.h"
4850
#include "tcop/tcopprot.h"
4951
#include "utils/injection_point.h"
5052
#include "utils/memdebug.h"
@@ -683,6 +685,24 @@ check_io_worker_gucs(void)
683685
"io_max_workers", io_max_workers)));
684686
}
685687

688+
/*
689+
* Handle cache invalidation messages for IoWorker
690+
*
691+
* Same as LocalExecuteInvalidationMessage for backends,
692+
* but in IoWorkers handle only file invalidation messages.
693+
*/
694+
static void
695+
pgaio_cache_invalidation_callback(SharedInvalidationMessage *msg)
696+
{
697+
if (msg->id == SHAREDINVALSMGR_ID)
698+
{
699+
RelFileLocatorBackend rlocator;
700+
rlocator.locator = msg->sm.rlocator;
701+
rlocator.backend = (msg->sm.backend_hi << 16) | (int) msg->sm.backend_lo;
702+
smgrreleaserellocator(rlocator);
703+
}
704+
}
705+
686706
void
687707
IoWorkerMain(const void *startup_data, size_t startup_data_len)
688708
{
@@ -698,6 +718,11 @@ IoWorkerMain(const void *startup_data, size_t startup_data_len)
698718

699719
AuxiliaryProcessMainCommon();
700720

721+
/*
722+
* IO workers cache file descriptors locally, subscribe to cluster-wide
723+
* cache invalidation events.
724+
*/
725+
SharedInvalBackendInit(false);
701726
pqsignal(SIGHUP, SignalHandlerForConfigReload);
702727
pqsignal(SIGINT, die); /* to allow manually triggering worker restart */
703728

@@ -1032,6 +1057,12 @@ IoWorkerMain(const void *startup_data, size_t startup_data_len)
10321057

10331058
CHECK_FOR_INTERRUPTS();
10341059

1060+
/*
1061+
* Handle pending invalidation one by one.
1062+
* smgrreleaseall used when there are too many pending invalidations.
1063+
*/
1064+
ReceiveSharedInvalidMessages(pgaio_cache_invalidation_callback, smgrreleaseall);
1065+
10351066
if (ConfigReloadPending)
10361067
{
10371068
int io_max_workers_prev = io_max_workers;

0 commit comments

Comments
 (0)