Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b98ba2a

Browse files
committed
pg_variable is not used in WAL version now.
1 parent b703c12 commit b98ba2a

File tree

5 files changed

+197
-13
lines changed

5 files changed

+197
-13
lines changed

src/backend/access/transam/transam.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.35 2000/08/03 19:18:55 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.36 2000/11/03 11:39:35 vadim Exp $
1212
*
1313
* NOTES
1414
* This file contains the high level access-method interface to the
@@ -83,6 +83,10 @@ int RecoveryCheckingEnableState = 0;
8383
*/
8484
extern int OidGenLockId;
8585

86+
#ifdef XLOG
87+
#include "miscadmin.h"
88+
extern VariableCache ShmemVariableCache;
89+
#endif
8690

8791
/* ----------------
8892
* recovery checking accessors
@@ -438,7 +442,13 @@ InitializeTransactionLog(void)
438442
TransactionLogUpdate(AmiTransactionId, XID_COMMIT);
439443
TransactionIdStore(AmiTransactionId, &cachedTestXid);
440444
cachedTestXidStatus = XID_COMMIT;
445+
#ifdef XLOG
446+
Assert(!IsUnderPostmaster &&
447+
ShmemVariableCache->nextXid <= FirstTransactionId);
448+
ShmemVariableCache->nextXid = FirstTransactionId;
449+
#else
441450
VariableRelationPutNextXid(FirstTransactionId);
451+
#endif
442452

443453
}
444454
else if (RecoveryCheckingEnabled())

src/backend/access/transam/varsup.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.30 2000/10/28 16:20:53 vadim Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.31 2000/11/03 11:39:35 vadim Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
15+
#ifdef XLOG
16+
17+
#include "xlog_varsup.c"
18+
19+
#else
1520

1621
#include "postgres.h"
1722

@@ -125,11 +130,7 @@ VariableRelationPutNextXid(TransactionId xid)
125130

126131
TransactionIdStore(xid, &(var->nextXidData));
127132

128-
#ifdef XLOG
129-
WriteBuffer(buf); /* temp */
130-
#else
131133
FlushBuffer(buf, TRUE);
132-
#endif
133134
}
134135

135136
/* --------------------------------
@@ -520,3 +521,5 @@ CheckMaxObjectId(Oid assigned_oid)
520521
prefetched_oid_count = 0; /* force reload */
521522
GetNewObjectId(&temp_oid); /* cause target OID to be allocated */
522523
}
524+
525+
#endif /* !XLOG */

src/backend/access/transam/xlog.c

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.22 2000/10/28 16:20:54 vadim Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.23 2000/11/03 11:39:35 vadim Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -157,6 +157,7 @@ typedef struct CheckPoint
157157
} CheckPoint;
158158

159159
#define XLOG_CHECKPOINT 0x00
160+
#define XLOG_NEXTOID 0x10
160161

161162
/*
162163
* We break each log file in 16Mb segments
@@ -1373,10 +1374,9 @@ StartupXLOG()
13731374
elog(LOG, "Invalid NextTransactionId/NextOid");
13741375
#endif
13751376

1376-
#ifdef XLOG_2
13771377
ShmemVariableCache->nextXid = checkPoint.nextXid;
13781378
ShmemVariableCache->nextOid = checkPoint.nextOid;
1379-
#endif
1379+
ShmemVariableCache->oidCount = 0;
13801380

13811381
ThisStartUpID = checkPoint.ThisStartUpID;
13821382

@@ -1430,10 +1430,8 @@ StartupXLOG()
14301430
ReadRecPtr.xlogid, ReadRecPtr.xrecoff);
14311431
do
14321432
{
1433-
#ifdef XLOG_2
14341433
if (record->xl_xid >= ShmemVariableCache->nextXid)
14351434
ShmemVariableCache->nextXid = record->xl_xid + 1;
1436-
#endif
14371435
if (XLOG_DEBUG)
14381436
{
14391437
char buf[8192];
@@ -1609,6 +1607,9 @@ CreateCheckPoint(bool shutdown)
16091607
SpinRelease(XidGenLockId);
16101608
SpinAcquire(OidGenLockId);
16111609
checkPoint.nextOid = ShmemVariableCache->nextOid;
1610+
if (!shutdown)
1611+
checkPoint.nextOid += ShmemVariableCache->oidCount;
1612+
16121613
SpinRelease(OidGenLockId);
16131614

16141615
FlushBufferPool();
@@ -1647,13 +1648,32 @@ CreateCheckPoint(bool shutdown)
16471648
return;
16481649
}
16491650

1651+
void XLogPutNextOid(Oid nextOid);
1652+
1653+
void
1654+
XLogPutNextOid(Oid nextOid)
1655+
{
1656+
(void) XLogInsert(RM_XLOG_ID, XLOG_NEXTOID,
1657+
(char *) &nextOid, sizeof(Oid), NULL, 0);
1658+
}
1659+
16501660
void xlog_redo(XLogRecPtr lsn, XLogRecord *record);
16511661
void xlog_undo(XLogRecPtr lsn, XLogRecord *record);
16521662
void xlog_desc(char *buf, uint8 xl_info, char* rec);
16531663

16541664
void
16551665
xlog_redo(XLogRecPtr lsn, XLogRecord *record)
16561666
{
1667+
uint8 info = record->xl_info & ~XLR_INFO_MASK;
1668+
1669+
if (info == XLOG_NEXTOID)
1670+
{
1671+
Oid nextOid;
1672+
1673+
memcpy(&nextOid, XLogRecGetData(record), sizeof(Oid));
1674+
if (ShmemVariableCache->nextOid < nextOid)
1675+
ShmemVariableCache->nextOid = nextOid;
1676+
}
16571677
}
16581678

16591679
void
@@ -1677,6 +1697,13 @@ xlog_desc(char *buf, uint8 xl_info, char* rec)
16771697
checkpoint->nextOid,
16781698
(checkpoint->Shutdown) ? "shutdown" : "online");
16791699
}
1700+
else if (info == XLOG_NEXTOID)
1701+
{
1702+
Oid nextOid;
1703+
1704+
memcpy(&nextOid, rec, sizeof(Oid));
1705+
sprintf(buf + strlen(buf), "nextOid: %u", nextOid);
1706+
}
16801707
else
16811708
strcat(buf, "UNKNOWN");
16821709
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* varsup.c
4+
* postgres OID & XID variables support routines
5+
*
6+
* Copyright (c) 2000, PostgreSQL, Inc
7+
*
8+
* IDENTIFICATION
9+
* $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/xlog_varsup.c,v 1.1 2000/11/03 11:39:35 vadim Exp $
10+
*
11+
*-------------------------------------------------------------------------
12+
*/
13+
14+
#include "postgres.h"
15+
16+
#include "access/transam.h"
17+
#include "storage/proc.h"
18+
19+
SPINLOCK OidGenLockId;
20+
21+
extern SPINLOCK XidGenLockId;
22+
extern void XLogPutNextOid(Oid nextOid);
23+
24+
/* pointer to "variable cache" in shared memory (set up by shmem.c) */
25+
VariableCache ShmemVariableCache = NULL;
26+
27+
void
28+
GetNewTransactionId(TransactionId *xid)
29+
{
30+
/*
31+
* During bootstrap initialization, we return the special
32+
* bootstrap transaction id.
33+
*/
34+
if (AMI_OVERRIDE)
35+
{
36+
*xid = AmiTransactionId;
37+
return;
38+
}
39+
40+
SpinAcquire(XidGenLockId);
41+
*xid = ShmemVariableCache->nextXid;
42+
(ShmemVariableCache->nextXid)++;
43+
44+
if (MyProc != (PROC *) NULL)
45+
MyProc->xid = *xid;
46+
47+
SpinRelease(XidGenLockId);
48+
49+
}
50+
51+
/*
52+
* Like GetNewTransactionId reads nextXid but don't fetch it.
53+
*/
54+
void
55+
ReadNewTransactionId(TransactionId *xid)
56+
{
57+
58+
/*
59+
* During bootstrap initialization, we return the special
60+
* bootstrap transaction id.
61+
*/
62+
if (AMI_OVERRIDE)
63+
{
64+
*xid = AmiTransactionId;
65+
return;
66+
}
67+
68+
SpinAcquire(XidGenLockId);
69+
*xid = ShmemVariableCache->nextXid;
70+
SpinRelease(XidGenLockId);
71+
72+
}
73+
74+
/* ----------------------------------------------------------------
75+
* object id generation support
76+
* ----------------------------------------------------------------
77+
*/
78+
79+
#define VAR_OID_PREFETCH 8192
80+
static Oid lastSeenOid = InvalidOid;
81+
82+
void
83+
GetNewObjectId(Oid *oid_return)
84+
{
85+
SpinAcquire(OidGenLockId);
86+
87+
/* If we run out of logged for use oids then we log more */
88+
if (ShmemVariableCache->oidCount == 0)
89+
{
90+
XLogPutNextOid(ShmemVariableCache->nextOid + VAR_OID_PREFETCH);
91+
ShmemVariableCache->oidCount = VAR_OID_PREFETCH;
92+
}
93+
94+
if (PointerIsValid(oid_return))
95+
lastSeenOid = (*oid_return) = ShmemVariableCache->nextOid;
96+
97+
(ShmemVariableCache->nextOid)++;
98+
(ShmemVariableCache->oidCount)--;
99+
100+
SpinRelease(OidGenLockId);
101+
}
102+
103+
void
104+
CheckMaxObjectId(Oid assigned_oid)
105+
{
106+
107+
if (lastSeenOid != InvalidOid && assigned_oid < lastSeenOid)
108+
return;
109+
110+
SpinAcquire(OidGenLockId);
111+
if (assigned_oid < ShmemVariableCache->nextOid)
112+
{
113+
lastSeenOid = ShmemVariableCache->nextOid - 1;
114+
SpinRelease(OidGenLockId);
115+
return;
116+
}
117+
118+
/* If we are in the logged oid range, just bump nextOid up */
119+
if (assigned_oid <= ShmemVariableCache->nextOid +
120+
ShmemVariableCache->oidCount - 1)
121+
{
122+
ShmemVariableCache->oidCount -=
123+
assigned_oid - ShmemVariableCache->nextOid + 1;
124+
ShmemVariableCache->nextOid = assigned_oid + 1;
125+
SpinRelease(OidGenLockId);
126+
return;
127+
}
128+
129+
/*
130+
* We have exceeded the logged oid range.
131+
* We should lock the database and kill all other backends
132+
* but we are loading oid's that we can not guarantee are unique
133+
* anyway, so we must rely on the user.
134+
*/
135+
136+
XLogPutNextOid(assigned_oid + VAR_OID_PREFETCH);
137+
ShmemVariableCache->oidCount = VAR_OID_PREFETCH - 1;
138+
ShmemVariableCache->nextOid = assigned_oid + 1;
139+
140+
SpinRelease(OidGenLockId);
141+
142+
}

src/include/access/transam.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: transam.h,v 1.25 2000/10/28 16:20:59 vadim Exp $
10+
* $Id: transam.h,v 1.26 2000/11/03 11:39:36 vadim Exp $
1111
*
1212
* NOTES
1313
* Transaction System Version 101 now support proper oid
@@ -136,10 +136,12 @@ typedef VariableRelationContentsData *VariableRelationContents;
136136
*/
137137
typedef struct VariableCacheData
138138
{
139+
#ifndef XLOG
139140
uint32 xid_count;
141+
#endif
140142
TransactionId nextXid;
141-
uint32 oid_count; /* not implemented, yet */
142143
Oid nextOid;
144+
uint32 oidCount;
143145
} VariableCacheData;
144146

145147
typedef VariableCacheData *VariableCache;

0 commit comments

Comments
 (0)