PostgreSQL Source Code git master
Macros | Functions | Variables
test_slru.c File Reference
#include "postgres.h"
#include "access/slru.h"
#include "access/transam.h"
#include "miscadmin.h"
#include "storage/fd.h"
#include "storage/ipc.h"
#include "storage/shmem.h"
#include "utils/builtins.h"
Include dependency graph for test_slru.c:

Go to the source code of this file.

Macros

#define  NUM_TEST_BUFFERS   16
 
#define  TestSlruCtl   (&TestSlruCtlData)
 

Functions

 
 
 
 
 
 
 
 
 
static bool  test_slru_scan_cb (SlruCtl ctl, char *filename, int64 segpage, void *data)
 
 
 
 
 
 
 
 
 
 
static void  test_slru_shmem_request (void)
 
static bool  test_slru_page_precedes_logically (int64 page1, int64 page2)
 
static void  test_slru_shmem_startup (void)
 
void  _PG_init (void)
 

Variables

 
 
 
 

Macro Definition Documentation

NUM_TEST_BUFFERS

#define NUM_TEST_BUFFERS   16

Definition at line 41 of file test_slru.c.

TestSlruCtl

#define TestSlruCtl   (&TestSlruCtlData)

Definition at line 44 of file test_slru.c.

Function Documentation

_PG_init()

void _PG_init ( void  )

Definition at line 255 of file test_slru.c.

256{
259 (errmsg("cannot load \"%s\" after startup", "test_slru"),
260 errdetail("\"%s\" must be loaded with \"shared_preload_libraries\".",
261 "test_slru")));
262
265
268}
int errdetail(const char *fmt,...)
Definition: elog.c:1207
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:150
shmem_startup_hook_type shmem_startup_hook
Definition: ipci.c:58
shmem_request_hook_type shmem_request_hook
Definition: miscinit.c:1789
bool process_shared_preload_libraries_in_progress
Definition: miscinit.c:1786
static void test_slru_shmem_startup(void)
Definition: test_slru.c:214
static shmem_startup_hook_type prev_shmem_startup_hook
Definition: test_slru.c:47
static shmem_request_hook_type prev_shmem_request_hook
Definition: test_slru.c:46
static void test_slru_shmem_request(void)
Definition: test_slru.c:198

References ereport, errdetail(), errmsg(), ERROR, prev_shmem_request_hook, prev_shmem_startup_hook, process_shared_preload_libraries_in_progress, shmem_request_hook, shmem_startup_hook, test_slru_shmem_request(), and test_slru_shmem_startup().

PG_FUNCTION_INFO_V1() [1/9]

PG_FUNCTION_INFO_V1 ( test_slru_delete_all  )

PG_FUNCTION_INFO_V1() [2/9]

PG_FUNCTION_INFO_V1 ( test_slru_page_delete  )

PG_FUNCTION_INFO_V1() [3/9]

PG_FUNCTION_INFO_V1 ( test_slru_page_exists  )

PG_FUNCTION_INFO_V1() [4/9]

PG_FUNCTION_INFO_V1 ( test_slru_page_read  )

PG_FUNCTION_INFO_V1() [5/9]

PG_FUNCTION_INFO_V1 ( test_slru_page_readonly  )

PG_FUNCTION_INFO_V1() [6/9]

PG_FUNCTION_INFO_V1 ( test_slru_page_sync  )

PG_FUNCTION_INFO_V1() [7/9]

PG_FUNCTION_INFO_V1 ( test_slru_page_truncate  )

PG_FUNCTION_INFO_V1() [8/9]

PG_FUNCTION_INFO_V1 ( test_slru_page_write  )

PG_FUNCTION_INFO_V1() [9/9]

PG_FUNCTION_INFO_V1 ( test_slru_page_writeall  )

test_slru_delete_all()

Datum test_slru_delete_all ( PG_FUNCTION_ARGS  )

Definition at line 185 of file test_slru.c.

186{
187 /* this calls SlruScanDirCbDeleteAll() internally, ensuring deletion */
189
191}
#define PG_RETURN_VOID()
Definition: fmgr.h:349
bool SlruScanDirectory(SlruCtl ctl, SlruScanCallback callback, void *data)
Definition: slru.c:1816
static bool test_slru_scan_cb(SlruCtl ctl, char *filename, int64 segpage, void *data)
Definition: test_slru.c:50
#define TestSlruCtl
Definition: test_slru.c:44

References PG_RETURN_VOID, SlruScanDirectory(), test_slru_scan_cb(), and TestSlruCtl.

test_slru_page_delete()

Datum test_slru_page_delete ( PG_FUNCTION_ARGS  )

Definition at line 161 of file test_slru.c.

162{
163 int64 pageno = PG_GETARG_INT64(0);
164 FileTag ftag;
165
166 ftag.segno = pageno / SLRU_PAGES_PER_SEGMENT;
168
169 elog(NOTICE, "Called SlruDeleteSegment() for segment %" PRIu64,
170 ftag.segno);
171
173}
int64_t int64
Definition: c.h:535
#define elog(elevel,...)
Definition: elog.h:226
#define NOTICE
Definition: elog.h:35
#define PG_GETARG_INT64(n)
Definition: fmgr.h:283
void SlruDeleteSegment(SlruCtl ctl, int64 segno)
Definition: slru.c:1551
#define SLRU_PAGES_PER_SEGMENT
Definition: slru.h:39
Definition: sync.h:51
uint64 segno
Definition: sync.h:55

References elog, NOTICE, PG_GETARG_INT64, PG_RETURN_VOID, FileTag::segno, SLRU_PAGES_PER_SEGMENT, SlruDeleteSegment(), and TestSlruCtl.

test_slru_page_exists()

Datum test_slru_page_exists ( PG_FUNCTION_ARGS  )

Definition at line 130 of file test_slru.c.

131{
132 int64 pageno = PG_GETARG_INT64(0);
133 bool found;
134 LWLock *lock = SimpleLruGetBankLock(TestSlruCtl, pageno);
135
138 LWLockRelease(lock);
139
140 PG_RETURN_BOOL(found);
141}
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1174
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1894
@ LW_EXCLUSIVE
Definition: lwlock.h:112
bool SimpleLruDoesPhysicalPageExist(SlruCtl ctl, int64 pageno)
Definition: slru.c:771
static LWLock * SimpleLruGetBankLock(SlruCtl ctl, int64 pageno)
Definition: slru.h:175
Definition: lwlock.h:42

References LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), PG_GETARG_INT64, PG_RETURN_BOOL, SimpleLruDoesPhysicalPageExist(), SimpleLruGetBankLock(), and TestSlruCtl.

test_slru_page_precedes_logically()

static bool test_slru_page_precedes_logically ( int64  page1,
int64  page2 
)
static

Definition at line 208 of file test_slru.c.

209{
210 return page1 < page2;
211}

Referenced by test_slru_shmem_startup().

test_slru_page_read()

Datum test_slru_page_read ( PG_FUNCTION_ARGS  )

Definition at line 92 of file test_slru.c.

93{
94 int64 pageno = PG_GETARG_INT64(0);
95 bool write_ok = PG_GETARG_BOOL(1);
96 char *data = NULL;
97 int slotno;
99
100 /* find page in buffers, reading it if necessary */
102 slotno = SimpleLruReadPage(TestSlruCtl, pageno,
103 write_ok, InvalidTransactionId);
104 data = (char *) TestSlruCtl->shared->page_buffer[slotno];
105 LWLockRelease(lock);
106
108}
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:372
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
const void * data
int SimpleLruReadPage(SlruCtl ctl, int64 pageno, bool write_ok, TransactionId xid)
Definition: slru.c:527
#define InvalidTransactionId
Definition: transam.h:31
text * cstring_to_text(const char *s)
Definition: varlena.c:181

References cstring_to_text(), data, InvalidTransactionId, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), PG_GETARG_BOOL, PG_GETARG_INT64, PG_RETURN_TEXT_P, SimpleLruGetBankLock(), SimpleLruReadPage(), and TestSlruCtl.

test_slru_page_readonly()

Datum test_slru_page_readonly ( PG_FUNCTION_ARGS  )

Definition at line 111 of file test_slru.c.

112{
113 int64 pageno = PG_GETARG_INT64(0);
114 char *data = NULL;
115 int slotno;
116 LWLock *lock = SimpleLruGetBankLock(TestSlruCtl, pageno);
117
118 /* find page in buffers, reading it if necessary */
120 pageno,
122 Assert(LWLockHeldByMe(lock));
123 data = (char *) TestSlruCtl->shared->page_buffer[slotno];
124 LWLockRelease(lock);
125
127}
Assert(PointerIsAligned(start, uint64))
bool LWLockHeldByMe(LWLock *lock)
Definition: lwlock.c:1977
int SimpleLruReadPage_ReadOnly(SlruCtl ctl, int64 pageno, TransactionId xid)
Definition: slru.c:630

References Assert(), cstring_to_text(), data, InvalidTransactionId, LWLockHeldByMe(), LWLockRelease(), PG_GETARG_INT64, PG_RETURN_TEXT_P, SimpleLruGetBankLock(), SimpleLruReadPage_ReadOnly(), and TestSlruCtl.

test_slru_page_sync()

Datum test_slru_page_sync ( PG_FUNCTION_ARGS  )

Definition at line 144 of file test_slru.c.

145{
146 int64 pageno = PG_GETARG_INT64(0);
147 FileTag ftag;
148 char path[MAXPGPATH];
149
150 /* note that this flushes the full file a segment is located in */
151 ftag.segno = pageno / SLRU_PAGES_PER_SEGMENT;
152 SlruSyncFileTag(TestSlruCtl, &ftag, path);
153
154 elog(NOTICE, "Called SlruSyncFileTag() for segment %" PRIu64 " on path %s",
155 ftag.segno, path);
156
158}
#define MAXPGPATH
int SlruSyncFileTag(SlruCtl ctl, const FileTag *ftag, char *path)
Definition: slru.c:1856

References elog, MAXPGPATH, NOTICE, PG_GETARG_INT64, PG_RETURN_VOID, FileTag::segno, SLRU_PAGES_PER_SEGMENT, SlruSyncFileTag(), and TestSlruCtl.

test_slru_page_truncate()

Datum test_slru_page_truncate ( PG_FUNCTION_ARGS  )

Definition at line 176 of file test_slru.c.

177{
178 int64 pageno = PG_GETARG_INT64(0);
179
182}
void SimpleLruTruncate(SlruCtl ctl, int64 cutoffPage)
Definition: slru.c:1433

References PG_GETARG_INT64, PG_RETURN_VOID, SimpleLruTruncate(), and TestSlruCtl.

test_slru_page_write()

Datum test_slru_page_write ( PG_FUNCTION_ARGS  )

Definition at line 57 of file test_slru.c.

58{
59 int64 pageno = PG_GETARG_INT64(0);
61 int slotno;
63
65 slotno = SimpleLruZeroPage(TestSlruCtl, pageno);
66
67 /* these should match */
68 Assert(TestSlruCtl->shared->page_number[slotno] == pageno);
69
70 /* mark the page as dirty so as it would get written */
71 TestSlruCtl->shared->page_dirty[slotno] = true;
72 TestSlruCtl->shared->page_status[slotno] = SLRU_PAGE_VALID;
73
74 /* write given data to the page, up to the limit of the page */
75 strncpy(TestSlruCtl->shared->page_buffer[slotno], data,
76 BLCKSZ - 1);
77
79 LWLockRelease(lock);
80
82}
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
void SimpleLruWritePage(SlruCtl ctl, int slotno)
Definition: slru.c:757
int SimpleLruZeroPage(SlruCtl ctl, int64 pageno)
Definition: slru.c:375
@ SLRU_PAGE_VALID
Definition: slru.h:51
char * text_to_cstring(const text *t)
Definition: varlena.c:214

References Assert(), data, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), PG_GETARG_INT64, PG_GETARG_TEXT_PP, PG_RETURN_VOID, SimpleLruGetBankLock(), SimpleLruWritePage(), SimpleLruZeroPage(), SLRU_PAGE_VALID, TestSlruCtl, and text_to_cstring().

test_slru_page_writeall()

Datum test_slru_page_writeall ( PG_FUNCTION_ARGS  )

Definition at line 85 of file test_slru.c.

86{
89}
void SimpleLruWriteAll(SlruCtl ctl, bool allow_redirtied)
Definition: slru.c:1347

References PG_RETURN_VOID, SimpleLruWriteAll(), and TestSlruCtl.

test_slru_scan_cb()

static bool test_slru_scan_cb ( SlruCtl  ctl,
char *  filename,
int64  segpage,
void *  data 
)
static

Definition at line 50 of file test_slru.c.

51{
52 elog(NOTICE, "Calling test_slru_scan_cb()");
53 return SlruScanDirCbDeleteAll(ctl, filename, segpage, data);
54}
static char * filename
Definition: pg_dumpall.c:120
tree ctl
Definition: radixtree.h:1838
bool SlruScanDirCbDeleteAll(SlruCtl ctl, char *filename, int64 segpage, void *data)
Definition: slru.c:1769

References ctl, data, elog, filename, NOTICE, and SlruScanDirCbDeleteAll().

Referenced by test_slru_delete_all().

test_slru_shmem_request()

static void test_slru_shmem_request ( void  )
static

Definition at line 198 of file test_slru.c.

199{
202
203 /* reserve shared memory for the test SLRU */
205}
void RequestAddinShmemSpace(Size size)
Definition: ipci.c:74
Size SimpleLruShmemSize(int nslots, int nlsns)
Definition: slru.c:198
#define NUM_TEST_BUFFERS
Definition: test_slru.c:41

References NUM_TEST_BUFFERS, prev_shmem_request_hook, RequestAddinShmemSpace(), and SimpleLruShmemSize().

Referenced by _PG_init().

test_slru_shmem_startup()

static void test_slru_shmem_startup ( void  )
static

Definition at line 214 of file test_slru.c.

215{
216 /*
217 * Short segments names are well tested elsewhere so in this test we are
218 * focusing on long names.
219 */
220 const bool long_segment_names = true;
221 const char slru_dir_name[] = "pg_test_slru";
222 int test_tranche_id = -1;
223 int test_buffer_tranche_id = -1;
224
227
228 /*
229 * Create the SLRU directory if it does not exist yet, from the root of
230 * the data directory.
231 */
232 (void) MakePGDirectory(slru_dir_name);
233
234 /*
235 * Initialize the SLRU facility. In EXEC_BACKEND builds, the
236 * shmem_startup_hook is called in the postmaster and in each backend, but
237 * we only need to generate the LWLock tranches once. Note that these
238 * tranche ID variables are not used by SimpleLruInit() when
239 * IsUnderPostmaster is true.
240 */
242 {
243 test_tranche_id = LWLockNewTrancheId("test_slru_tranche");
244 test_buffer_tranche_id = LWLockNewTrancheId("test_buffer_tranche");
245 }
246
248 SimpleLruInit(TestSlruCtl, "TestSLRU",
249 NUM_TEST_BUFFERS, 0, slru_dir_name,
250 test_buffer_tranche_id, test_tranche_id, SYNC_HANDLER_NONE,
251 long_segment_names);
252}
int MakePGDirectory(const char *directoryName)
Definition: fd.c:3975
bool IsUnderPostmaster
Definition: globals.c:120
int LWLockNewTrancheId(const char *name)
Definition: lwlock.c:596
void SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns, const char *subdir, int buffer_tranche_id, int bank_tranche_id, SyncRequestHandler sync_handler, bool long_segment_names)
Definition: slru.c:252
@ SYNC_HANDLER_NONE
Definition: sync.h:42
static bool test_slru_page_precedes_logically(int64 page1, int64 page2)
Definition: test_slru.c:208

References IsUnderPostmaster, LWLockNewTrancheId(), MakePGDirectory(), NUM_TEST_BUFFERS, prev_shmem_startup_hook, SimpleLruInit(), SYNC_HANDLER_NONE, test_slru_page_precedes_logically(), and TestSlruCtl.

Referenced by _PG_init().

Variable Documentation

PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 25 of file test_slru.c.

prev_shmem_request_hook

shmem_request_hook_type prev_shmem_request_hook = NULL
static

Definition at line 46 of file test_slru.c.

Referenced by _PG_init(), and test_slru_shmem_request().

prev_shmem_startup_hook

shmem_startup_hook_type prev_shmem_startup_hook = NULL
static

Definition at line 47 of file test_slru.c.

Referenced by _PG_init(), and test_slru_shmem_startup().

TestSlruCtlData

SlruCtlData TestSlruCtlData
static

Definition at line 43 of file test_slru.c.

AltStyle によって変換されたページ (->オリジナル) /