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

Commit b9f3a92

Browse files
committed
Create a new HeapTupleSatisfiesVacuum() routine in tqual.c that embodies the
validity checking rules for VACUUM. Make some other rearrangements of the VACUUM code to allow more code to be shared between full and lazy VACUUM. Minor code cleanups and added comments for TransactionId manipulations.
1 parent eaafc9d commit b9f3a92

File tree

14 files changed

+638
-562
lines changed

14 files changed

+638
-562
lines changed

src/backend/access/heap/heapam.c

+1-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.122 2001/07/06 09:41:36 inoue Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.123 2001/07/12 04:11:12 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -48,11 +48,6 @@
4848
#include "pgstat.h"
4949

5050

51-
XLogRecPtr log_heap_move(Relation reln, Buffer oldbuf, ItemPointerData from,
52-
Buffer newbuf, HeapTuple newtup);
53-
XLogRecPtr log_heap_clean(Relation reln, Buffer buffer,
54-
char *unused, int unlen);
55-
5651
/* comments are in heap_update */
5752
static xl_heaptid _locked_tuple_;
5853
static void _heap_unlock_tuple(void *data);

src/backend/access/transam/transam.c

+8-32
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.44 2001/05/14 20:30:19 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.45 2001/07/12 04:11:13 tgl Exp $
1212
*
1313
* NOTES
1414
* This file contains the high level access-method interface to the
@@ -24,6 +24,7 @@
2424
#include "catalog/catname.h"
2525
#include "miscadmin.h"
2626

27+
2728
static int RecoveryCheckingEnabled(void);
2829
static void TransRecover(Relation logRelation);
2930
static bool TransactionLogTest(TransactionId transactionId, XidStatus status);
@@ -40,29 +41,11 @@ static void TransactionLogUpdate(TransactionId transactionId,
4041
Relation LogRelation = (Relation) NULL;
4142

4243
/* ----------------
43-
* global variables holding cached transaction id's and statuses.
44-
* ----------------
45-
*/
46-
TransactionId cachedTestXid;
47-
XidStatus cachedTestXidStatus;
48-
49-
/* ----------------
50-
* transaction system constants
44+
* Single-item cache for results of TransactionLogTest.
5145
* ----------------
5246
*/
53-
/* ----------------------------------------------------------------
54-
* transaction system constants
55-
*
56-
* read the comments for GetNewTransactionId in order to
57-
* understand the initial values for AmiTransactionId and
58-
* FirstTransactionId. -cim 3/23/90
59-
* ----------------------------------------------------------------
60-
*/
61-
TransactionId NullTransactionId = (TransactionId) 0;
62-
63-
TransactionId AmiTransactionId = (TransactionId) 512;
64-
65-
TransactionId FirstTransactionId = (TransactionId) 514;
47+
static TransactionId cachedTestXid = NullTransactionId;
48+
static XidStatus cachedTestXidStatus;
6649

6750
/* ----------------
6851
* transaction recovery state variables
@@ -76,7 +59,7 @@ TransactionId FirstTransactionId = (TransactionId) 514;
7659
* goes from zero to one. -cim 3/21/90
7760
* ----------------
7861
*/
79-
int RecoveryCheckingEnableState = 0;
62+
static int RecoveryCheckingEnableState = 0;
8063

8164
/* ----------------
8265
* recovery checking accessors
@@ -203,14 +186,9 @@ TransactionLogUpdate(TransactionId transactionId, /* trans id to update */
203186

204187
/*
205188
* update (invalidate) our single item TransactionLogTest cache.
206-
*
207-
* if (status != XID_COMMIT)
208-
*
209-
* What's the hell ?! Why != XID_COMMIT ?!
210189
*/
211190
TransactionIdStore(transactionId, &cachedTestXid);
212191
cachedTestXidStatus = status;
213-
214192
}
215193

216194
/* ----------------------------------------------------------------
@@ -355,17 +333,15 @@ InitializeTransactionLog(void)
355333

356334
/*
357335
* if we have a virgin database, we initialize the log relation by
358-
* committing the AmiTransactionId (id 512) and we initialize the
336+
* committing the AmiTransactionId and we initialize the
359337
* variable relation by setting the next available transaction id to
360-
* FirstTransactionId (id 514). OID initialization happens as a side
338+
* FirstTransactionId. OID initialization happens as a side
361339
* effect of bootstrapping in varsup.c.
362340
*/
363341
SpinAcquire(OidGenLockId);
364342
if (!TransactionIdDidCommit(AmiTransactionId))
365343
{
366344
TransactionLogUpdate(AmiTransactionId, XID_COMMIT);
367-
TransactionIdStore(AmiTransactionId, &cachedTestXid);
368-
cachedTestXidStatus = XID_COMMIT;
369345
Assert(!IsUnderPostmaster &&
370346
ShmemVariableCache->nextXid <= FirstTransactionId);
371347
ShmemVariableCache->nextXid = FirstTransactionId;

src/backend/access/transam/transsup.c

+59-7
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,75 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/transsup.c,v 1.30 2001/03/22 06:16:10 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/transsup.c,v 1.31 2001/07/12 04:11:13 tgl Exp $
1212
*
1313
* NOTES
1414
* This file contains support functions for the high
1515
* level access method interface routines found in transam.c
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
19-
2019
#include "postgres.h"
2120

2221
#include "access/xact.h"
2322
#include "utils/bit.h"
2423

24+
25+
/* ----------------
26+
* transaction system version id
27+
*
28+
* this is stored on the first page of the log, time and variable
29+
* relations on the first 4 bytes. This is so that if we improve
30+
* the format of the transaction log after postgres version 2, then
31+
* people won't have to rebuild their databases.
32+
*
33+
* TRANS_SYSTEM_VERSION 100 means major version 1 minor version 0.
34+
* Two databases with the same major version should be compatible,
35+
* even if their minor versions differ.
36+
*
37+
* XXX This isn't actually being used!
38+
* ----------------
39+
*/
40+
#define TRANS_SYSTEM_VERSION 200
41+
42+
/* ----------------
43+
* LogRelationContents structure
44+
*
45+
* This structure describes the storage of the data in the
46+
* first 128 bytes of the log relation. This storage is never
47+
* used for transaction status because transaction id's begin
48+
* their numbering at 512.
49+
*
50+
* The first 4 bytes of this relation store the version
51+
* number of the transaction system.
52+
*
53+
* XXX This isn't actually being used!
54+
* ----------------
55+
*/
56+
typedef struct LogRelationContentsData
57+
{
58+
XLogRecPtr LSN; /* temp hack: LSN is member of any block */
59+
/* so should be described in bufmgr */
60+
int TransSystemVersion;
61+
} LogRelationContentsData;
62+
63+
typedef LogRelationContentsData *LogRelationContents;
64+
65+
66+
/* ----------------
67+
* BitIndexOf computes the index of the Nth xid on a given block
68+
* ----------------
69+
*/
70+
#define BitIndexOf(N) ((N) * 2)
71+
72+
/* ----------------
73+
* transaction page definitions
74+
* ----------------
75+
*/
76+
#define TP_DataSize (BLCKSZ - sizeof(XLogRecPtr))
77+
#define TP_NumXidStatusPerBlock (TP_DataSize * 4)
78+
79+
2580
static XidStatus TransBlockGetXidStatus(Block tblock,
2681
TransactionId transactionId);
2782
static void TransBlockSetXidStatus(Block tblock,
@@ -54,7 +109,7 @@ TransComputeBlockNumber(Relation relation, /* relation to test */
54109
* test */
55110
BlockNumber *blockNumberOutP)
56111
{
57-
long itemsPerBlock = 0;
112+
uint32 itemsPerBlock = 0;
58113

59114
/*
60115
* we calculate the block number of our transaction by dividing the
@@ -135,10 +190,7 @@ TransBlockGetLastTransactionIdStatus(Block tblock,
135190
if (xstatus != XID_INPROGRESS)
136191
{
137192
if (returnXidP != NULL)
138-
{
139-
TransactionIdStore(baseXid, returnXidP);
140-
TransactionIdAdd(returnXidP, index - 1);
141-
}
193+
TransactionIdStore(baseXid + (index - 1), returnXidP);
142194
break;
143195
}
144196
}

src/backend/access/transam/varsup.c

+20-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 2000, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.40 2001/05/25 15:45:32 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.41 2001/07/12 04:11:13 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -18,8 +18,7 @@
1818
#include "storage/proc.h"
1919

2020

21-
/* Number of XIDs and OIDs to prefetch (preallocate) per XLOG write */
22-
#define VAR_XID_PREFETCH 1024
21+
/* Number of OIDs to prefetch (preallocate) per XLOG write */
2322
#define VAR_OID_PREFETCH 8192
2423

2524
/* Spinlocks for serializing generation of XIDs and OIDs, respectively */
@@ -29,10 +28,13 @@ SPINLOCK OidGenLockId;
2928
/* pointer to "variable cache" in shared memory (set up by shmem.c) */
3029
VariableCache ShmemVariableCache = NULL;
3130

31+
32+
/*
33+
* Allocate the next XID for my new transaction.
34+
*/
3235
void
3336
GetNewTransactionId(TransactionId *xid)
3437
{
35-
3638
/*
3739
* During bootstrap initialization, we return the special bootstrap
3840
* transaction id.
@@ -49,10 +51,22 @@ GetNewTransactionId(TransactionId *xid)
4951

5052
(ShmemVariableCache->nextXid)++;
5153

52-
SpinRelease(XidGenLockId);
53-
54+
/*
55+
* Must set MyProc->xid before releasing XidGenLock. This ensures that
56+
* when GetSnapshotData calls ReadNewTransactionId, all active XIDs
57+
* before the returned value of nextXid are already present in the shared
58+
* PROC array. Else we have a race condition.
59+
*
60+
* XXX by storing xid into MyProc without acquiring SInvalLock, we are
61+
* relying on fetch/store of an xid to be atomic, else other backends
62+
* might see a partially-set xid here. But holding both locks at once
63+
* would be a nasty concurrency hit (and at this writing, could cause a
64+
* deadlock against GetSnapshotData). So for now, assume atomicity.
65+
*/
5466
if (MyProc != (PROC *) NULL)
5567
MyProc->xid = *xid;
68+
69+
SpinRelease(XidGenLockId);
5670
}
5771

5872
/*
@@ -61,7 +75,6 @@ GetNewTransactionId(TransactionId *xid)
6175
void
6276
ReadNewTransactionId(TransactionId *xid)
6377
{
64-
6578
/*
6679
* During bootstrap initialization, we return the special bootstrap
6780
* transaction id.

0 commit comments

Comments
 (0)