Skip to content

Commit 22fe3d4

Browse files
committed
I finally understood what sinvaladt.c is doing --- and it
offended my aesthestic sensibility that there was so much unreadable code doing so little. Rewritten code is about half the size, faster, and (I hope) much more intelligible.
1 parent cc8b67a commit 22fe3d4

File tree

4 files changed

+316
-820
lines changed

4 files changed

+316
-820
lines changed

src/backend/storage/ipc/sinval.c

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.17 1999/09/04 18:36:45 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.18 1999/09/06 19:37:38 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -21,12 +21,6 @@
2121
#include "storage/sinval.h"
2222
#include "storage/sinvaladt.h"
2323

24-
extern SISeg *shmInvalBuffer; /* the shared buffer segment, set by
25-
* SISegmentAttach()
26-
*/
27-
extern BackendId MyBackendId;
28-
extern BackendTag MyBackendTag;
29-
3024
SPINLOCK SInvalLock = (SPINLOCK) NULL;
3125

3226
/****************************************************************************/
@@ -39,11 +33,6 @@ CreateSharedInvalidationState(IPCKey key, int maxBackends)
3933
{
4034
int status;
4135

42-
/*
43-
* REMOVED SISyncKill(IPCKeyGetSIBufferMemorySemaphoreKey(key));
44-
* SISyncInit(IPCKeyGetSIBufferMemorySemaphoreKey(key));
45-
*/
46-
4736
/* SInvalLock gets set in spin.c, during spinlock init */
4837
status = SISegmentInit(true, IPCKeyGetSIBufferMemoryBlock(key),
4938
maxBackends);
@@ -53,9 +42,9 @@ CreateSharedInvalidationState(IPCKey key, int maxBackends)
5342
}
5443

5544
/****************************************************************************/
56-
/* AttachSharedInvalidationState(key) Attach a buffer segment */
45+
/* AttachSharedInvalidationState(key) Attach to existing buffer segment */
5746
/* */
58-
/* should be called only by the POSTMASTER */
47+
/* should be called by each backend during startup */
5948
/****************************************************************************/
6049
void
6150
AttachSharedInvalidationState(IPCKey key)
@@ -74,6 +63,11 @@ AttachSharedInvalidationState(IPCKey key)
7463
elog(FATAL, "AttachSharedInvalidationState: failed segment init");
7564
}
7665

66+
/*
67+
* InitSharedInvalidationState
68+
* Initialize new backend's state info in buffer segment.
69+
* Must be called after AttachSharedInvalidationState().
70+
*/
7771
void
7872
InitSharedInvalidationState(void)
7973
{
@@ -88,24 +82,19 @@ InitSharedInvalidationState(void)
8882

8983
/*
9084
* RegisterSharedInvalid
91-
* Returns a new local cache invalidation state containing a new entry.
85+
* Add a shared-cache-invalidation message to the global SI message queue.
9286
*
9387
* Note:
9488
* Assumes hash index is valid.
9589
* Assumes item pointer is valid.
9690
*/
97-
/****************************************************************************/
98-
/* RegisterSharedInvalid(cacheId, hashIndex, pointer) */
99-
/* */
100-
/* register a message in the buffer */
101-
/* should be called by a backend */
102-
/****************************************************************************/
10391
void
10492
RegisterSharedInvalid(int cacheId, /* XXX */
10593
Index hashIndex,
10694
ItemPointer pointer)
10795
{
108-
SharedInvalidData newInvalid;
96+
SharedInvalidData newInvalid;
97+
bool insertOK;
10998

11099
/*
111100
* This code has been hacked to accept two types of messages. This
@@ -127,34 +116,16 @@ RegisterSharedInvalid(int cacheId, /* XXX */
127116
ItemPointerSetInvalid(&newInvalid.pointerData);
128117

129118
SpinAcquire(SInvalLock);
130-
while (!SISetDataEntry(shmInvalBuffer, &newInvalid))
131-
{
132-
/* buffer full */
133-
/* release a message, mark process cache states to be invalid */
134-
SISetProcStateInvalid(shmInvalBuffer);
135-
136-
if (!SIDelDataEntries(shmInvalBuffer, 1))
137-
{
138-
/* inconsistent buffer state -- shd never happen */
139-
SpinRelease(SInvalLock);
140-
elog(FATAL, "RegisterSharedInvalid: inconsistent buffer state");
141-
}
142-
143-
/* loop around to try write again */
144-
}
119+
insertOK = SIInsertDataEntry(shmInvalBuffer, &newInvalid);
145120
SpinRelease(SInvalLock);
121+
if (! insertOK)
122+
elog(NOTICE, "RegisterSharedInvalid: SI buffer overflow");
146123
}
147124

148125
/*
149126
* InvalidateSharedInvalid
150-
* Processes all entries in a shared cache invalidation state.
127+
* Process shared-cache-invalidation messages waiting for this backend
151128
*/
152-
/****************************************************************************/
153-
/* InvalidateSharedInvalid(invalFunction, resetFunction) */
154-
/* */
155-
/* invalidate a message in the buffer (read and clean up) */
156-
/* should be called by a backend */
157-
/****************************************************************************/
158129
void
159130
InvalidateSharedInvalid(void (*invalFunction) (),
160131
void (*resetFunction) ())

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy