Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2b043f1

Browse files
dutowCommitfest Bot
authored and
Commitfest Bot
committed
SMGR GUC variable and chaining
The overall goal of this commit is to introduce a user interface to the previous SMGR patch. The idea is to allow a simple configuration for multiple "modificator" SMGRs similar to the fsync_checker in the original proposal. * Extensions should be able to declare a named lists of SMGR implementations, also specifying if the given SMGR is an "end" implementation for actual storage, or if it is a modifier implementation for some other purpose. * Users should be able to specify a list of SMGRs: possibly multiple modifiers, and one storage implementation at the end to configure how the storage manager is constructed. This commit introduces a new GUC variable, `smgr_chain`, which allows users to configure multiple SMGR implementations: it is a comma separated list, where the last entry most be a storage implementation, the others must be modifiers. The default value of this variable is "md". The internal storage manager API is also refactored to include an easy way for SMGR implementations to support proper chaining. Modifier SMGR implementations also only have to implement the functions they actually change, and can leave everything else as empty (NULL). And with this change we can make the functions of the md smgr static. The fsync example extension is also modified to match the new API.
1 parent 790fe55 commit 2b043f1

File tree

12 files changed

+448
-161
lines changed

12 files changed

+448
-161
lines changed

contrib/fsync_checker/fsync_checker_smgr.c

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ typedef struct
2727
void _PG_init(void);
2828

2929
static void fsync_checker_extend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
30-
const void *buffer, bool skipFsync);
31-
static void fsync_checker_immedsync(SMgrRelation reln, ForkNumber forknum);
30+
const void *buffer, bool skipFsync, SmgrChainIndex chain_index);
31+
static void fsync_checker_immedsync(SMgrRelation reln, ForkNumber forknum, SmgrChainIndex chain_index);
3232
static void fsync_checker_writev(SMgrRelation reln, ForkNumber forknum,
3333
BlockNumber blocknum, const void **buffers,
34-
BlockNumber nblocks, bool skipFsync);
34+
BlockNumber nblocks, bool skipFsync, SmgrChainIndex chain_index);
3535
static void fsync_checker_writeback(SMgrRelation reln, ForkNumber forknum,
36-
BlockNumber blocknum, BlockNumber nblocks);
36+
BlockNumber blocknum, BlockNumber nblocks, SmgrChainIndex chain_index);
3737
static void fsync_checker_zeroextend(SMgrRelation reln, ForkNumber forknum,
38-
BlockNumber blocknum, int nblocks, bool skipFsync);
38+
BlockNumber blocknum, int nblocks, bool skipFsync, SmgrChainIndex chain_index);
3939

4040
static void fsync_checker_checkpoint_create(const CheckPoint *checkPoint);
4141
static void fsync_checker_shmem_request(void);
@@ -47,24 +47,25 @@ static void remove_reln(SMgrRelation reln, ForkNumber forknum);
4747
static SMgrId fsync_checker_smgr_id;
4848
static const struct f_smgr fsync_checker_smgr = {
4949
.name = "fsync_checker",
50-
.smgr_init = mdinit,
50+
.chain_position = SMGR_CHAIN_MODIFIER,
51+
.smgr_init = NULL,
5152
.smgr_shutdown = NULL,
52-
.smgr_open = mdopen,
53-
.smgr_close = mdclose,
54-
.smgr_create = mdcreate,
55-
.smgr_exists = mdexists,
56-
.smgr_unlink = mdunlink,
53+
.smgr_open = NULL,
54+
.smgr_close = NULL,
55+
.smgr_create = NULL,
56+
.smgr_exists = NULL,
57+
.smgr_unlink = NULL,
5758
.smgr_extend = fsync_checker_extend,
5859
.smgr_zeroextend = fsync_checker_zeroextend,
59-
.smgr_prefetch = mdprefetch,
60-
.smgr_maxcombine = mdmaxcombine,
61-
.smgr_readv = mdreadv,
60+
.smgr_prefetch = NULL,
61+
.smgr_maxcombine = NULL,
62+
.smgr_readv = NULL,
6263
.smgr_writev = fsync_checker_writev,
6364
.smgr_writeback = fsync_checker_writeback,
64-
.smgr_nblocks = mdnblocks,
65-
.smgr_truncate = mdtruncate,
65+
.smgr_nblocks = NULL,
66+
.smgr_truncate = NULL,
6667
.smgr_immedsync = fsync_checker_immedsync,
67-
.smgr_registersync = mdregistersync,
68+
.smgr_registersync = NULL,
6869
};
6970

7071
static HTAB *volatile_relns;
@@ -91,8 +92,6 @@ _PG_init(void)
9192
* could use MdSmgrRelation as the parent.
9293
*/
9394
fsync_checker_smgr_id = smgr_register(&fsync_checker_smgr, 0);
94-
95-
storage_manager_id = fsync_checker_smgr_id;
9695
}
9796

9897
static void
@@ -200,50 +199,50 @@ remove_reln(SMgrRelation reln, ForkNumber forknum)
200199

201200
static void
202201
fsync_checker_extend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
203-
const void *buffer, bool skipFsync)
202+
const void *buffer, bool skipFsync, SmgrChainIndex chain_index)
204203
{
205204
if (!SmgrIsTemp(reln) && !skipFsync)
206205
add_reln(reln, forknum);
207206

208-
mdextend(reln, forknum, blocknum, buffer, skipFsync);
207+
smgr_extend_next(reln, forknum, blocknum, buffer, skipFsync, chain_index + 1);
209208
}
210209

211210
static void
212-
fsync_checker_immedsync(SMgrRelation reln, ForkNumber forknum)
211+
fsync_checker_immedsync(SMgrRelation reln, ForkNumber forknum, SmgrChainIndex chain_index)
213212
{
214213
if (!SmgrIsTemp(reln))
215214
remove_reln(reln, forknum);
216215

217-
mdimmedsync(reln, forknum);
216+
smgr_immedsync_next(reln, forknum, chain_index + 1);
218217
}
219218

220219
static void
221220
fsync_checker_writev(SMgrRelation reln, ForkNumber forknum,
222221
BlockNumber blocknum, const void **buffers,
223-
BlockNumber nblocks, bool skipFsync)
222+
BlockNumber nblocks, bool skipFsync, SmgrChainIndex chain_index)
224223
{
225224
if (!SmgrIsTemp(reln) && !skipFsync)
226225
add_reln(reln, forknum);
227226

228-
mdwritev(reln, forknum, blocknum, buffers, nblocks, skipFsync);
227+
smgr_writev_next(reln, forknum, blocknum, buffers, nblocks, skipFsync, chain_index + 1);
229228
}
230229

231230
static void
232231
fsync_checker_writeback(SMgrRelation reln, ForkNumber forknum,
233-
BlockNumber blocknum, BlockNumber nblocks)
232+
BlockNumber blocknum, BlockNumber nblocks, SmgrChainIndex chain_index)
234233
{
235234
if (!SmgrIsTemp(reln))
236235
remove_reln(reln, forknum);
237236

238-
mdwriteback(reln, forknum, blocknum, nblocks);
237+
smgr_writeback_next(reln, forknum, blocknum, nblocks, chain_index + 1);
239238
}
240239

241240
static void
242241
fsync_checker_zeroextend(SMgrRelation reln, ForkNumber forknum,
243-
BlockNumber blocknum, int nblocks, bool skipFsync)
242+
BlockNumber blocknum, int nblocks, bool skipFsync, SmgrChainIndex chain_index)
244243
{
245244
if (!SmgrIsTemp(reln) && !skipFsync)
246245
add_reln(reln, forknum);
247246

248-
mdzeroextend(reln, forknum, blocknum, nblocks, skipFsync);
247+
smgr_zeroextend_next(reln, forknum, blocknum, nblocks, skipFsync, chain_index + 1);
249248
}

src/backend/postmaster/postmaster.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,8 @@ PostmasterMain(int argc, char *argv[])
925925
*/
926926
process_shared_preload_libraries();
927927

928+
process_smgr_chain();
929+
928930
/*
929931
* Initialize SSL library, if specified.
930932
*/

0 commit comments

Comments
 (0)