6
6
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
7
7
* Portions Copyright (c) 1994, Regents of the University of California
8
8
*
9
- * $PostgreSQL: pgsql/src/backend/access/transam/xlogutils.c,v 1.28 2003/12/14 00:34:47 neilc Exp $
9
+ * $PostgreSQL: pgsql/src/backend/access/transam/xlogutils.c,v 1.29 2004/02/10 01:55:24 tgl Exp $
10
10
*
11
11
*-------------------------------------------------------------------------
12
12
*/
@@ -261,14 +261,12 @@ _xl_remove_hash_entry(XLogRelDesc *rdesc)
261
261
if (hentry == NULL )
262
262
elog (PANIC ,"_xl_remove_hash_entry: file was not found in cache" );
263
263
264
- if (rdesc -> reldata .rd_fd >= 0 )
265
- smgrclose (DEFAULT_SMGR , & ( rdesc -> reldata ) );
264
+ if (rdesc -> reldata .rd_smgr != NULL )
265
+ smgrclose (rdesc -> reldata . rd_smgr );
266
266
267
267
memset (rdesc ,0 ,sizeof (XLogRelDesc ));
268
268
memset (tpgc ,0 ,sizeof (FormData_pg_class ));
269
269
rdesc -> reldata .rd_rel = tpgc ;
270
-
271
- return ;
272
270
}
273
271
274
272
static XLogRelDesc *
@@ -296,7 +294,6 @@ _xl_new_reldesc(void)
296
294
void
297
295
XLogInitRelationCache (void )
298
296
{
299
- CreateDummyCaches ();
300
297
_xl_init_rel_cache ();
301
298
}
302
299
@@ -306,8 +303,6 @@ XLogCloseRelationCache(void)
306
303
HASH_SEQ_STATUS status ;
307
304
XLogRelCacheEntry * hentry ;
308
305
309
- DestroyDummyCaches ();
310
-
311
306
if (!_xlrelarr )
312
307
return ;
313
308
@@ -347,11 +342,18 @@ XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode)
347
342
348
343
sprintf (RelationGetRelationName (& (res -> reldata )),"%u" ,rnode .relNode );
349
344
350
- /* unexisting DB id */
351
- res -> reldata .rd_lockInfo .lockRelId .dbId = RecoveryDb ;
352
- res -> reldata .rd_lockInfo .lockRelId .relId = rnode .relNode ;
353
345
res -> reldata .rd_node = rnode ;
354
346
347
+ /*
348
+ * We set up the lockRelId in case anything tries to lock the dummy
349
+ * relation. Note that this is fairly bogus since relNode may be
350
+ * different from the relation's OID. It shouldn't really matter
351
+ * though, since we are presumably running by ourselves and can't
352
+ * have any lock conflicts ...
353
+ */
354
+ res -> reldata .rd_lockInfo .lockRelId .dbId = rnode .tblNode ;
355
+ res -> reldata .rd_lockInfo .lockRelId .relId = rnode .relNode ;
356
+
355
357
hentry = (XLogRelCacheEntry * )
356
358
hash_search (_xlrelcache , (void * )& rnode ,HASH_ENTER ,& found );
357
359
@@ -364,18 +366,23 @@ XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode)
364
366
hentry -> rdesc = res ;
365
367
366
368
res -> reldata .rd_targblock = InvalidBlockNumber ;
367
- res -> reldata .rd_fd = -1 ;
368
- res -> reldata .rd_fd = smgropen (DEFAULT_SMGR ,& (res -> reldata ),
369
- true/* allow failure */ );
369
+ res -> reldata .rd_smgr = smgropen (res -> reldata .rd_node );
370
+ /*
371
+ * Create the target file if it doesn't already exist. This lets
372
+ * us cope if the replay sequence contains writes to a relation
373
+ * that is later deleted. (The original coding of this routine
374
+ * would instead return NULL, causing the writes to be suppressed.
375
+ * But that seems like it risks losing valuable data if the filesystem
376
+ * loses an inode during a crash. Better to write the data until we
377
+ * are actually told to delete the file.)
378
+ */
379
+ smgrcreate (res -> reldata .rd_smgr ,res -> reldata .rd_istemp , true);
370
380
}
371
381
372
382
res -> moreRecently = & (_xlrelarr [0 ]);
373
383
res -> lessRecently = _xlrelarr [0 ].lessRecently ;
374
384
_xlrelarr [0 ].lessRecently = res ;
375
385
res -> lessRecently -> moreRecently = res ;
376
386
377
- if (res -> reldata .rd_fd < 0 )/* file doesn't exist */
378
- return (NULL );
379
-
380
387
return (& (res -> reldata ));
381
388
}