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

Commitdf10f7c

Browse files
Oleg Gurevfunny-falcon
Oleg Gurev
authored andcommitted
[PGPRO-10166] Set ptrack init_lsn before first transaction to switched xlog segment
- Because of vanilla commit:- "During online checkpoints, insert XLOG_CHECKPOINT_REDO at redo point."- Ptrack in some cases got init_lsn right after this xlog record- New hook will set init_lsn before insernig checkpoint record
1 parent82b1f80 commitdf10f7c

File tree

4 files changed

+88
-21
lines changed

4 files changed

+88
-21
lines changed

‎engine.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,21 @@ ptrack_mark_block(RelFileNodeBackend smgr_rnode,
643643
slots[0]= (size_t)(hash %PtrackContentNblocks);
644644
slots[1]= (size_t)(((hash <<32) | (hash >>32)) %PtrackContentNblocks);
645645

646+
new_lsn=ptrack_set_init_lsn();
647+
648+
/* Atomically assign new LSN value to the slots */
649+
for (i=0;i<lengthof(slots);i++)
650+
{
651+
#ifUSE_ASSERT_CHECKING
652+
elog(DEBUG3,"ptrack_mark_block: map[%zu]",slots[i]);
653+
#endif
654+
ptrack_atomic_increase(new_lsn,&ptrack_map->entries[slots[i]]);
655+
}
656+
}
657+
658+
externXLogRecPtrptrack_set_init_lsn(void)
659+
{
660+
XLogRecPtrnew_lsn;
646661
if (RecoveryInProgress())
647662
new_lsn=GetXLogReplayRecPtr(NULL);
648663
else
@@ -652,17 +667,9 @@ ptrack_mark_block(RelFileNodeBackend smgr_rnode,
652667
if (pg_atomic_read_u64(&ptrack_map->init_lsn)==InvalidXLogRecPtr)
653668
{
654669
#ifUSE_ASSERT_CHECKING
655-
elog(DEBUG3,"ptrack_mark_block: init_lsn");
670+
elog(DEBUG3,"ptrack_set_init_lsn: init_lsn");
656671
#endif
657672
ptrack_atomic_increase(new_lsn,&ptrack_map->init_lsn);
658673
}
659-
660-
/* Atomically assign new LSN value to the slots */
661-
for (i=0;i<lengthof(slots);i++)
662-
{
663-
#ifUSE_ASSERT_CHECKING
664-
elog(DEBUG3,"ptrack_mark_block: map[%zu]",slots[i]);
665-
#endif
666-
ptrack_atomic_increase(new_lsn,&ptrack_map->entries[slots[i]]);
667-
}
674+
returnnew_lsn;
668675
}

‎engine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ extern intptrack_map_size_tmp;
104104
externvoidptrackCheckpoint(void);
105105
externvoidptrackMapInit(void);
106106
externvoidptrackCleanFiles(void);
107+
externXLogRecPtrptrack_set_init_lsn(void);
107108

108109
externvoidassign_ptrack_map_size(intnewval,void*extra);
109110

‎patches/master-ptrack-core.diff

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
1+
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
2+
index 34a2c71812..2d73d8023e 100644
3+
--- a/src/backend/access/transam/xlog.c
4+
+++ b/src/backend/access/transam/xlog.c
5+
@@ -135,6 +135,7 @@ intwal_retrieve_retry_interval = 5000;
6+
intmax_slot_wal_keep_size_mb = -1;
7+
intwal_decode_buffer_size = 512 * 1024;
8+
booltrack_wal_io_timing = false;
9+
+backup_checkpoint_request_hook_type backup_checkpoint_request_hook = NULL;
10+
11+
#ifdef WAL_DEBUG
12+
boolXLOG_DEBUG = false;
13+
@@ -8801,6 +8802,12 @@ do_pg_backup_start(const char *backupidstr, bool fast, List **tablespaces,
14+
{
15+
boolcheckpointfpw;
16+
17+
+/*
18+
+ * Before we call RequestCheckpoint() we need to set
19+
+ * init_lsn for ptrack map
20+
+ */
21+
+if (backup_checkpoint_request_hook)
22+
+backup_checkpoint_request_hook();
23+
/*
24+
* Force a CHECKPOINT. Aside from being necessary to prevent torn
25+
* page problems, this guarantees that two successive backup runs
126
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
2-
index5fbbe5ffd20..3c9b99f851d 100644
27+
index9a2bf59e84..ade9115651 100644
328
--- a/src/backend/backup/basebackup.c
429
+++ b/src/backend/backup/basebackup.c
530
@@ -220,6 +220,13 @@ static const struct exclude_list_item excludeFiles[] =
@@ -17,7 +42,7 @@ index 5fbbe5ffd20..3c9b99f851d 100644
1742
{NULL, false}
1843
};
1944
diff --git a/src/backend/storage/file/copydir.c b/src/backend/storage/file/copydir.c
20-
indexd4fbe542077..b108416c708 100644
45+
indexd4fbe54207..b108416c70 100644
2146
--- a/src/backend/storage/file/copydir.c
2247
+++ b/src/backend/storage/file/copydir.c
2348
@@ -27,6 +27,8 @@
@@ -40,7 +65,7 @@ index d4fbe542077..b108416c708 100644
4065
* Be paranoid here and fsync all files to ensure the copy is really done.
4166
* But if fsync is disabled, we're done.
4267
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
43-
indexbf0f3ca76d1..7d9833a3604 100644
68+
indexbf0f3ca76d..7d9833a360 100644
4469
--- a/src/backend/storage/smgr/md.c
4570
+++ b/src/backend/storage/smgr/md.c
4671
@@ -85,6 +85,8 @@ typedef struct _MdfdVec
@@ -92,7 +117,7 @@ index bf0f3ca76d1..7d9833a3604 100644
92117
}
93118

94119
diff --git a/src/backend/storage/sync/sync.c b/src/backend/storage/sync/sync.c
95-
indexab7137d0fff..bc40a763c05 100644
120+
indexab7137d0ff..bc40a763c0 100644
96121
--- a/src/backend/storage/sync/sync.c
97122
+++ b/src/backend/storage/sync/sync.c
98123
@@ -74,6 +74,8 @@ static MemoryContext pendingOpsCxt; /* context for the above */
@@ -115,7 +140,7 @@ index ab7137d0fff..bc40a763c05 100644
115140
sync_in_progress = false;
116141
}
117142
diff --git a/src/bin/pg_checksums/pg_checksums.c b/src/bin/pg_checksums/pg_checksums.c
118-
index9e6fd435f60..f2180b9f6de 100644
143+
index9e6fd435f6..f2180b9f6d 100644
119144
--- a/src/bin/pg_checksums/pg_checksums.c
120145
+++ b/src/bin/pg_checksums/pg_checksums.c
121146
@@ -110,6 +110,11 @@ static const struct exclude_list_item skip[] = {
@@ -131,7 +156,7 @@ index 9e6fd435f60..f2180b9f6de 100644
131156
{"config_exec_params", true},
132157
#endif
133158
diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c
134-
indexe9dcb5a6d89..844b04d5e12 100644
159+
indexe9dcb5a6d8..844b04d5e1 100644
135160
--- a/src/bin/pg_resetwal/pg_resetwal.c
136161
+++ b/src/bin/pg_resetwal/pg_resetwal.c
137162
@@ -86,6 +86,7 @@ static void FindEndOfXLOG(void);
@@ -193,10 +218,10 @@ index e9dcb5a6d89..844b04d5e12 100644
193218
/*
194219
* Remove existing archive status files
195220
diff --git a/src/bin/pg_rewind/filemap.c b/src/bin/pg_rewind/filemap.c
196-
index255ddf2ffaf..1142c244926 100644
221+
index4458324c9d..7d857467f7 100644
197222
--- a/src/bin/pg_rewind/filemap.c
198223
+++ b/src/bin/pg_rewind/filemap.c
199-
@@ -157,6 +157,10 @@ static const struct exclude_list_item excludeFiles[] =
224+
@@ -156,6 +156,10 @@ static const struct exclude_list_item excludeFiles[] =
200225
{"postmaster.pid", false},
201226
{"postmaster.opts", false},
202227

@@ -207,8 +232,22 @@ index 255ddf2ffaf..1142c244926 100644
207232
/* end of list */
208233
{NULL, false}
209234
};
235+
diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h
236+
index 76787a8267..2c662f4022 100644
237+
--- a/src/include/access/xlog.h
238+
+++ b/src/include/access/xlog.h
239+
@@ -57,6 +57,9 @@ extern PGDLLIMPORT int wal_decode_buffer_size;
240+
241+
extern PGDLLIMPORT int CheckPointSegments;
242+
243+
+typedef void (*backup_checkpoint_request_hook_type) (void);
244+
+extern PGDLLIMPORT backup_checkpoint_request_hook_type backup_checkpoint_request_hook;
245+
+
246+
/* Archive modes */
247+
typedef enum ArchiveMode
248+
{
210249
diff --git a/src/include/storage/copydir.h b/src/include/storage/copydir.h
211-
indexa25e258f479..b20b9c76e8d 100644
250+
indexa25e258f47..b20b9c76e8 100644
212251
--- a/src/include/storage/copydir.h
213252
+++ b/src/include/storage/copydir.h
214253
@@ -13,6 +13,9 @@
@@ -222,7 +261,7 @@ index a25e258f479..b20b9c76e8d 100644
222261
extern void copy_file(const char *fromfile, const char *tofile);
223262

224263
diff --git a/src/include/storage/md.h b/src/include/storage/md.h
225-
index620f10abdeb..b36936871bd 100644
264+
index620f10abde..b36936871b 100644
226265
--- a/src/include/storage/md.h
227266
+++ b/src/include/storage/md.h
228267
@@ -19,6 +19,13 @@
@@ -240,7 +279,7 @@ index 620f10abdeb..b36936871bd 100644
240279
extern void mdinit(void);
241280
extern void mdopen(SMgrRelation reln);
242281
diff --git a/src/include/storage/sync.h b/src/include/storage/sync.h
243-
index9dee8fa6e5b..348ed53e4e2 100644
282+
index9dee8fa6e5..348ed53e4e 100644
244283
--- a/src/include/storage/sync.h
245284
+++ b/src/include/storage/sync.h
246285
@@ -55,6 +55,9 @@ typedef struct FileTag

‎ptrack.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ static copydir_hook_type prev_copydir_hook = NULL;
6464
staticmdwrite_hook_typeprev_mdwrite_hook=NULL;
6565
staticmdextend_hook_typeprev_mdextend_hook=NULL;
6666
staticProcessSyncRequests_hook_typeprev_ProcessSyncRequests_hook=NULL;
67+
#ifPG_VERSION_NUM >=170000
68+
staticbackup_checkpoint_request_hook_typeprev_backup_checkpoint_request_hook=NULL;
69+
#endif
6770

6871
void_PG_init(void);
6972

@@ -74,6 +77,9 @@ static void ptrack_mdwrite_hook(RelFileNodeBackend smgr_rnode,
7477
staticvoidptrack_mdextend_hook(RelFileNodeBackendsmgr_rnode,
7578
ForkNumberforkno,BlockNumberblkno);
7679
staticvoidptrack_ProcessSyncRequests_hook(void);
80+
#ifPG_VERSION_NUM >=170000
81+
staticvoidptrack_backup_checkpoint_request_hook(void);
82+
#endif
7783

7884
staticvoidptrack_gather_filelist(List**filelist,char*path,OidspcOid,OiddbOid);
7985
staticintptrack_filelist_getnext(PtScanCtx*ctx);
@@ -141,6 +147,10 @@ _PG_init(void)
141147
mdextend_hook=ptrack_mdextend_hook;
142148
prev_ProcessSyncRequests_hook=ProcessSyncRequests_hook;
143149
ProcessSyncRequests_hook=ptrack_ProcessSyncRequests_hook;
150+
#ifPG_VERSION_NUM >=170000
151+
prev_backup_checkpoint_request_hook=backup_checkpoint_request_hook;
152+
backup_checkpoint_request_hook=ptrack_backup_checkpoint_request_hook;
153+
#endif
144154
}
145155

146156
#ifPG_VERSION_NUM >=150000
@@ -267,6 +277,16 @@ ptrack_ProcessSyncRequests_hook()
267277
prev_ProcessSyncRequests_hook();
268278
}
269279

280+
#ifPG_VERSION_NUM >=170000
281+
staticvoid
282+
ptrack_backup_checkpoint_request_hook(void)
283+
{
284+
ptrack_set_init_lsn();
285+
286+
if (prev_backup_checkpoint_request_hook)
287+
prev_backup_checkpoint_request_hook();
288+
}
289+
#endif
270290
/*
271291
* Recursively walk through the path and add all data files to filelist.
272292
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp