Fix bogus hashtable setup. (This code has quite a few other problems

too, but that one is in my way at the moment.)
This commit is contained in:
Tom Lane 2005-05-05 22:18:27 +00:00
parent c2e729fa20
commit 6f1ca7e457
1 changed files with 15 additions and 35 deletions

View File

@ -1,7 +1,7 @@
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* checkfiles.c * checkfiles.c
* support to clean up stale relation files on crash recovery * check for stale relation files during crash recovery
* *
* If a backend crashes while in a transaction that has created or * If a backend crashes while in a transaction that has created or
* deleted a relfilenode, a stale file can be left over in the data * deleted a relfilenode, a stale file can be left over in the data
@ -14,24 +14,24 @@
* files, and use the 'dirty' flag to determine if we should run this on * files, and use the 'dirty' flag to determine if we should run this on
* a clean startup. * a clean startup.
* *
* $PostgreSQL: pgsql/src/backend/utils/init/checkfiles.c,v 1.1 2005/05/02 18:26:53 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/init/checkfiles.c,v 1.2 2005/05/05 22:18:27 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres.h" #include "postgres.h"
#include "storage/fd.h"
#include "utils/flatfiles.h"
#include "miscadmin.h"
#include "catalog/pg_tablespace.h"
#include "catalog/catalog.h"
#include "access/skey.h"
#include "utils/fmgroids.h"
#include "access/relscan.h"
#include "access/heapam.h" #include "access/heapam.h"
#include "access/relscan.h"
#include "access/skey.h"
#include "catalog/catalog.h"
#include "catalog/pg_tablespace.h"
#include "miscadmin.h"
#include "storage/fd.h"
#include "utils/flatfiles.h"
#include "utils/fmgroids.h"
#include "utils/resowner.h" #include "utils/resowner.h"
static void CheckStaleRelFilesFrom(Oid tablespaceoid, Oid dboid); static void CheckStaleRelFilesFrom(Oid tablespaceoid, Oid dboid);
static void CheckStaleRelFilesFromTablespace(Oid tablespaceoid); static void CheckStaleRelFilesFromTablespace(Oid tablespaceoid);
@ -52,11 +52,6 @@ AllocateDirChecked(char *path)
/* /*
* Scan through all tablespaces for relations left over * Scan through all tablespaces for relations left over
* by aborted transactions. * by aborted transactions.
*
* For example, if a transaction issues
* BEGIN; CREATE TABLE foobar ();
* and then the backend crashes, the file is left in the
* tablespace until CheckStaleRelFiles deletes it.
*/ */
void void
CheckStaleRelFiles(void) CheckStaleRelFiles(void)
@ -125,31 +120,18 @@ CheckStaleRelFilesFrom(Oid tablespaceoid, Oid dboid)
struct dirent *de; struct dirent *de;
HASHCTL hashctl; HASHCTL hashctl;
HTAB *relfilenodeHash; HTAB *relfilenodeHash;
MemoryContext mcxt;
RelFileNode rnode; RelFileNode rnode;
char *path; char *path;
/*
* We create a private memory context so that we can easily deallocate the
* hash table and its contents
*/
mcxt = AllocSetContextCreate(TopMemoryContext, "CheckStaleRelFiles",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
hashctl.hash = tag_hash;
/* /*
* The entry contents is not used for anything, we just check if an oid is * The entry contents is not used for anything, we just check if an oid is
* in the hash table or not. * in the hash table or not.
*/ */
hashctl.keysize = sizeof(Oid); hashctl.keysize = sizeof(Oid);
hashctl.entrysize = 1; hashctl.entrysize = sizeof(Oid);
hashctl.hcxt = mcxt; hashctl.hash = tag_hash;
relfilenodeHash = hash_create("relfilenodeHash", 100, &hashctl, relfilenodeHash = hash_create("relfilenodeHash", 100, &hashctl,
HASH_FUNCTION HASH_FUNCTION | HASH_ELEM);
| HASH_ELEM | HASH_CONTEXT);
/* Read all relfilenodes from pg_class into the hash table */ /* Read all relfilenodes from pg_class into the hash table */
{ {
@ -209,10 +191,9 @@ CheckStaleRelFilesFrom(Oid tablespaceoid, Oid dboid)
rnode.relNode = relfilenode; rnode.relNode = relfilenode;
filepath = relpath(rnode); filepath = relpath(rnode);
ereport(LOG, ereport(LOG,
(errcode_for_file_access(), (errcode_for_file_access(),
errmsg("The table or index file \"%s\" is stale and can be safely removed", errmsg("table or index file \"%s\" is stale and can safely be removed",
filepath))); filepath)));
pfree(filepath); pfree(filepath);
} }
@ -221,5 +202,4 @@ CheckStaleRelFilesFrom(Oid tablespaceoid, Oid dboid)
FreeDir(dirdesc); FreeDir(dirdesc);
pfree(path); pfree(path);
hash_destroy(relfilenodeHash); hash_destroy(relfilenodeHash);
MemoryContextDelete(mcxt);
} }