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

Commit5035701

Browse files
committed
Improve generation algorithm for database system identifier.
As noted some time ago, the original coding had a typo ("|" for "^")that made the result less unique than intended. Even the intendedbehavior is obsolete since it was based on wanting to produce ausable value even if we didn't have int64 arithmetic --- a limitationwe stopped supporting years ago. Instead, let's redefine the systemidentifier as tv_sec in the upper 32 bits (same as before), tv_usecin the next 20 bits, and the low 12 bits of getpid() in the remainingbits. This is still hardly guaranteed-universally-unique, but it'snoticeably better than before. Per my proposal at<29019.1374535940@sss.pgh.pa.us>
1 parent528c454 commit5035701

File tree

1 file changed

+7
-6
lines changed
  • src/backend/access/transam

1 file changed

+7
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4889,15 +4889,16 @@ BootStrapXLOG(void)
48894889
* field, as being about as unique as we can easily get. (Think not to
48904890
* use random(), since it hasn't been seeded and there's no portable way
48914891
* to seed it other than the system clock value...) The upper half of the
4892-
* uint64 value is just the tv_sec part, while the lower halfis the XOR
4893-
*of tv_sec and tv_usec. This is to ensure that we don't lose uniqueness
4894-
*unnecessarily if "uint64" is really only 32 bits wide. A person
4895-
*knowing this encoding candetermine the initialization time of the
4896-
*installation, which couldperhaps be useful sometimes.
4892+
* uint64 value is just the tv_sec part, while the lower halfcontains the
4893+
*tv_usec part (which must fit in 20 bits), plus 12 bits from our current
4894+
*PID for a little extra uniqueness. A person knowing this encoding can
4895+
* determine the initialization time of the installation, which could
4896+
* perhaps be useful sometimes.
48974897
*/
48984898
gettimeofday(&tv,NULL);
48994899
sysidentifier= ((uint64)tv.tv_sec) <<32;
4900-
sysidentifier |= (uint32) (tv.tv_sec |tv.tv_usec);
4900+
sysidentifier |= ((uint64)tv.tv_usec) <<12;
4901+
sysidentifier |=getpid()&0xFFF;
49014902

49024903
/* First timeline ID is always 1 */
49034904
ThisTimeLineID=1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp