Simplify initdb-time assignment of OIDs as I proposed yesterday, and

avoid encroaching on the 'user' range of OIDs by allowing automatic
OID assignment to use values below 16k until we reach normal operation.

initdb not forced since this doesn't make any incompatible change;
however a lot of stuff will have different OIDs after your next initdb.
This commit is contained in:
Tom Lane 2005-04-13 18:54:57 +00:00
parent 2fdf9e0be6
commit 2193a856a2
10 changed files with 69 additions and 94 deletions

View File

@ -1,5 +1,5 @@
<!--
$PostgreSQL: pgsql/doc/src/sgml/bki.sgml,v 1.14 2005/03/29 19:44:22 tgl Exp $
$PostgreSQL: pgsql/doc/src/sgml/bki.sgml,v 1.15 2005/04/13 18:54:55 tgl Exp $
-->
<chapter id="bki">
@ -167,8 +167,8 @@ $PostgreSQL: pgsql/doc/src/sgml/bki.sgml,v 1.14 2005/03/29 19:44:22 tgl Exp $
values and <replaceable
class="parameter">oid_value</replaceable> for its OID. If
<replaceable class="parameter">oid_value</replaceable> is zero
(0) or the clause is omitted, then the next available OID is
used.
(0) or the clause is omitted, and the table has OIDs, then the
next available OID is assigned.
</para>
<para>

View File

@ -6,7 +6,7 @@
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/transam/varsup.c,v 1.62 2005/02/20 21:46:48 tgl Exp $
* $PostgreSQL: pgsql/src/backend/access/transam/varsup.c,v 1.63 2005/04/13 18:54:56 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -265,14 +265,36 @@ GetNewObjectId(void)
/*
* Check for wraparound of the OID counter. We *must* not return 0
* (InvalidOid); and as long as we have to check that, it seems a good
* idea to skip over everything below BootstrapObjectIdData too. (This
* idea to skip over everything below FirstNormalObjectId too. (This
* basically just reduces the odds of OID collision right after a wrap
* occurs.) Note we are relying on unsigned comparison here.
*
* During initdb, we start the OID generator at FirstBootstrapObjectId,
* so we only enforce wrapping to that point when in bootstrap or
* standalone mode. The first time through this routine after normal
* postmaster start, the counter will be forced up to FirstNormalObjectId.
* This mechanism leaves the OIDs between FirstBootstrapObjectId and
* FirstNormalObjectId available for automatic assignment during initdb,
* while ensuring they will never conflict with user-assigned OIDs.
*/
if (ShmemVariableCache->nextOid < ((Oid) BootstrapObjectIdData))
if (ShmemVariableCache->nextOid < ((Oid) FirstNormalObjectId))
{
ShmemVariableCache->nextOid = BootstrapObjectIdData;
ShmemVariableCache->oidCount = 0;
if (IsPostmasterEnvironment)
{
/* wraparound in normal environment */
ShmemVariableCache->nextOid = FirstNormalObjectId;
ShmemVariableCache->oidCount = 0;
}
else
{
/* we may be bootstrapping, so don't enforce the full range */
if (ShmemVariableCache->nextOid < ((Oid) FirstBootstrapObjectId))
{
/* wraparound in standalone environment? */
ShmemVariableCache->nextOid = FirstBootstrapObjectId;
ShmemVariableCache->oidCount = 0;
}
}
}
/* If we run out of logged for use oids then we must log more */

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.183 2005/03/29 03:01:30 tgl Exp $
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.184 2005/04/13 18:54:56 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -3505,7 +3505,7 @@ BootStrapXLOG(void)
checkPoint.undo = checkPoint.redo;
checkPoint.ThisTimeLineID = ThisTimeLineID;
checkPoint.nextXid = FirstNormalTransactionId;
checkPoint.nextOid = BootstrapObjectIdData;
checkPoint.nextOid = FirstBootstrapObjectId;
checkPoint.time = time(NULL);
ShmemVariableCache->nextXid = checkPoint.nextXid;

View File

@ -10,7 +10,7 @@
#
#
# IDENTIFICATION
# $PostgreSQL: pgsql/src/backend/catalog/genbki.sh,v 1.33 2005/03/29 00:16:55 tgl Exp $
# $PostgreSQL: pgsql/src/backend/catalog/genbki.sh,v 1.34 2005/04/13 18:54:56 tgl Exp $
#
# NOTES
# non-essential whitespace is removed from the generated file.
@ -121,15 +121,6 @@ for dir in $INCLUDE_DIRS; do
fi
done
# Get FirstGenBKIObjectId from access/transam.h
for dir in $INCLUDE_DIRS; do
if [ -f "$dir/access/transam.h" ]; then
BKIOBJECTID=`grep '^#define[ ]*FirstGenBKIObjectId' $dir/access/transam.h | $AWK '{ print $3 }'`
break
fi
done
export BKIOBJECTID
touch ${OUTPUT_PREFIX}.description.$$
# ----------------
@ -173,8 +164,7 @@ sed -e "s/;[ ]*$//g" \
# contents of a catalog definition.
# reln_open is a flag indicating when we are processing DATA lines.
# (i.e. have a relation open and need to close it)
# nextbkioid is the next OID available for automatic assignment.
# oid is the most recently seen or assigned oid.
# oid is the most recently seen oid, or 0 if none in the last DATA line.
# ----------------
BEGIN {
inside = 0;
@ -184,7 +174,6 @@ BEGIN {
nc = 0;
reln_open = 0;
comment_level = 0;
nextbkioid = ENVIRON["BKIOBJECTID"];
oid = 0;
}
@ -202,9 +191,8 @@ comment_level > 0 { next; }
# ----------------
# DATA() statements are basically passed right through after
# stripping off the DATA( and the ) on the end. However,
# if we see "OID = 0" then we should assign an oid from nextbkioid.
# Remember any explicit or assigned OID for use by DESCR().
# stripping off the DATA( and the ) on the end.
# Remember any explicit OID for use by DESCR().
# ----------------
/^DATA\(/ {
data = substr($0, 6, length($0) - 6);
@ -213,12 +201,6 @@ comment_level > 0 { next; }
if (nf >= 4 && datafields[1] == "insert" && datafields[2] == "OID" && datafields[3] == "=")
{
oid = datafields[4];
if (oid == 0)
{
oid = nextbkioid;
nextbkioid++;
sub("OID *= *0", "OID = " oid, data);
}
}
print data;
next;

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.148 2005/03/11 03:52:06 neilc Exp $
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.149 2005/04/13 18:54:56 tgl Exp $
*
* NOTES
* Outside modules can create a lock table and acquire/release
@ -97,7 +97,7 @@ static const char *const lock_mode_names[] =
* --------
*/
int Trace_lock_oidmin = BootstrapObjectIdData;
int Trace_lock_oidmin = FirstNormalObjectId;
bool Trace_locks = false;
bool Trace_userlocks = false;
int Trace_lock_table = 0;

View File

@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.258 2005/04/08 00:59:59 neilc Exp $
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.259 2005/04/13 18:54:56 tgl Exp $
*
*--------------------------------------------------------------------
*/
@ -1090,7 +1090,7 @@ static struct config_int ConfigureNamesInt[] =
GUC_NOT_IN_SAMPLE
},
&Trace_lock_oidmin,
BootstrapObjectIdData, 0, INT_MAX, NULL, NULL
FirstNormalObjectId, 0, INT_MAX, NULL, NULL
},
{
{"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,

View File

@ -23,7 +23,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.30 2005/03/29 03:01:32 tgl Exp $
* $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.31 2005/04/13 18:54:56 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -404,7 +404,7 @@ GuessControlValues(void)
ControlFile.checkPointCopy.undo = ControlFile.checkPointCopy.redo;
ControlFile.checkPointCopy.ThisTimeLineID = 1;
ControlFile.checkPointCopy.nextXid = (TransactionId) 514; /* XXX */
ControlFile.checkPointCopy.nextOid = BootstrapObjectIdData;
ControlFile.checkPointCopy.nextOid = FirstBootstrapObjectId;
ControlFile.checkPointCopy.time = time(NULL);
ControlFile.state = DB_SHUTDOWNED;

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/access/transam.h,v 1.53 2005/02/20 21:46:50 tgl Exp $
* $PostgreSQL: pgsql/src/include/access/transam.h,v 1.54 2005/04/13 18:54:57 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -55,23 +55,24 @@
* OIDs 1-9999 are reserved for manual assignment (see the files
* in src/include/catalog/).
*
* OIDS 10000-16383 are reserved for assignment by genbki.sh.
* OIDS 10000-16383 are reserved for assignment during initdb
* using the OID generator. (We start the generator at 10000.)
*
* OIDs beginning at 16384 are assigned at runtime from the OID
* generator. (The first few of these will be assigned during initdb,
* to objects created after the initial BKI script processing.)
* OIDs beginning at 16384 are assigned from the OID generator
* during normal multiuser operation. (We force the generator up to
* 16384 as soon as we are in normal operation.)
*
* The choices of 10000 and 16384 are completely arbitrary, and can be moved
* if we run low on OIDs in either category. Changing the macros below
* should be sufficient to do this.
*
* NOTE: if the OID generator wraps around, we should skip over OIDs 0-16383
* NOTE: if the OID generator wraps around, we skip over OIDs 0-16383
* and resume with 16384. This minimizes the odds of OID conflict, by not
* reassigning OIDs that might have been assigned during initdb.
* ----------
*/
#define FirstGenBKIObjectId 10000
#define BootstrapObjectIdData 16384
#define FirstBootstrapObjectId 10000
#define FirstNormalObjectId 16384
/*
* VariableCache is placed in shmem and used by

View File

@ -2,45 +2,18 @@
#
# duplicate_oids
#
# finds oids that are duplicated in the system tables.
# $PostgreSQL: pgsql/src/include/catalog/duplicate_oids,v 1.6 2005/04/13 18:54:57 tgl Exp $
#
# finds manually-assigned oids that are duplicated in the system tables.
#
# run this script in src/include/catalog.
#
FILES=`ls pg_*.h`
#
# The previous version did not use the -d option on uniq
# so check here that it is supported.
# Otherwise, use the old algorithm
#
if [ `uniq -d < /dev/null > /dev/null 2>&1` ]; then
echo "uniq -d is not supported on your platform."
echo "Please report this to pgsql-hackers@postgresql.org"
egrep '^DATA' $FILES | \
sed -e 's/^.*OID[^=]*=[^0-9]*//' -e 's/[^0-9].*$//' | \
sort -n >/tmp/alloids.$$
uniq /tmp/alloids.$$ >/tmp/uniqoids.$$
diff -u /tmp/alloids.$$ /tmp/uniqoids.$$ | \
grep -v '/tmp/' | \
grep '^-' | \
sed -e 's/^-//' | \
grep -v '^0$' | \
uniq
rm /tmp/alloids.$$
rm /tmp/uniqoids.$$
else
# echo "uniq -d is supported on this platform."
# echo "Will omit the use of temporary files."
egrep '^DATA' $FILES | \
sed -e 's/^.*OID[^=]*=[^0-9]*//' -e 's/[^0-9].*$//' | \
sort -n | uniq -d | \
egrep -v '^[0]*$'
egrep -v '^0*$'
fi
exit
exit 0

View File

@ -1,20 +1,17 @@
#!/bin/sh
#
# unused_oids
#
# $PostgreSQL: pgsql/src/include/catalog/unused_oids,v 1.5 2003/11/29 19:52:08 pgsql Exp $
# $PostgreSQL: pgsql/src/include/catalog/unused_oids,v 1.6 2005/04/13 18:54:57 tgl Exp $
#
# finds blocks of oids that have not already been claimed by
# post_hackers for internal purposes. primarily useful for
# finding valid oids for new internal function oids. the numbers
# printed are inclusive ranges of valid (unused) oids.
# finds blocks of manually-assignable oids that have not already been
# claimed by post_hackers. primarily useful for finding available
# oids for new internal functions. the numbers printed are inclusive
# ranges of unused oids.
#
# before using a large empty block, make sure you aren't about
# to take over what was intended as expansion space for something
# else. also, before using a number, do a "grepsrc" to make sure
# that someone isn't using a literal numeric constant somewhere..
#
# non-berkeley post_hackers should probably not try to use oids
# less than the highest one that comes with the distributed source.
# else.
#
# run this script in src/include/catalog.
#
@ -22,9 +19,9 @@
AWK="awk"
# Get FirstGenBKIObjectId from access/transam.h
BKIOBJECTID=`grep '#define[ ]*FirstGenBKIObjectId' ../access/transam.h | $AWK '{ print $3 }'`
export BKIOBJECTID
# Get FirstBootstrapObjectId from access/transam.h
FIRSTOBJECTID=`grep '#define[ ]*FirstBootstrapObjectId' ../access/transam.h | $AWK '{ print $3 }'`
export FIRSTOBJECTID
egrep '^DATA' pg_*.h | \
sed -e 's/^.*OID[^=]*=[^0-9]*//' -e 's/[^0-9].*$//' | \
@ -45,5 +42,5 @@ BEGIN {
last = $1;
}
END {
print last + 1, "-", ENVIRON["BKIOBJECTID"]-1;
print last + 1, "-", ENVIRON["FIRSTOBJECTID"]-1;
}'