14
14
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
15
15
* Portions Copyright (c) 1994-5, Regents of the University of California
16
16
*
17
- *
18
- * IDENTIFICATION
19
- * $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.36 2000/11/30 01:39:07 tgl Exp $
20
- *
21
17
*-------------------------------------------------------------------------
22
18
*/
23
-
24
19
#include "postgres.h"
25
20
26
- #ifdef XLOG
27
- #include "xlog_localbuf.c"
28
- #else
29
-
30
21
#include <sys/types.h>
31
22
#include <sys/file.h>
32
23
#include <math.h>
@@ -109,7 +100,7 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr)
109
100
* transaction to touch it doesn't need its contents but has not
110
101
* flushed it). if that's the case, write it out before reusing it!
111
102
*/
112
- if (bufHdr -> flags & BM_DIRTY )
103
+ if (bufHdr -> flags & BM_DIRTY || bufHdr -> cntxDirty )
113
104
{
114
105
Relation bufrel = RelationNodeCacheGetRelation (bufHdr -> tag .rnode );
115
106
@@ -136,6 +127,7 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr)
136
127
bufHdr -> tag .rnode = reln -> rd_node ;
137
128
bufHdr -> tag .blockNum = blockNum ;
138
129
bufHdr -> flags &= ~BM_DIRTY ;
130
+ bufHdr -> cntxDirty = false;
139
131
140
132
/*
141
133
* lazy memory allocation: allocate space on first use of a buffer.
@@ -189,50 +181,6 @@ WriteLocalBuffer(Buffer buffer, bool release)
189
181
return true;
190
182
}
191
183
192
- /*
193
- * FlushLocalBuffer -
194
- * flushes a local buffer
195
- */
196
- int
197
- FlushLocalBuffer (Buffer buffer , bool sync , bool release )
198
- {
199
- int bufid ;
200
- Relation bufrel ;
201
- BufferDesc * bufHdr ;
202
-
203
- Assert (BufferIsLocal (buffer ));
204
-
205
- #ifdef LBDEBUG
206
- fprintf (stderr , "LB FLUSH %d\n" , buffer );
207
- #endif
208
-
209
- bufid = - (buffer + 1 );
210
- bufHdr = & LocalBufferDescriptors [bufid ];
211
- bufHdr -> flags &= ~BM_DIRTY ;
212
- bufrel = RelationNodeCacheGetRelation (bufHdr -> tag .rnode );
213
- Assert (bufrel != NULL );
214
-
215
- if (sync )
216
- smgrflush (DEFAULT_SMGR , bufrel , bufHdr -> tag .blockNum ,
217
- (char * ) MAKE_PTR (bufHdr -> data ));
218
- else
219
- smgrwrite (DEFAULT_SMGR , bufrel , bufHdr -> tag .blockNum ,
220
- (char * ) MAKE_PTR (bufHdr -> data ));
221
-
222
- LocalBufferFlushCount ++ ;
223
-
224
- /* drop relcache refcount incremented by RelationNodeCacheGetRelation */
225
- RelationDecrementReferenceCount (bufrel );
226
-
227
- if (release )
228
- {
229
- Assert (LocalRefCount [bufid ] > 0 );
230
- LocalRefCount [bufid ]-- ;
231
- }
232
-
233
- return true;
234
- }
235
-
236
184
/*
237
185
* InitLocalBuffer -
238
186
* init the local buffer cache. Since most queries (esp. multi-user ones)
@@ -273,6 +221,9 @@ InitLocalBuffer(void)
273
221
* Flush all dirty buffers in the local buffer cache at commit time.
274
222
* Since the buffer cache is only used for keeping relations visible
275
223
* during a transaction, we will not need these buffers again.
224
+ *
225
+ * Note that we have to *flush* local buffers because of them are not
226
+ * visible to checkpoint makers. But we can skip XLOG flush check.
276
227
*/
277
228
void
278
229
LocalBufferSync (void )
@@ -284,7 +235,7 @@ LocalBufferSync(void)
284
235
BufferDesc * buf = & LocalBufferDescriptors [i ];
285
236
Relation bufrel ;
286
237
287
- if (buf -> flags & BM_DIRTY )
238
+ if (buf -> flags & BM_DIRTY || buf -> cntxDirty )
288
239
{
289
240
#ifdef LBDEBUG
290
241
fprintf (stderr , "LB SYNC %d\n" , - i - 1 );
@@ -295,12 +246,14 @@ LocalBufferSync(void)
295
246
296
247
smgrwrite (DEFAULT_SMGR , bufrel , buf -> tag .blockNum ,
297
248
(char * ) MAKE_PTR (buf -> data ));
249
+ smgrmarkdirty (DEFAULT_SMGR , bufrel , buf -> tag .blockNum );
298
250
LocalBufferFlushCount ++ ;
299
251
300
252
/* drop relcache refcount from RelationIdCacheGetRelation */
301
253
RelationDecrementReferenceCount (bufrel );
302
254
303
255
buf -> flags &= ~BM_DIRTY ;
256
+ buf -> cntxDirty = false;
304
257
}
305
258
}
306
259
@@ -319,10 +272,9 @@ ResetLocalBufferPool(void)
319
272
320
273
buf -> tag .rnode .relNode = InvalidOid ;
321
274
buf -> flags &= ~BM_DIRTY ;
275
+ buf -> cntxDirty = false;
322
276
}
323
277
324
278
MemSet (LocalRefCount , 0 , sizeof (long ) * NLocBuffer );
325
279
nextFreeLocalBuf = 0 ;
326
280
}
327
-
328
- #endif /* XLOG */
0 commit comments