7
7
*
8
8
*
9
9
* 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 $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
21
21
#include "storage/sinval.h"
22
22
#include "storage/sinvaladt.h"
23
23
24
- extern SISeg * shmInvalBuffer ;/* the shared buffer segment, set by
25
- * SISegmentAttach()
26
- */
27
- extern BackendId MyBackendId ;
28
- extern BackendTag MyBackendTag ;
29
-
30
24
SPINLOCK SInvalLock = (SPINLOCK )NULL ;
31
25
32
26
/****************************************************************************/
@@ -39,11 +33,6 @@ CreateSharedInvalidationState(IPCKey key, int maxBackends)
39
33
{
40
34
int status ;
41
35
42
- /*
43
- * REMOVED SISyncKill(IPCKeyGetSIBufferMemorySemaphoreKey(key));
44
- * SISyncInit(IPCKeyGetSIBufferMemorySemaphoreKey(key));
45
- */
46
-
47
36
/* SInvalLock gets set in spin.c, during spinlock init */
48
37
status = SISegmentInit (true,IPCKeyGetSIBufferMemoryBlock (key ),
49
38
maxBackends );
@@ -53,9 +42,9 @@ CreateSharedInvalidationState(IPCKey key, int maxBackends)
53
42
}
54
43
55
44
/****************************************************************************/
56
- /*AttachSharedInvalidationState(key) Attacha buffer segment */
45
+ /*AttachSharedInvalidationState(key) Attachto existing buffer segment*/
57
46
/**/
58
- /*should be calledonly bythe POSTMASTER */
47
+ /*should be called byeach backend during startup */
59
48
/****************************************************************************/
60
49
void
61
50
AttachSharedInvalidationState (IPCKey key )
@@ -74,6 +63,11 @@ AttachSharedInvalidationState(IPCKey key)
74
63
elog (FATAL ,"AttachSharedInvalidationState: failed segment init" );
75
64
}
76
65
66
+ /*
67
+ * InitSharedInvalidationState
68
+ *Initialize new backend's state info in buffer segment.
69
+ *Must be called after AttachSharedInvalidationState().
70
+ */
77
71
void
78
72
InitSharedInvalidationState (void )
79
73
{
@@ -88,24 +82,19 @@ InitSharedInvalidationState(void)
88
82
89
83
/*
90
84
* RegisterSharedInvalid
91
- *Returns anew local cache invalidationstate containing a new entry .
85
+ *Add ashared- cache- invalidationmessage to the global SI message queue .
92
86
*
93
87
* Note:
94
88
*Assumes hash index is valid.
95
89
*Assumes item pointer is valid.
96
90
*/
97
- /****************************************************************************/
98
- /*RegisterSharedInvalid(cacheId, hashIndex, pointer)*/
99
- /**/
100
- /*register a message in the buffer*/
101
- /*should be called by a backend*/
102
- /****************************************************************************/
103
91
void
104
92
RegisterSharedInvalid (int cacheId ,/* XXX */
105
93
Index hashIndex ,
106
94
ItemPointer pointer )
107
95
{
108
- SharedInvalidData newInvalid ;
96
+ SharedInvalidData newInvalid ;
97
+ bool insertOK ;
109
98
110
99
/*
111
100
* This code has been hacked to accept two types of messages. This
@@ -127,34 +116,16 @@ RegisterSharedInvalid(int cacheId,/* XXX */
127
116
ItemPointerSetInvalid (& newInvalid .pointerData );
128
117
129
118
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 );
145
120
SpinRelease (SInvalLock );
121
+ if (!insertOK )
122
+ elog (NOTICE ,"RegisterSharedInvalid: SI buffer overflow" );
146
123
}
147
124
148
125
/*
149
126
* InvalidateSharedInvalid
150
- *Processes all entries in a shared cache invalidation state.
127
+ *Process shared-cache-invalidation messages waiting for this backend
151
128
*/
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
- /****************************************************************************/
158
129
void
159
130
InvalidateSharedInvalid (void (* invalFunction ) (),
160
131
void (* resetFunction ) ())