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

Commit309b2cf

Browse files
committed
Have GetCurrentTransactionStopTimestamp() set xactStopTimestamp if unset
Previously GetCurrentTransactionStopTimestamp() computed a new timestampwhenever xactStopTimestamp was unset and xactStopTimestamp was only set when acommit or abort record was written.An upcoming patch will add additional calls toGetCurrentTransactionStopTimestamp() from pgstats. To avoid computingtimestamps multiple times, set xactStopTimestamp inGetCurrentTransactionStopTimestamp() if not already set.Author: Dave Page <dpage@pgadmin.org>Reviewed-by: Andres Freund <andres@anarazel.de>Reviewed-by: Vik Fearing <vik@postgresfriends.org>Discussion:https://postgr.es/m/20220906155325.an3xesq5o3fq36gt%40awork3.anarazel.de
1 parentdb1b931 commit309b2cf

File tree

1 file changed

+21
-21
lines changed
  • src/backend/access/transam

1 file changed

+21
-21
lines changed

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ static bool currentCommandIdUsed;
263263
/*
264264
* xactStartTimestamp is the value of transaction_timestamp().
265265
* stmtStartTimestamp is the value of statement_timestamp().
266-
* xactStopTimestamp is the time at which we log a commit or abort WAL record.
266+
* xactStopTimestamp is the time at which we log a commit / abort WAL record,
267+
* or if that was skipped, the time of the first subsequent
268+
* GetCurrentTransactionStopTimestamp() call.
269+
*
267270
* These do not change as we enter and exit subtransactions, so we don't
268271
* keep them inside the TransactionState stack.
269272
*/
@@ -865,15 +868,24 @@ GetCurrentStatementStartTimestamp(void)
865868
/*
866869
*GetCurrentTransactionStopTimestamp
867870
*
868-
*We return current time ifthe transaction stop time hasn't been set
869-
*(which can happen ifwedecide we don't need to log an XLOG record).
871+
*Ifthe transaction stop time hasn'talreadybeen set, which can happen if
872+
* wedecided we don't need to log an XLOG record, set xactStopTimestamp.
870873
*/
871874
TimestampTz
872875
GetCurrentTransactionStopTimestamp(void)
873876
{
874-
if (xactStopTimestamp!=0)
875-
returnxactStopTimestamp;
876-
returnGetCurrentTimestamp();
877+
TransactionStatesPG_USED_FOR_ASSERTS_ONLY=CurrentTransactionState;
878+
879+
/* should only be called after commit / abort processing */
880+
Assert(s->state==TRANS_DEFAULT||
881+
s->state==TRANS_COMMIT||
882+
s->state==TRANS_ABORT||
883+
s->state==TRANS_PREPARE);
884+
885+
if (xactStopTimestamp==0)
886+
xactStopTimestamp=GetCurrentTimestamp();
887+
888+
returnxactStopTimestamp;
877889
}
878890

879891
/*
@@ -891,15 +903,6 @@ SetCurrentStatementStartTimestamp(void)
891903
Assert(stmtStartTimestamp!=0);
892904
}
893905

894-
/*
895-
*SetCurrentTransactionStopTimestamp
896-
*/
897-
staticinlinevoid
898-
SetCurrentTransactionStopTimestamp(void)
899-
{
900-
xactStopTimestamp=GetCurrentTimestamp();
901-
}
902-
903906
/*
904907
*GetCurrentTransactionNestLevel
905908
*
@@ -1396,9 +1399,7 @@ RecordTransactionCommit(void)
13961399
START_CRIT_SECTION();
13971400
MyProc->delayChkptFlags |=DELAY_CHKPT_START;
13981401

1399-
SetCurrentTransactionStopTimestamp();
1400-
1401-
XactLogCommitRecord(xactStopTimestamp,
1402+
XactLogCommitRecord(GetCurrentTransactionStopTimestamp(),
14021403
nchildren,children,nrels,rels,
14031404
ndroppedstats,droppedstats,
14041405
nmsgs,invalMessages,
@@ -1422,7 +1423,7 @@ RecordTransactionCommit(void)
14221423
*/
14231424

14241425
if (!replorigin||replorigin_session_origin_timestamp==0)
1425-
replorigin_session_origin_timestamp=xactStopTimestamp;
1426+
replorigin_session_origin_timestamp=GetCurrentTransactionStopTimestamp();
14261427

14271428
TransactionTreeSetCommitTsData(xid,nchildren,children,
14281429
replorigin_session_origin_timestamp,
@@ -1754,8 +1755,7 @@ RecordTransactionAbort(bool isSubXact)
17541755
xact_time=GetCurrentTimestamp();
17551756
else
17561757
{
1757-
SetCurrentTransactionStopTimestamp();
1758-
xact_time=xactStopTimestamp;
1758+
xact_time=GetCurrentTransactionStopTimestamp();
17591759
}
17601760

17611761
XactLogAbortRecord(xact_time,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp