Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita87987c

Browse files
committed
Move WAL sequence code into its own file
This split exists for most of the other RMGRs, and makes cleaner theseparation between the WAL code, the redo code and the recorddescription code (already in its own file) when it comes to the sequenceRMGR. The redo and masking routines are moved to a new file,sequence_xlog.c. All the RMGR routines are now located in a new header,sequence_xlog.h.This separation is useful for a different patch related to sequencesthat I have been working on, where it makes a refactoring of sequence.ceasier if its RMGR routines and its core routines are split.Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>Discussion:https://postgr.es/m/aSfTxIWjiXkTKh1E@paquier.xyz
1 parentd03668e commita87987c

File tree

9 files changed

+132
-95
lines changed

9 files changed

+132
-95
lines changed

‎src/backend/access/rmgrdesc/seqdesc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
#include"postgres.h"
1616

17-
#include"commands/sequence.h"
17+
#include"commands/sequence_xlog.h"
1818

1919

2020
void

‎src/backend/access/transam/rmgr.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include"access/xact.h"
3434
#include"catalog/storage_xlog.h"
3535
#include"commands/dbcommands_xlog.h"
36-
#include"commands/sequence.h"
36+
#include"commands/sequence_xlog.h"
3737
#include"commands/tablespace.h"
3838
#include"replication/decode.h"
3939
#include"replication/message.h"

‎src/backend/commands/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ OBJS = \
5353
schemacmds.o\
5454
seclabel.o\
5555
sequence.o\
56+
sequence_xlog.o\
5657
statscmds.o\
5758
subscriptioncmds.o\
5859
tablecmds.o\

‎src/backend/commands/meson.build‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ backend_sources += files(
4141
'schemacmds.c',
4242
'seclabel.c',
4343
'sequence.c',
44+
'sequence_xlog.c',
4445
'statscmds.c',
4546
'subscriptioncmds.c',
4647
'tablecmds.c',

‎src/backend/commands/sequence.c‎

Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@
1414
*/
1515
#include"postgres.h"
1616

17-
#include"access/bufmask.h"
1817
#include"access/htup_details.h"
1918
#include"access/multixact.h"
2019
#include"access/relation.h"
2120
#include"access/sequence.h"
2221
#include"access/table.h"
2322
#include"access/transam.h"
2423
#include"access/xact.h"
25-
#include"access/xlog.h"
2624
#include"access/xloginsert.h"
27-
#include"access/xlogutils.h"
2825
#include"catalog/dependency.h"
2926
#include"catalog/indexing.h"
3027
#include"catalog/namespace.h"
@@ -34,11 +31,13 @@
3431
#include"catalog/storage_xlog.h"
3532
#include"commands/defrem.h"
3633
#include"commands/sequence.h"
34+
#include"commands/sequence_xlog.h"
3735
#include"commands/tablecmds.h"
3836
#include"funcapi.h"
3937
#include"miscadmin.h"
4038
#include"nodes/makefuncs.h"
4139
#include"parser/parse_type.h"
40+
#include"storage/bufmgr.h"
4241
#include"storage/lmgr.h"
4342
#include"storage/proc.h"
4443
#include"storage/smgr.h"
@@ -58,16 +57,6 @@
5857
*/
5958
#defineSEQ_LOG_VALS32
6059

61-
/*
62-
* The "special area" of a sequence's buffer page looks like this.
63-
*/
64-
#defineSEQ_MAGIC 0x1717
65-
66-
typedefstructsequence_magic
67-
{
68-
uint32magic;
69-
}sequence_magic;
70-
7160
/*
7261
* We store a SeqTable item for every sequence we have touched in the current
7362
* session. This is needed to hold onto nextval/currval state. (We can't
@@ -1907,56 +1896,6 @@ pg_sequence_last_value(PG_FUNCTION_ARGS)
19071896
PG_RETURN_NULL();
19081897
}
19091898

1910-
1911-
void
1912-
seq_redo(XLogReaderState*record)
1913-
{
1914-
XLogRecPtrlsn=record->EndRecPtr;
1915-
uint8info=XLogRecGetInfo(record)& ~XLR_INFO_MASK;
1916-
Bufferbuffer;
1917-
Pagepage;
1918-
Pagelocalpage;
1919-
char*item;
1920-
Sizeitemsz;
1921-
xl_seq_rec*xlrec= (xl_seq_rec*)XLogRecGetData(record);
1922-
sequence_magic*sm;
1923-
1924-
if (info!=XLOG_SEQ_LOG)
1925-
elog(PANIC,"seq_redo: unknown op code %u",info);
1926-
1927-
buffer=XLogInitBufferForRedo(record,0);
1928-
page=BufferGetPage(buffer);
1929-
1930-
/*
1931-
* We always reinit the page. However, since this WAL record type is also
1932-
* used for updating sequences, it's possible that a hot-standby backend
1933-
* is examining the page concurrently; so we mustn't transiently trash the
1934-
* buffer. The solution is to build the correct new page contents in
1935-
* local workspace and then memcpy into the buffer. Then only bytes that
1936-
* are supposed to change will change, even transiently. We must palloc
1937-
* the local page for alignment reasons.
1938-
*/
1939-
localpage= (Page)palloc(BufferGetPageSize(buffer));
1940-
1941-
PageInit(localpage,BufferGetPageSize(buffer),sizeof(sequence_magic));
1942-
sm= (sequence_magic*)PageGetSpecialPointer(localpage);
1943-
sm->magic=SEQ_MAGIC;
1944-
1945-
item= (char*)xlrec+sizeof(xl_seq_rec);
1946-
itemsz=XLogRecGetDataLen(record)-sizeof(xl_seq_rec);
1947-
1948-
if (PageAddItem(localpage,item,itemsz,FirstOffsetNumber, false, false)==InvalidOffsetNumber)
1949-
elog(PANIC,"seq_redo: failed to add item to page");
1950-
1951-
PageSetLSN(localpage,lsn);
1952-
1953-
memcpy(page,localpage,BufferGetPageSize(buffer));
1954-
MarkBufferDirty(buffer);
1955-
UnlockReleaseBuffer(buffer);
1956-
1957-
pfree(localpage);
1958-
}
1959-
19601899
/*
19611900
* Flush cached sequence information.
19621901
*/
@@ -1971,14 +1910,3 @@ ResetSequenceCaches(void)
19711910

19721911
last_used_seq=NULL;
19731912
}
1974-
1975-
/*
1976-
* Mask a Sequence page before performing consistency checks on it.
1977-
*/
1978-
void
1979-
seq_mask(char*page,BlockNumberblkno)
1980-
{
1981-
mask_page_lsn_and_checksum(page);
1982-
1983-
mask_unused_space(page);
1984-
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* sequence.c
4+
* RMGR WAL routines for sequences.
5+
*
6+
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7+
* Portions Copyright (c) 1994, Regents of the University of California
8+
*
9+
*
10+
* IDENTIFICATION
11+
* src/backend/commands/sequence_xlog.c
12+
*
13+
*-------------------------------------------------------------------------
14+
*/
15+
#include"postgres.h"
16+
17+
#include"access/bufmask.h"
18+
#include"access/xlogutils.h"
19+
#include"commands/sequence_xlog.h"
20+
#include"storage/bufmgr.h"
21+
22+
void
23+
seq_redo(XLogReaderState*record)
24+
{
25+
XLogRecPtrlsn=record->EndRecPtr;
26+
uint8info=XLogRecGetInfo(record)& ~XLR_INFO_MASK;
27+
Bufferbuffer;
28+
Pagepage;
29+
Pagelocalpage;
30+
char*item;
31+
Sizeitemsz;
32+
xl_seq_rec*xlrec= (xl_seq_rec*)XLogRecGetData(record);
33+
sequence_magic*sm;
34+
35+
if (info!=XLOG_SEQ_LOG)
36+
elog(PANIC,"seq_redo: unknown op code %u",info);
37+
38+
buffer=XLogInitBufferForRedo(record,0);
39+
page=BufferGetPage(buffer);
40+
41+
/*
42+
* We always reinit the page. However, since this WAL record type is also
43+
* used for updating sequences, it's possible that a hot-standby backend
44+
* is examining the page concurrently; so we mustn't transiently trash the
45+
* buffer. The solution is to build the correct new page contents in
46+
* local workspace and then memcpy into the buffer. Then only bytes that
47+
* are supposed to change will change, even transiently. We must palloc
48+
* the local page for alignment reasons.
49+
*/
50+
localpage= (Page)palloc(BufferGetPageSize(buffer));
51+
52+
PageInit(localpage,BufferGetPageSize(buffer),sizeof(sequence_magic));
53+
sm= (sequence_magic*)PageGetSpecialPointer(localpage);
54+
sm->magic=SEQ_MAGIC;
55+
56+
item= (char*)xlrec+sizeof(xl_seq_rec);
57+
itemsz=XLogRecGetDataLen(record)-sizeof(xl_seq_rec);
58+
59+
if (PageAddItem(localpage,item,itemsz,FirstOffsetNumber, false, false)==InvalidOffsetNumber)
60+
elog(PANIC,"seq_redo: failed to add item to page");
61+
62+
PageSetLSN(localpage,lsn);
63+
64+
memcpy(page,localpage,BufferGetPageSize(buffer));
65+
MarkBufferDirty(buffer);
66+
UnlockReleaseBuffer(buffer);
67+
68+
pfree(localpage);
69+
}
70+
71+
/*
72+
* Mask a Sequence page before performing consistency checks on it.
73+
*/
74+
void
75+
seq_mask(char*page,BlockNumberblkno)
76+
{
77+
mask_page_lsn_and_checksum(page);
78+
79+
mask_unused_space(page);
80+
}

‎src/bin/pg_waldump/rmgrdesc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include"access/xlog_internal.h"
2525
#include"catalog/storage_xlog.h"
2626
#include"commands/dbcommands_xlog.h"
27-
#include"commands/sequence.h"
27+
#include"commands/sequence_xlog.h"
2828
#include"commands/tablespace.h"
2929
#include"replication/message.h"
3030
#include"replication/origin.h"

‎src/include/commands/sequence.h‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@
1313
#ifndefSEQUENCE_H
1414
#defineSEQUENCE_H
1515

16-
#include"access/xlogreader.h"
1716
#include"catalog/objectaddress.h"
1817
#include"fmgr.h"
19-
#include"lib/stringinfo.h"
2018
#include"nodes/parsenodes.h"
2119
#include"parser/parse_node.h"
22-
#include"storage/relfilelocator.h"
23-
2420

2521
typedefstructFormData_pg_sequence_data
2622
{
@@ -42,15 +38,6 @@ typedef FormData_pg_sequence_data *Form_pg_sequence_data;
4238
#defineSEQ_COL_FIRSTCOLSEQ_COL_LASTVAL
4339
#defineSEQ_COL_LASTCOLSEQ_COL_CALLED
4440

45-
/* XLOG stuff */
46-
#defineXLOG_SEQ_LOG0x00
47-
48-
typedefstructxl_seq_rec
49-
{
50-
RelFileLocatorlocator;
51-
/* SEQUENCE TUPLE DATA FOLLOWS AT THE END */
52-
}xl_seq_rec;
53-
5441
externint64nextval_internal(Oidrelid,boolcheck_permissions);
5542
externDatumnextval(PG_FUNCTION_ARGS);
5643
externList*sequence_options(Oidrelid);
@@ -63,9 +50,4 @@ extern void ResetSequence(Oid seq_relid);
6350
externvoidSetSequence(Oidrelid,int64next,boolis_called);
6451
externvoidResetSequenceCaches(void);
6552

66-
externvoidseq_redo(XLogReaderState*record);
67-
externvoidseq_desc(StringInfobuf,XLogReaderState*record);
68-
externconstchar*seq_identify(uint8info);
69-
externvoidseq_mask(char*page,BlockNumberblkno);
70-
7153
#endif/* SEQUENCE_H */
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* sequence_xlog.h
4+
* Sequence WAL definitions.
5+
*
6+
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7+
* Portions Copyright (c) 1994, Regents of the University of California
8+
*
9+
* src/include/commands/sequence_xlog.h
10+
*
11+
*-------------------------------------------------------------------------
12+
*/
13+
14+
#ifndefSEQUENCE_XLOG_H
15+
#defineSEQUENCE_XLOG_H
16+
17+
#include"access/xlogreader.h"
18+
#include"lib/stringinfo.h"
19+
20+
/* Record identifier */
21+
#defineXLOG_SEQ_LOG0x00
22+
23+
/*
24+
* The "special area" of a sequence's buffer page looks like this.
25+
*/
26+
#defineSEQ_MAGIC0x1717
27+
28+
typedefstructsequence_magic
29+
{
30+
uint32magic;
31+
}sequence_magic;
32+
33+
/* Sequence WAL record */
34+
typedefstructxl_seq_rec
35+
{
36+
RelFileLocatorlocator;
37+
/* SEQUENCE TUPLE DATA FOLLOWS AT THE END */
38+
}xl_seq_rec;
39+
40+
externvoidseq_redo(XLogReaderState*record);
41+
externvoidseq_desc(StringInfobuf,XLogReaderState*record);
42+
externconstchar*seq_identify(uint8info);
43+
externvoidseq_mask(char*page,BlockNumberblkno);
44+
45+
#endif/* SEQUENCE_XLOG_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp