Skip to content

Commit 41d0c92

Browse files
committed
Merge branch 'CORE-470-test_64_xid' into PGPROEE9_6
2 parents be2e7a7 + be38995 commit 41d0c92

File tree

6 files changed

+64
-29
lines changed

6 files changed

+64
-29
lines changed

doc/src/sgml/ref/initdb.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ doc/src/sgml/ref/initdb.sgml
378378
<term><option>--multixact-id=<replaceable class="parameter">START_MX_ID</replaceable></option></term>
379379
<listitem>
380380
<para>
381-
Specifies a start multixact id value in the hex format for new db instance to test 64-bit xids,
381+
Specifies a start multixact id value in the decimal format for new db instance to test 64-bit xids,
382382
default value is <literal>0</literal>.
383383
</para>
384384
</listitem>
@@ -400,7 +400,7 @@ doc/src/sgml/ref/initdb.sgml
400400
<term><option>--xid=<replaceable class="parameter">START_XID</replaceable></option></term>
401401
<listitem>
402402
<para>
403-
Specifies a start xid value in the hex format for new db instance to test 64-bit xids,
403+
Specifies a start xid value in the decimal for new db instance to test 64-bit xids,
404404
default value is <literal>0</literal>.
405405
</para>
406406
</listitem>

src/backend/bootstrap/bootstrap.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -250,28 +250,28 @@ AuxiliaryProcessMain(int argc, char *argv[])
250250
bootstrap_data_checksum_version = PG_DATA_CHECKSUM_VERSION;
251251
break;
252252
case 'm':
253-
if (sscanf(optarg, HEX_XID_FMT, &start_mx_id) != 1)
254-
{
255-
fprintf(stderr, "%s: invalid hex value of multixact-id\n", progname);
256-
exit(1);
257-
}
253+
if (sscanf(optarg, HEX_XID_FMT, &start_mx_id) != 1
254+
|| !StartMultiXactIdIsValid(start_mx_id))
255+
ereport(ERROR,
256+
(errcode(ERRCODE_SYNTAX_ERROR),
257+
errmsg("invalid start multixact id value")));
258258
break;
259259
case 'o':
260-
if (sscanf(optarg, XID_FMT, &start_mx_offset) != 1)
261-
{
262-
fprintf(stderr, "%s: invalid decimal value of multixact-offset\n", progname);
263-
exit(1);
264-
}
260+
if (sscanf(optarg, XID_FMT, &start_mx_offset) != 1
261+
|| !StartMultiXactOffsetIsValid(start_mx_offset))
262+
ereport(ERROR,
263+
(errcode(ERRCODE_SYNTAX_ERROR),
264+
errmsg("invalid start multixact offset value")));
265265
break;
266266
case 'r':
267267
strlcpy(OutputFileName, optarg, MAXPGPATH);
268268
break;
269269
case 'X':
270-
if (sscanf(optarg, HEX_XID_FMT, &start_xid) != 1)
271-
{
272-
fprintf(stderr, "%s: invalid hex value of xid\n", progname);
273-
exit(1);
274-
}
270+
if (sscanf(optarg, HEX_XID_FMT, &start_xid) != 1
271+
|| !StartTransactionIdIsValid(start_xid))
272+
ereport(ERROR,
273+
(errcode(ERRCODE_SYNTAX_ERROR),
274+
errmsg("invalid start xid value")));
275275
break;
276276
case 'x':
277277
MyAuxProcType = atoi(optarg);

src/bin/initdb/initdb.c

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,20 +2693,20 @@ usage(const char *progname)
26932693
printf(_(" -U, --username=NAME database superuser name\n"));
26942694
printf(_(" -W, --pwprompt prompt for a password for the new superuser\n"));
26952695
printf(_(" -X, --xlogdir=XLOGDIR location for the transaction log directory\n"));
2696-
printf(_(" -x, --xid=START_XID specify start xid value in hex format for new db instance to test 64-bit xids,\n"
2697-
" default value is 0\n"));
2696+
printf(_(" -x, --xid=START_XID specify start xid value in decimal format for new db instance to test 64-bit xids,\n"
2697+
" default value is 0, max value is 2^62-1\n"));
26982698
printf(_("\nLess commonly used options:\n"));
26992699
printf(_(" -d, --debug generate lots of debugging output\n"));
27002700
printf(_(" -k, --data-checksums use data page checksums\n"));
27012701
printf(_(" -L DIRECTORY where to find the input files\n"));
27022702
printf(_(" -m, --multixact-id=START_MX_ID\n"
2703-
" specify start multixact id value in hex format for new db instance\n"
2704-
" to test 64-bit xids, default value is 0\n"));
2703+
" specify start multixact id value in decimal format for new db instance\n"
2704+
" to test 64-bit xids, default value is 0, max value is 2^62-1\n"));
27052705
printf(_(" -n, --noclean do not clean up after errors\n"));
27062706
printf(_(" -N, --nosync do not wait for changes to be written safely to disk\n"));
27072707
printf(_(" -o, --multixact-offset=START_MX_OFFSET\n"
27082708
" specify start multixact offset value in decimal format for new db instance\n"
2709-
" to test 64-bit xids, default value is 0\n"));
2709+
" to test 64-bit xids, default value is 0, max value is 2^62-1\n"));
27102710
printf(_(" -s, --show show internal settings\n"));
27112711
printf(_(" -S, --sync-only only sync data directory\n"));
27122712
printf(_("\nOther options:\n"));
@@ -3469,9 +3469,16 @@ main(int argc, char *argv[])
34693469
printf(_("Running in debug mode.\n"));
34703470
break;
34713471
case 'm':
3472-
if (sscanf(optarg, HEX_XID_FMT, &start_mx_id) != 1)
3472+
if (sscanf(optarg, XID_FMT, &start_mx_id) != 1)
34733473
{
3474-
fprintf(stderr, "%s: invalid hex value of multixact-id\n", progname);
3474+
fprintf(stderr, "%s: invalid decimal START_MX_ID value\n",
3475+
progname);
3476+
exit(1);
3477+
}
3478+
if (!StartMultiXactIdIsValid(start_mx_id))
3479+
{
3480+
fprintf(stderr, "%s: out-of-range START_MX_ID value (the value must be less than 2^62)\n",
3481+
progname);
34753482
exit(1);
34763483
}
34773484
break;
@@ -3485,7 +3492,14 @@ main(int argc, char *argv[])
34853492
case 'o':
34863493
if (sscanf(optarg, XID_FMT, &start_mx_offset) != 1)
34873494
{
3488-
fprintf(stderr, "%s: invalid decimal value of multixact-offset\n", progname);
3495+
fprintf(stderr, "%s: invalid decimal START_MX_OFFSET value\n",
3496+
progname);
3497+
exit(1);
3498+
}
3499+
if (!StartMultiXactOffsetIsValid(start_mx_offset))
3500+
{
3501+
fprintf(stderr, "%s: out-of-range START_MX_OFFSET value (the value must be less than 2^62)\n",
3502+
progname);
34893503
exit(1);
34903504
}
34913505
break;
@@ -3535,9 +3549,16 @@ main(int argc, char *argv[])
35353549
xlog_dir = pg_strdup(optarg);
35363550
break;
35373551
case 'x':
3538-
if (sscanf(optarg, HEX_XID_FMT, &start_xid) != 1)
3552+
if (sscanf(optarg, XID_FMT, &start_xid) != 1)
3553+
{
3554+
fprintf(stderr, "%s: invalid decimal START_XID value\n",
3555+
progname);
3556+
exit(1);
3557+
}
3558+
if (!StartTransactionIdIsValid(start_xid))
35393559
{
3540-
fprintf(stderr, "%s: invalid hex value of xid\n", progname);
3560+
fprintf(stderr, "%s: out-of-range START_XID value (the value must be less than 2^62)\n",
3561+
progname);
35413562
exit(1);
35423563
}
35433564
break;

src/include/c.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,17 @@ typedef double float8;
390390
typedef Oid regproc;
391391
typedef regproc RegProcedure;
392392

393+
#define MAX_START_XID UINT64CONST(0x3fffffffffffffff)
394+
393395
typedef uint64 TransactionId;
394396

395397
#define TransactionIdPrecedes(id1, id2) ((id1) < (id2))
396398
#define TransactionIdPrecedesOrEquals(id1, id2) ((id1) <= (id2))
397399
#define TransactionIdFollows(id1, id2) ((id1) > (id2))
398400
#define TransactionIdFollowsOrEquals(id1, id2) ((id1) >= (id2))
399401

402+
#define StartTransactionIdIsValid(start_xid) ((start_xid) <= MAX_START_XID)
403+
400404
typedef uint32 ShortTransactionId;
401405

402406
typedef uint64 LocalTransactionId;
@@ -417,8 +421,12 @@ typedef TransactionId MultiXactId;
417421
#define MultiXactIdFollows(id1, id2) ((id1) > (id2))
418422
#define MultiXactIdFollowsOrEquals(id1, id2) ((id1) >= (id2))
419423

424+
#define StartMultiXactIdIsValid(start_mx_id) ((start_mx_id) <= MAX_START_XID)
425+
420426
typedef uint64 MultiXactOffset;
421427

428+
#define StartMultiXactOffsetIsValid(start_mx_offset) ((start_mx_offset) <= MAX_START_XID)
429+
422430
typedef uint32 CommandId;
423431

424432
#define FirstCommandId ((CommandId) 0)

src/test/perl/PostgresNode.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ sub init
397397
mkdir $self->backup_dir;
398398
mkdir $self->archive_dir;
399399

400-
TestLib::system_or_bail('initdb', '-D', $pgdata, '-A', 'trust', '-N');
400+
TestLib::system_or_bail('initdb', '-D', $pgdata, '-A', 'trust', '-N', '-x', '4294967296', '-m', '4294967296');
401401
TestLib::system_or_bail($ENV{PG_REGRESS}, '--config-auth', $pgdata);
402402

403403
open my $conf, ">>$pgdata/postgresql.conf";

src/test/regress/pg_regress.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "getopt_long.h"
3535
#include "libpq/pqcomm.h" /* needed for UNIXSOCK_PATH() */
3636
#include "pg_config_paths.h"
37+
#include "pg_config.h"
3738

3839
/* for resultmap we need a list of pairs of strings */
3940
typedef struct _resultmap
@@ -73,6 +74,7 @@ char *inputdir = ".";
7374
char *outputdir = ".";
7475
char *bindir = PGBINDIR;
7576
char *launcher = NULL;
77+
char *xid_options = "";
7678
static _stringlist *loadlanguage = NULL;
7779
static _stringlist *loadextension = NULL;
7880
static int max_connections = 0;
@@ -2215,13 +2217,17 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
22152217

22162218
/* initdb */
22172219
header(_("initializing database system"));
2220+
#ifdef XID_IS_64BIT
2221+
xid_options = " -x 4294967296 -m 4294967296";
2222+
#endif
22182223
snprintf(buf, sizeof(buf),
2219-
"\"%s%sinitdb\" -D \"%s/data\" --noclean --nosync%s%s > \"%s/log/initdb.log\" 2>&1",
2224+
"\"%s%sinitdb\" -D \"%s/data\" --noclean --nosync%s%s%s > \"%s/log/initdb.log\" 2>&1",
22202225
bindir ? bindir : "",
22212226
bindir ? "/" : "",
22222227
temp_instance,
22232228
debug ? " --debug" : "",
22242229
nolocale ? " --no-locale" : "",
2230+
xid_options,
22252231
outputdir);
22262232
if (system(buf))
22272233
{

0 commit comments

Comments
 (0)