aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-06-08 23:55:48 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-06-08 23:55:48 +0000
commit1358466a8c918f14f48ea60d60db96ae7eba5045 (patch)
tree28e6e889c53f65063228c1f5736ca91415901549
parente4725e35be7b36ae3c21c6f5d94bb3fb4afede67 (diff)
downloadpostgresql-1358466a8c918f14f48ea60d60db96ae7eba5045.tar.gz
postgresql-1358466a8c918f14f48ea60d60db96ae7eba5045.zip
Fix bootstrap.c so that database startup process and bgwriter properly release
LWLocks during a panic exit. This avoids the possible self-deadlock pointed out by Qingqing Zhou. Also, I noted that an error during LoadFreeSpaceMap() or BuildFlatFiles() would result in exit(0) which would leave the postmaster thinking all is well. Added a critical section to ensure such errors don't allow startup to proceed. Backpatched to 8.1. The 8.0 code is a bit different and I'm not sure if the problem exists there; given we've not seen this reported from the field, I'm going to be conservative about backpatching any further.
-rw-r--r--src/backend/bootstrap/bootstrap.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index 5dfda5a427d..bc60d533ae4 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.215 2006/05/10 23:18:39 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.216 2006/06/08 23:55:48 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -55,6 +55,7 @@ extern char *optarg;
static void usage(void);
static void bootstrap_signals(void);
+static void ShutdownDummyProcess(int code, Datum arg);
static hashnode *AddStr(char *str, int strlength, int mderef);
static Form_pg_attribute AllocateAttribute(void);
static int CompHash(char *str, int len);
@@ -395,6 +396,9 @@ BootstrapMain(int argc, char *argv[])
/* finish setting up bufmgr.c */
InitBufferPoolBackend();
+
+ /* register a shutdown callback for LWLock cleanup */
+ on_shmem_exit(ShutdownDummyProcess, 0);
}
/*
@@ -417,8 +421,14 @@ BootstrapMain(int argc, char *argv[])
case BS_XLOG_STARTUP:
bootstrap_signals();
StartupXLOG();
+ /*
+ * These next two functions don't consider themselves critical,
+ * but we'd best PANIC anyway if they fail.
+ */
+ START_CRIT_SECTION();
LoadFreeSpaceMap();
BuildFlatFiles(false);
+ END_CRIT_SECTION();
proc_exit(0); /* startup done */
case BS_XLOG_BGWRITER:
@@ -552,6 +562,19 @@ bootstrap_signals(void)
}
}
+/*
+ * Begin shutdown of a dummy process. This is approximately the equivalent
+ * of ShutdownPostgres() in postinit.c. We can't run transactions in a
+ * dummy process, so most of the work of AbortTransaction() is not needed,
+ * but we do need to make sure we've released any LWLocks we are holding.
+ * (This is only critical during an error exit.)
+ */
+static void
+ShutdownDummyProcess(int code, Datum arg)
+{
+ LWLockReleaseAll();
+}
+
/* ----------------
* error handling / abort routines
* ----------------