summaryrefslogtreecommitdiff
path: root/src/bin/pg_upgrade/slru_io.h
blob: 5c80a679b4d1364ad5dc1d4df55043b36311264a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * slru_io.h
 *
 * Copyright (c) 2025, PostgreSQL Global Development Group
 * src/bin/pg_upgrade/slru_io.h
 */

#ifndef SLRU_IO_H
#define SLRU_IO_H

/*
 * State for reading or writing an SLRU, with a one page buffer.
 */
typedef struct SlruSegState
{
	bool		writing;
	bool		long_segment_names;

	char	   *dir;
	char	   *fn;
	int			fd;
	int64		segno;
	uint64		pageno;

	PGAlignedBlock buf;
} SlruSegState;

extern SlruSegState *AllocSlruRead(const char *dir, bool long_segment_names);
extern char *SlruReadSwitchPageSlow(SlruSegState *state, uint64 pageno);
extern void FreeSlruRead(SlruSegState *state);

static inline char *
SlruReadSwitchPage(SlruSegState *state, uint64 pageno)
{
	if (state->segno != -1 && pageno == state->pageno)
		return state->buf.data;
	return SlruReadSwitchPageSlow(state, pageno);
}

extern SlruSegState *AllocSlruWrite(const char *dir, bool long_segment_names);
extern char *SlruWriteSwitchPageSlow(SlruSegState *state, uint64 pageno);
extern void FreeSlruWrite(SlruSegState *state);

static inline char *
SlruWriteSwitchPage(SlruSegState *state, uint64 pageno)
{
	if (state->segno != -1 && pageno == state->pageno)
		return state->buf.data;
	return SlruWriteSwitchPageSlow(state, pageno);
}

#endif							/* SLRU_IO_H */