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

Commitc668dc8

Browse files
author
Oleg Gurev
committed
Backport from ee ptrack_atomic_increase() function
- refactor of ptrack_mark_block()
1 parent0659512 commitc668dc8

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

‎engine.c

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,23 @@ ptrack_walkdir(const char *path, Oid tablespaceOid, Oid dbOid)
599599
FreeDir(dir);/* we ignore any error here */
600600
}
601601

602+
staticvoid
603+
ptrack_atomic_increase(XLogRecPtrnew_lsn,pg_atomic_uint64*var)
604+
{
605+
/*
606+
* We use pg_atomic_uint64 here only for alignment purposes, because
607+
* pg_atomic_uint64 is forcedly aligned on 8 bytes during the MSVC build.
608+
*/
609+
pg_atomic_uint64old_lsn;
610+
611+
old_lsn.value=pg_atomic_read_u64(var);
612+
#ifUSE_ASSERT_CHECKING
613+
elog(DEBUG3,"ptrack_mark_block: "UINT64_FORMAT" <- "UINT64_FORMAT,old_lsn.value,new_lsn);
614+
#endif
615+
while (old_lsn.value<new_lsn&&
616+
!pg_atomic_compare_exchange_u64(var, (uint64*)&old_lsn.value,new_lsn));
617+
}
618+
602619
/*
603620
* Mark modified block in ptrack_map.
604621
*/
@@ -608,15 +625,9 @@ ptrack_mark_block(RelFileNodeBackend smgr_rnode,
608625
{
609626
PtBlockIdbid;
610627
uint64hash;
611-
size_tslot1;
612-
size_tslot2;
628+
size_tslots[2];
613629
XLogRecPtrnew_lsn;
614-
/*
615-
* We use pg_atomic_uint64 here only for alignment purposes, because
616-
* pg_atomic_uint64 is forcedly aligned on 8 bytes during the MSVC build.
617-
*/
618-
pg_atomic_uint64old_lsn;
619-
pg_atomic_uint64old_init_lsn;
630+
inti;
620631

621632
if (ptrack_map_size==0
622633
||ptrack_map==NULL
@@ -629,39 +640,29 @@ ptrack_mark_block(RelFileNodeBackend smgr_rnode,
629640
bid.blocknum=blocknum;
630641

631642
hash=BID_HASH_FUNC(bid);
632-
slot1= (size_t)(hash %PtrackContentNblocks);
633-
slot2= (size_t)(((hash <<32) | (hash >>32)) %PtrackContentNblocks);
643+
slots[0]= (size_t)(hash %PtrackContentNblocks);
644+
slots[1]= (size_t)(((hash <<32) | (hash >>32)) %PtrackContentNblocks);
634645

635646
if (RecoveryInProgress())
636647
new_lsn=GetXLogReplayRecPtr(NULL);
637648
else
638649
new_lsn=GetXLogInsertRecPtr();
639650

640651
/* Atomically assign new init LSN value */
641-
old_init_lsn.value=pg_atomic_read_u64(&ptrack_map->init_lsn);
642-
if (old_init_lsn.value==InvalidXLogRecPtr)
652+
if (pg_atomic_read_u64(&ptrack_map->init_lsn)==InvalidXLogRecPtr)
643653
{
644654
#ifUSE_ASSERT_CHECKING
645-
elog(DEBUG1,"ptrack_mark_block: init_lsn "UINT64_FORMAT" <- "UINT64_FORMAT,old_init_lsn.value,new_lsn);
655+
elog(DEBUG3,"ptrack_mark_block: init_lsn");
646656
#endif
647-
648-
while (old_init_lsn.value<new_lsn&&
649-
!pg_atomic_compare_exchange_u64(&ptrack_map->init_lsn, (uint64*)&old_init_lsn.value,new_lsn));
657+
ptrack_atomic_increase(new_lsn,&ptrack_map->init_lsn);
650658
}
651659

652-
/* Atomically assign new LSN value to the first slot */
653-
old_lsn.value=pg_atomic_read_u64(&ptrack_map->entries[slot1]);
654-
#ifUSE_ASSERT_CHECKING
655-
elog(DEBUG3,"ptrack_mark_block: map[%zu]="UINT64_FORMAT" <- "UINT64_FORMAT,slot1,old_lsn.value,new_lsn);
656-
#endif
657-
while (old_lsn.value<new_lsn&&
658-
!pg_atomic_compare_exchange_u64(&ptrack_map->entries[slot1], (uint64*)&old_lsn.value,new_lsn));
659-
660-
/* And to the second */
661-
old_lsn.value=pg_atomic_read_u64(&ptrack_map->entries[slot2]);
660+
/* Atomically assign new LSN value to the slots */
661+
for (i=0;i<lengthof(slots);i++)
662+
{
662663
#ifUSE_ASSERT_CHECKING
663-
elog(DEBUG3,"ptrack_mark_block: map[%zu]="UINT64_FORMAT" <- "UINT64_FORMAT,slot2,old_lsn.value,new_lsn);
664+
elog(DEBUG3,"ptrack_mark_block: map[%zu]",slots[i]);
664665
#endif
665-
while (old_lsn.value<new_lsn&&
666-
!pg_atomic_compare_exchange_u64(&ptrack_map->entries[slot2], (uint64*)&old_lsn.value,new_lsn));
666+
ptrack_atomic_increase(new_lsn,&ptrack_map->entries[slots[i]]);
667+
}
667668
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp