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

Commitc29aff9

Browse files
committed
Consistently declare timestamp variables as TimestampTz.
Twiddle the replication-related code so that its timestamp variablesare declared TimestampTz, rather than the uninformative "int64" thatwas previously used for meant-to-be-always-integer timestamps.This resolves the int64-vs-TimestampTz declaration inconsistenciesintroduced by commit7c03078, though in the opposite direction towhat was originally suggested.This required including datatype/timestamp.h in a couple more placesthan before. I decided it would be a good idea to slim down thatheader by not having it pull in <float.h> etc, as those headers areno longer at all relevant to its purpose. Unsurprisingly, a small numberof .c files turn out to have been depending on those inclusions, so addthem back in the .c files as needed.Discussion:https://postgr.es/m/26788.1487455319@sss.pgh.pa.usDiscussion:https://postgr.es/m/27694.1487456324@sss.pgh.pa.us
1 parentb9d092c commitc29aff9

File tree

22 files changed

+100
-94
lines changed

22 files changed

+100
-94
lines changed

‎contrib/auth_delay/auth_delay.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
*/
1212
#include"postgres.h"
1313

14+
#include<limits.h>
15+
1416
#include"libpq/auth.h"
1517
#include"port.h"
1618
#include"utils/guc.h"

‎contrib/btree_gist/btree_ts.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*/
44
#include"postgres.h"
55

6+
#include<limits.h>
7+
68
#include"btree_gist.h"
79
#include"btree_utils_num.h"
810
#include"utils/builtins.h"

‎src/backend/access/common/reloptions.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include"postgres.h"
1717

18+
#include<float.h>
19+
1820
#include"access/gist_private.h"
1921
#include"access/hash.h"
2022
#include"access/htup_details.h"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include"postgres.h"
1616

1717
#include<ctype.h>
18+
#include<math.h>
1819
#include<time.h>
1920
#include<fcntl.h>
2021
#include<sys/stat.h>

‎src/backend/commands/prepare.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
#include"postgres.h"
1818

19+
#include<limits.h>
20+
1921
#include"access/xact.h"
2022
#include"catalog/pg_type.h"
2123
#include"commands/createas.h"

‎src/backend/executor/nodeBitmapHeapscan.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
*/
3636
#include"postgres.h"
3737

38+
#include<math.h>
39+
3840
#include"access/relscan.h"
3941
#include"access/transam.h"
4042
#include"executor/execdebug.h"

‎src/backend/replication/basebackup.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ static uint64 throttling_sample;
9292
staticint64throttling_counter;
9393

9494
/* The minimum time required to transfer throttling_sample bytes. */
95-
staticint64elapsed_min_unit;
95+
staticTimeOffsetelapsed_min_unit;
9696

9797
/* The last check of the transfer rate. */
98-
staticint64throttled_last;
98+
staticTimestampTzthrottled_last;
9999

100100
/*
101101
* The contents of these directories are removed or recreated during server
@@ -254,7 +254,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
254254
throttling_counter=0;
255255

256256
/* The 'real data' starts now (header was ignored). */
257-
throttled_last=GetCurrentIntegerTimestamp();
257+
throttled_last=GetCurrentTimestamp();
258258
}
259259
else
260260
{
@@ -1333,7 +1333,7 @@ _tarWriteDir(const char *pathbuf, int basepathlen, struct stat *statbuf,
13331333
staticvoid
13341334
throttle(size_tincrement)
13351335
{
1336-
int64elapsed,
1336+
TimeOffsetelapsed,
13371337
elapsed_min,
13381338
sleep;
13391339
intwait_result;
@@ -1346,7 +1346,7 @@ throttle(size_t increment)
13461346
return;
13471347

13481348
/* Time elapsed since the last measurement (and possible wake up). */
1349-
elapsed=GetCurrentIntegerTimestamp()-throttled_last;
1349+
elapsed=GetCurrentTimestamp()-throttled_last;
13501350
/* How much should have elapsed at minimum? */
13511351
elapsed_min=elapsed_min_unit* (throttling_counter /throttling_sample);
13521352
sleep=elapsed_min-elapsed;
@@ -1381,5 +1381,5 @@ throttle(size_t increment)
13811381
* Time interval for the remaining amount and possible next increments
13821382
* starts now.
13831383
*/
1384-
throttled_last=GetCurrentIntegerTimestamp();
1384+
throttled_last=GetCurrentTimestamp();
13851385
}

‎src/backend/replication/logical/worker.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -981,12 +981,11 @@ ApplyLoop(void)
981981
{
982982
XLogRecPtrstart_lsn;
983983
XLogRecPtrend_lsn;
984-
TimestampTzsend_time;
984+
TimestampTzsend_time;
985985

986986
start_lsn=pq_getmsgint64(&s);
987987
end_lsn=pq_getmsgint64(&s);
988-
send_time=
989-
IntegerTimestampToTimestampTz(pq_getmsgint64(&s));
988+
send_time=pq_getmsgint64(&s);
990989

991990
if (last_received<start_lsn)
992991
last_received=start_lsn;
@@ -1000,13 +999,12 @@ ApplyLoop(void)
1000999
}
10011000
elseif (c=='k')
10021001
{
1003-
XLogRecPtrendpos;
1004-
TimestampTztimestamp;
1005-
boolreply_requested;
1002+
XLogRecPtrendpos;
1003+
TimestampTztimestamp;
1004+
boolreply_requested;
10061005

10071006
endpos=pq_getmsgint64(&s);
1008-
timestamp=
1009-
IntegerTimestampToTimestampTz(pq_getmsgint64(&s));
1007+
timestamp=pq_getmsgint64(&s);
10101008
reply_requested=pq_getmsgbyte(&s);
10111009

10121010
send_feedback(endpos,reply_requested, false);

‎src/backend/replication/walreceiver.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -892,8 +892,7 @@ XLogWalRcvProcessMsg(unsigned char type, char *buf, Size len)
892892
/* read the fields */
893893
dataStart=pq_getmsgint64(&incoming_message);
894894
walEnd=pq_getmsgint64(&incoming_message);
895-
sendTime=IntegerTimestampToTimestampTz(
896-
pq_getmsgint64(&incoming_message));
895+
sendTime=pq_getmsgint64(&incoming_message);
897896
ProcessWalSndrMessage(walEnd,sendTime);
898897

899898
buf+=hdrlen;
@@ -913,8 +912,7 @@ XLogWalRcvProcessMsg(unsigned char type, char *buf, Size len)
913912

914913
/* read the fields */
915914
walEnd=pq_getmsgint64(&incoming_message);
916-
sendTime=IntegerTimestampToTimestampTz(
917-
pq_getmsgint64(&incoming_message));
915+
sendTime=pq_getmsgint64(&incoming_message);
918916
replyRequested=pq_getmsgbyte(&incoming_message);
919917

920918
ProcessWalSndrMessage(walEnd,sendTime);
@@ -1149,7 +1147,7 @@ XLogWalRcvSendReply(bool force, bool requestReply)
11491147
pq_sendint64(&reply_message,writePtr);
11501148
pq_sendint64(&reply_message,flushPtr);
11511149
pq_sendint64(&reply_message,applyPtr);
1152-
pq_sendint64(&reply_message,GetCurrentIntegerTimestamp());
1150+
pq_sendint64(&reply_message,GetCurrentTimestamp());
11531151
pq_sendbyte(&reply_message,requestReply ?1 :0);
11541152

11551153
/* Send it */
@@ -1241,7 +1239,7 @@ XLogWalRcvSendHSFeedback(bool immed)
12411239
/* Construct the message and send it. */
12421240
resetStringInfo(&reply_message);
12431241
pq_sendbyte(&reply_message,'h');
1244-
pq_sendint64(&reply_message,GetCurrentIntegerTimestamp());
1242+
pq_sendint64(&reply_message,GetCurrentTimestamp());
12451243
pq_sendint(&reply_message,xmin,4);
12461244
pq_sendint(&reply_message,nextEpoch,4);
12471245
walrcv_send(wrconn,reply_message.data,reply_message.len);

‎src/backend/replication/walsender.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -823,12 +823,13 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
823823
dest=CreateDestReceiver(DestRemoteSimple);
824824
MemSet(nulls, false,sizeof(nulls));
825825

826-
/*
826+
/*----------
827827
* Need a tuple descriptor representing four columns:
828828
* - first field: the slot name
829829
* - second field: LSN at which we became consistent
830830
* - third field: exported snapshot's name
831831
* - fourth field: output plugin
832+
*----------
832833
*/
833834
tupdesc=CreateTemplateTupleDesc(4, false);
834835
TupleDescInitBuiltinEntry(tupdesc, (AttrNumber)1,"slot_name",
@@ -1014,7 +1015,7 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
10141015
* several releases by streaming physical replication.
10151016
*/
10161017
resetStringInfo(&tmpbuf);
1017-
pq_sendint64(&tmpbuf,GetCurrentIntegerTimestamp());
1018+
pq_sendint64(&tmpbuf,GetCurrentTimestamp());
10181019
memcpy(&ctx->out->data[1+sizeof(int64)+sizeof(int64)],
10191020
tmpbuf.data,sizeof(int64));
10201021

@@ -2334,7 +2335,7 @@ XLogSendPhysical(void)
23342335
* Fill the send timestamp last, so that it is taken as late as possible.
23352336
*/
23362337
resetStringInfo(&tmpbuf);
2337-
pq_sendint64(&tmpbuf,GetCurrentIntegerTimestamp());
2338+
pq_sendint64(&tmpbuf,GetCurrentTimestamp());
23382339
memcpy(&output_message.data[1+sizeof(int64)+sizeof(int64)],
23392340
tmpbuf.data,sizeof(int64));
23402341

@@ -2842,7 +2843,7 @@ WalSndKeepalive(bool requestReply)
28422843
resetStringInfo(&output_message);
28432844
pq_sendbyte(&output_message,'k');
28442845
pq_sendint64(&output_message,sentPtr);
2845-
pq_sendint64(&output_message,GetCurrentIntegerTimestamp());
2846+
pq_sendint64(&output_message,GetCurrentTimestamp());
28462847
pq_sendbyte(&output_message,requestReply ?1 :0);
28472848

28482849
/* ... and send it wrapped in CopyData */

‎src/backend/tcop/pquery.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include"postgres.h"
1717

18+
#include<limits.h>
19+
1820
#include"access/xact.h"
1921
#include"commands/prepare.h"
2022
#include"executor/tstoreReceiver.h"

‎src/backend/utils/adt/nabstime.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include<ctype.h>
2020
#include<float.h>
2121
#include<limits.h>
22+
#include<math.h>
2223
#include<time.h>
2324
#include<sys/time.h>
2425

‎src/backend/utils/cache/inval.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@
9595
*/
9696
#include"postgres.h"
9797

98+
#include<limits.h>
99+
98100
#include"access/htup_details.h"
99101
#include"access/xact.h"
100102
#include"catalog/catalog.h"

‎src/backend/utils/time/snapmgr.c

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ typedef struct OldSnapshotControlData
8383
* only allowed to move forward.
8484
*/
8585
slock_tmutex_current;/* protect current_timestamp */
86-
int64current_timestamp;/* latest snapshot timestamp */
86+
TimestampTzcurrent_timestamp;/* latest snapshot timestamp */
8787
slock_tmutex_latest_xmin;/* protect latest_xmin and
8888
* next_map_update */
8989
TransactionIdlatest_xmin;/* latest snapshot xmin */
90-
int64next_map_update;/* latest snapshot valid up to */
90+
TimestampTznext_map_update;/* latest snapshot valid up to */
9191
slock_tmutex_threshold;/* protect threshold fields */
92-
int64threshold_timestamp;/* earlier snapshot is old */
92+
TimestampTzthreshold_timestamp;/* earlier snapshot is old */
9393
TransactionIdthreshold_xid;/* earlier xid may be gone */
9494

9595
/*
@@ -121,7 +121,7 @@ typedef struct OldSnapshotControlData
121121
* Persistence is not needed.
122122
*/
123123
inthead_offset;/* subscript of oldest tracked time */
124-
int64head_timestamp;/* time corresponding to head xid */
124+
TimestampTzhead_timestamp;/* time corresponding to head xid */
125125
intcount_used;/* how many slots are in use */
126126
TransactionIdxid_by_minute[FLEXIBLE_ARRAY_MEMBER];
127127
}OldSnapshotControlData;
@@ -219,7 +219,7 @@ static Snapshot FirstXactSnapshot = NULL;
219219
staticList*exportedSnapshots=NIL;
220220

221221
/* Prototypes for local functions */
222-
staticint64AlignTimestampToMinuteBoundary(int64ts);
222+
staticTimestampTzAlignTimestampToMinuteBoundary(TimestampTzts);
223223
staticSnapshotCopySnapshot(Snapshotsnapshot);
224224
staticvoidFreeSnapshot(Snapshotsnapshot);
225225
staticvoidSnapshotResetXmin(void);
@@ -239,7 +239,7 @@ typedef struct SerializedSnapshotData
239239
boolsuboverflowed;
240240
booltakenDuringRecovery;
241241
CommandIdcurcid;
242-
int64whenTaken;
242+
TimestampTzwhenTaken;
243243
XLogRecPtrlsn;
244244
}SerializedSnapshotData;
245245

@@ -1611,26 +1611,29 @@ ThereAreNoPriorRegisteredSnapshots(void)
16111611

16121612

16131613
/*
1614-
* Returnan int64timestampwhich is exactly on a minute boundary.
1614+
* Returnatimestampthat is exactly on a minute boundary.
16151615
*
16161616
* If the argument is already aligned, return that value, otherwise move to
16171617
* the next minute boundary following the given time.
16181618
*/
1619-
staticint64
1620-
AlignTimestampToMinuteBoundary(int64ts)
1619+
staticTimestampTz
1620+
AlignTimestampToMinuteBoundary(TimestampTzts)
16211621
{
1622-
int64retval=ts+ (USECS_PER_MINUTE-1);
1622+
TimestampTzretval=ts+ (USECS_PER_MINUTE-1);
16231623

16241624
returnretval- (retval %USECS_PER_MINUTE);
16251625
}
16261626

16271627
/*
1628-
* Get current timestamp for snapshots as int64 that never moves backward.
1628+
* Get current timestamp for snapshots
1629+
*
1630+
* This is basically GetCurrentTimestamp(), but with a guarantee that
1631+
* the result never moves backward.
16291632
*/
1630-
int64
1633+
TimestampTz
16311634
GetSnapshotCurrentTimestamp(void)
16321635
{
1633-
int64now=GetCurrentIntegerTimestamp();
1636+
TimestampTznow=GetCurrentTimestamp();
16341637

16351638
/*
16361639
* Don't let time move backward; if it hasn't advanced, use the old value.
@@ -1652,10 +1655,10 @@ GetSnapshotCurrentTimestamp(void)
16521655
* XXX: So far, we never trust that a 64-bit value can be read atomically; if
16531656
* that ever changes, we could get rid of the spinlock here.
16541657
*/
1655-
int64
1658+
TimestampTz
16561659
GetOldSnapshotThresholdTimestamp(void)
16571660
{
1658-
int64threshold_timestamp;
1661+
TimestampTzthreshold_timestamp;
16591662

16601663
SpinLockAcquire(&oldSnapshotControl->mutex_threshold);
16611664
threshold_timestamp=oldSnapshotControl->threshold_timestamp;
@@ -1665,7 +1668,7 @@ GetOldSnapshotThresholdTimestamp(void)
16651668
}
16661669

16671670
staticvoid
1668-
SetOldSnapshotThresholdTimestamp(int64ts,TransactionIdxlimit)
1671+
SetOldSnapshotThresholdTimestamp(TimestampTzts,TransactionIdxlimit)
16691672
{
16701673
SpinLockAcquire(&oldSnapshotControl->mutex_threshold);
16711674
oldSnapshotControl->threshold_timestamp=ts;
@@ -1690,10 +1693,10 @@ TransactionIdLimitedForOldSnapshots(TransactionId recentXmin,
16901693
&&old_snapshot_threshold >=0
16911694
&&RelationAllowsEarlyPruning(relation))
16921695
{
1693-
int64ts=GetSnapshotCurrentTimestamp();
1696+
TimestampTzts=GetSnapshotCurrentTimestamp();
16941697
TransactionIdxlimit=recentXmin;
16951698
TransactionIdlatest_xmin;
1696-
int64update_ts;
1699+
TimestampTzupdate_ts;
16971700
boolsame_ts_as_threshold= false;
16981701

16991702
SpinLockAcquire(&oldSnapshotControl->mutex_latest_xmin);
@@ -1790,11 +1793,11 @@ TransactionIdLimitedForOldSnapshots(TransactionId recentXmin,
17901793
* Take care of the circular buffer that maps time to xid.
17911794
*/
17921795
void
1793-
MaintainOldSnapshotTimeMapping(int64whenTaken,TransactionIdxmin)
1796+
MaintainOldSnapshotTimeMapping(TimestampTzwhenTaken,TransactionIdxmin)
17941797
{
1795-
int64ts;
1798+
TimestampTzts;
17961799
TransactionIdlatest_xmin;
1797-
int64update_ts;
1800+
TimestampTzupdate_ts;
17981801
boolmap_update_required= false;
17991802

18001803
/* Never call this function when old snapshot checking is disabled. */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp