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

Commit37d9bba

Browse files
author
Daniel Shelepanov
committed
max lsn
1 parentf4c24d6 commit37d9bba

File tree

3 files changed

+83
-11
lines changed

3 files changed

+83
-11
lines changed

‎engine.c

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,34 @@ ptrack_walkdir(const char *path, Oid tablespaceOid, Oid dbOid)
675675
/*
676676
* Mark modified block in ptrack_map.
677677
*/
678+
staticvoidswap_slots(size_t*slot1,size_t*slot2) {
679+
*slot1 ^=*slot2;
680+
*slot2=*slot1 ^*slot2;
681+
*slot1=*slot1 ^*slot2;
682+
}
683+
684+
staticvoid
685+
ptrack_mark_map_pair(size_tslot1,size_tslot2,XLogRecPtrnew_lsn)
686+
{
687+
/*
688+
* We use pg_atomic_uint64 here only for alignment purposes, because
689+
* pg_atomic_uint64 is forcedly aligned on 8 bytes during the MSVC build.
690+
*/
691+
pg_atomic_uint64old_lsn;
692+
693+
/* Atomically assign new LSN value to the first slot */
694+
old_lsn.value=pg_atomic_read_u64(&ptrack_map->entries[slot1]);
695+
elog(DEBUG3,"ptrack_mark_block: map[%zu]="UINT64_FORMAT" <- "UINT64_FORMAT,slot1,old_lsn.value,new_lsn);
696+
while (old_lsn.value<new_lsn&&
697+
!pg_atomic_compare_exchange_u64(&ptrack_map->entries[slot1], (uint64*)&old_lsn.value,new_lsn));
698+
699+
/* And to the second */
700+
old_lsn.value=pg_atomic_read_u64(&ptrack_map->entries[slot2]);
701+
elog(DEBUG3,"ptrack_mark_block: map[%zu]="UINT64_FORMAT" <- "UINT64_FORMAT,slot2,old_lsn.value,new_lsn);
702+
while (old_lsn.value<new_lsn&&
703+
!pg_atomic_compare_exchange_u64(&ptrack_map->entries[slot2], (uint64*)&old_lsn.value,new_lsn));
704+
}
705+
678706
void
679707
ptrack_mark_block(RelFileNodeBackendsmgr_rnode,
680708
ForkNumberforknum,BlockNumberblocknum)
@@ -683,12 +711,13 @@ ptrack_mark_block(RelFileNodeBackend smgr_rnode,
683711
uint64hash;
684712
size_tslot1;
685713
size_tslot2;
714+
size_tmax_lsn_slot1;
715+
size_tmax_lsn_slot2;
686716
XLogRecPtrnew_lsn;
687717
/*
688718
* We use pg_atomic_uint64 here only for alignment purposes, because
689719
* pg_atomic_uint64 is forcedly aligned on 8 bytes during the MSVC build.
690720
*/
691-
pg_atomic_uint64old_lsn;
692721
pg_atomic_uint64old_init_lsn;
693722

694723
if (ptrack_map_size==0
@@ -705,6 +734,14 @@ ptrack_mark_block(RelFileNodeBackend smgr_rnode,
705734
slot1= (size_t)(hash %PtrackContentNblocks);
706735
slot2= (size_t)(((hash <<32) | (hash >>32)) %PtrackContentNblocks);
707736

737+
bid.blocknum=InvalidBlockNumber;
738+
hash=BID_HASH_FUNC(bid);
739+
max_lsn_slot1= (size_t)(hash %PtrackContentNblocks);
740+
max_lsn_slot2=max_lsn_slot1+1;
741+
742+
if (max_lsn_slot2<max_lsn_slot1)
743+
swap_slots(&max_lsn_slot1,&max_lsn_slot2);
744+
708745
if (RecoveryInProgress())
709746
new_lsn=GetXLogReplayRecPtr(NULL);
710747
else
@@ -720,15 +757,35 @@ ptrack_mark_block(RelFileNodeBackend smgr_rnode,
720757
!pg_atomic_compare_exchange_u64(&ptrack_map->init_lsn, (uint64*)&old_init_lsn.value,new_lsn));
721758
}
722759

723-
/* Atomically assign new LSN value tothefirst slot */
724-
old_lsn.value=pg_atomic_read_u64(&ptrack_map->entries[slot1]);
725-
elog(DEBUG3,"ptrack_mark_block: map[%zu]="UINT64_FORMAT" <- "UINT64_FORMAT,slot1,old_lsn.value,new_lsn);
726-
while (old_lsn.value<new_lsn&&
727-
!pg_atomic_compare_exchange_u64(&ptrack_map->entries[slot1], (uint64*)&old_lsn.value,new_lsn));
760+
// markthepage
761+
ptrack_mark_map_pair(slot1,slot2,new_lsn);
762+
// mark the file (new LSN is always valid maximum LSN)
763+
ptrack_mark_map_pair(max_lsn_slot1,max_lsn_slot2,new_lsn);
764+
}
728765

729-
/* And to the second */
730-
old_lsn.value=pg_atomic_read_u64(&ptrack_map->entries[slot2]);
731-
elog(DEBUG3,"ptrack_mark_block: map[%zu]="UINT64_FORMAT" <- "UINT64_FORMAT,slot2,old_lsn.value,new_lsn);
732-
while (old_lsn.value<new_lsn&&
733-
!pg_atomic_compare_exchange_u64(&ptrack_map->entries[slot2], (uint64*)&old_lsn.value,new_lsn));
766+
XLogRecPtrptrack_read_file_maxlsn(RelFileNodernode,ForkNumberforknum)
767+
{
768+
PtBlockIdbid;
769+
uint64hash;
770+
size_tslot1;
771+
size_tslot2;
772+
XLogRecPtrupdate_lsn1;
773+
XLogRecPtrupdate_lsn2;
774+
775+
bid.relnode=rnode;
776+
bid.forknum=forknum;
777+
bid.blocknum=InvalidBlockNumber;
778+
779+
hash=BID_HASH_FUNC(bid);
780+
781+
slot1= (size_t)(hash %PtrackContentNblocks);
782+
slot2=slot1+1;
783+
784+
if (slot2<slot1)
785+
swap_slots(&slot1,&slot2);
786+
787+
update_lsn1=pg_atomic_read_u64(&ptrack_map->entries[slot1]);
788+
update_lsn2=pg_atomic_read_u64(&ptrack_map->entries[slot2]);
789+
790+
returnupdate_lsn1==update_lsn2 ?update_lsn1 :InvalidXLogRecPtr;
734791
}

‎engine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ extern void assign_ptrack_map_size(int newval, void *extra);
115115
externvoidptrack_walkdir(constchar*path,OidtablespaceOid,OiddbOid);
116116
externvoidptrack_mark_block(RelFileNodeBackendsmgr_rnode,
117117
ForkNumberforkno,BlockNumberblkno);
118+
externXLogRecPtrptrack_read_file_maxlsn(RelFileNodesmgr_rnode,
119+
ForkNumberforknum);
118120

119121
externboolis_cfm_file_path(constchar*path);
120122
#ifdefPGPRO_EE

‎ptrack.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ ptrack_filelist_getnext(PtScanCtx * ctx)
410410
char*fullpath;
411411
structstatfst;
412412
off_trel_st_size=0;
413+
XLogRecPtrmaxlsn;
413414
#ifCFS_SUPPORT
414415
RelFileNodeBackendrnodebackend;
415416
#endif
@@ -461,6 +462,18 @@ ptrack_filelist_getnext(PtScanCtx * ctx)
461462
gotoget_next;
462463
}
463464

465+
maxlsn=ptrack_read_file_maxlsn(pfl->relnode,pfl->forknum);
466+
467+
if (maxlsn<ctx->lsn)
468+
{
469+
elog(DEBUG3,"ptrack: skip file %s: maxlsn is %X/%X, expected %X/%X",
470+
fullpath, (uint32) (maxlsn >>32), (uint32)maxlsn,
471+
(uint32) (ctx->lsn >>32), (uint32)ctx->lsn);
472+
473+
/* Try the next one */
474+
gotoget_next;
475+
}
476+
464477
#ifCFS_SUPPORT
465478
nodeOf(rnodebackend)=ctx->bid.relnode;
466479
rnodebackend.backend=InvalidBackendId;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp