1/*-------------------------------------------------------------------------
4 * Block reference tables.
6 * A block reference table is used to keep track of which blocks have
7 * been modified by WAL records within a certain LSN range.
9 * For each relation fork, there is a "limit block number". All existing
10 * blocks greater than or equal to the limit block number must be
11 * considered modified; for those less than the limit block number,
12 * we maintain a bitmap. When a relation fork is created or dropped,
13 * the limit block number should be set to 0. When it's truncated,
14 * the limit block number should be set to the length in blocks to
15 * which it was truncated.
17 * Portions Copyright (c) 2010-2025, PostgreSQL Global Development Group
19 * src/include/common/blkreftable.h
21 *-------------------------------------------------------------------------
29/* Magic number for serialization file format. */
30 #define BLOCKREFTABLE_MAGIC 0x652b137b
38 * The return value of io_callback_fn should be the number of bytes read
39 * or written. If an error occurs, the functions should report it and
40 * not return. When used as a write callback, short writes should be retried
41 * or treated as errors, so that if the callback returns, the return value
42 * is always the request length.
44 * report_error_fn should not return.
51 * Functions for manipulating an entire in-memory block reference table.
64 void *write_callback_arg);
77 * Functions for reading a block reference table incrementally from disk.
80 void *read_callback_arg,
83 void *error_callback_arg);
94 * Functions for writing a block reference table incrementally to disk.
96 * Note that entries must be written in the proper order, that is, sorted by
97 * database, then tablespace, then relfilenumber, then fork number. Caller
98 * is responsible for supplying data in the correct order. If that seems hard,
99 * use an in-memory BlockRefTable instead.
102 void *write_callback_arg);
116#endif /* BLKREFTABLE_H */
void BlockRefTableFreeEntry(BlockRefTableEntry *entry)
BlockRefTableEntry * BlockRefTableGetEntry(BlockRefTable *brtab, const RelFileLocator *rlocator, ForkNumber forknum, BlockNumber *limit_block)
void(* report_error_fn)(void *callback_arg, char *msg,...) pg_attribute_printf(2
bool BlockRefTableReaderNextRelation(BlockRefTableReader *reader, RelFileLocator *rlocator, ForkNumber *forknum, BlockNumber *limit_block)
int BlockRefTableEntryGetBlocks(BlockRefTableEntry *entry, BlockNumber start_blkno, BlockNumber stop_blkno, BlockNumber *blocks, int nblocks)
void BlockRefTableMarkBlockModified(BlockRefTable *brtab, const RelFileLocator *rlocator, ForkNumber forknum, BlockNumber blknum)
BlockRefTableWriter * CreateBlockRefTableWriter(io_callback_fn write_callback, void *write_callback_arg)
void BlockRefTableWriteEntry(BlockRefTableWriter *writer, BlockRefTableEntry *entry)
void BlockRefTableEntryMarkBlockModified(BlockRefTableEntry *entry, ForkNumber forknum, BlockNumber blknum)
BlockRefTableReader * CreateBlockRefTableReader(io_callback_fn read_callback, void *read_callback_arg, char *error_filename, report_error_fn error_callback, void *error_callback_arg)
unsigned BlockRefTableReaderGetBlocks(BlockRefTableReader *reader, BlockNumber *blocks, int nblocks)
void BlockRefTableSetLimitBlock(BlockRefTable *brtab, const RelFileLocator *rlocator, ForkNumber forknum, BlockNumber limit_block)
void BlockRefTableEntrySetLimitBlock(BlockRefTableEntry *entry, BlockNumber limit_block)
BlockRefTableEntry * CreateBlockRefTableEntry(RelFileLocator rlocator, ForkNumber forknum)
void WriteBlockRefTable(BlockRefTable *brtab, io_callback_fn write_callback, void *write_callback_arg)
void DestroyBlockRefTableReader(BlockRefTableReader *reader)
void(*) BlockRefTable CreateEmptyBlockRefTable)(void)
int(* io_callback_fn)(void *callback_arg, void *data, int length)
void DestroyBlockRefTableWriter(BlockRefTableWriter *writer)
#define pg_attribute_printf(f, a)