You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by ch...@apache.org on 2025/10/22 13:10:24 UTC

(cloudberry) branch cbdb-postgres-merge updated: Fix issues for Latch

This is an automated email from the ASF dual-hosted git repository.

chenjinbao1989 pushed a commit to branch cbdb-postgres-merge
in repository https://gitbox.apache.org/repos/asf/cloudberry.git


The following commit(s) were added to refs/heads/cbdb-postgres-merge by this push:
     new 7536c99911d Fix issues for Latch
7536c99911d is described below

commit 7536c99911da7736990e8669864af4b1c6120d60
Author: Jinbao Chen <ch...@gmail.com>
AuthorDate: Wed Oct 22 21:10:06 2025 +0800

    Fix issues for Latch
---
 src/backend/access/transam/xlog.c |  2 +-
 src/backend/commands/dbcommands.c | 49 ++-------------------------------------
 src/backend/storage/ipc/latch.c   | 21 ++++++++++++++++-
 3 files changed, 23 insertions(+), 49 deletions(-)

diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index cd2a517baf5..30eab6de880 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -7209,7 +7209,7 @@ CreateCheckPoint(int flags)
 		{
 			AbsorbSyncRequests();
 			pg_usleep(10000L);	/* wait for 10 msec */
-		} while (HaveVirtualXIDsDelayingChkpt(vxids, nvxids));
+		} while (HaveVirtualXIDsDelayingChkptEnd(vxids, nvxids));
 	}
 	pfree(vxids);
 
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 225d505ccba..08811b87929 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -1682,11 +1682,7 @@ dropdb(const char *dbname, bool missing_ok, bool force)
 	Oid			db_id = InvalidOid;
 	bool		db_istemplate = true;
 	Relation	pgdbrel;
-	HeapTuple	tup;
-	ScanKeyData scankey;
-	void	   *inplace_state;
-	Form_pg_database datform;
-	int			notherbackends;
+	HeapTuple	tup;	int			notherbackends;
 	int			npreparedxacts;
 	int			nslots,
 				nslots_active;
@@ -1854,7 +1850,7 @@ dropdb(const char *dbname, bool missing_ok, bool force)
 	 */
 	DeleteSharedComments(db_id, DatabaseRelationId);
 	DeleteSharedSecurityLabel(db_id, DatabaseRelationId);
-	
+
 	/*
 	 * Delete any tag description and associated dependencies.
 	 */
@@ -1872,42 +1868,6 @@ dropdb(const char *dbname, bool missing_ok, bool force)
 	 */
 	dropDatabaseDependencies(db_id);
 
-	/*
-	 * Tell the cumulative stats system to forget it immediately, too.
-	 */
-	pgstat_drop_database(db_id);
-
-	/*
-	 * Except for the deletion of the catalog row, subsequent actions are not
-	 * transactional (consider DropDatabaseBuffers() discarding modified
-	 * buffers). But we might crash or get interrupted below. To prevent
-	 * accesses to a database with invalid contents, mark the database as
-	 * invalid using an in-place update.
-	 *
-	 * We need to flush the WAL before continuing, to guarantee the
-	 * modification is durable before performing irreversible filesystem
-	 * operations.
-	 */
-	ScanKeyInit(&scankey,
-				Anum_pg_database_datname,
-				BTEqualStrategyNumber, F_NAMEEQ,
-				CStringGetDatum(dbname));
-	systable_inplace_update_begin(pgdbrel, DatabaseNameIndexId, true,
-								  NULL, 1, &scankey, &tup, &inplace_state);
-	if (!HeapTupleIsValid(tup))
-		elog(ERROR, "cache lookup failed for database %u", db_id);
-	datform = (Form_pg_database) GETSTRUCT(tup);
-	datform->datconnlimit = DATCONNLIMIT_INVALID_DB;
-	systable_inplace_update_finish(inplace_state, tup);
-	XLogFlush(XactLastRecEnd);
-
-	/*
-	 * Also delete the tuple - transactionally. If this transaction commits,
-	 * the row will be gone, but if we fail, dropdb() can be invoked again.
-	 */
-	CatalogTupleDelete(pgdbrel, &tup->t_self);
-	heap_freetuple(tup);
-
 	/*
 	 * Drop db-specific replication slots.
 	 */
@@ -1924,11 +1884,6 @@ dropdb(const char *dbname, bool missing_ok, bool force)
 	if (Gp_role == GP_ROLE_DISPATCH)
 		MetaTrackDropObject(DatabaseRelationId, db_id);
 
-	/*
-	 * Tell the stats collector to forget it immediately, too.
-	 */
-	pgstat_drop_database(db_id);
-
 	/*
 	 * Tell checkpointer to forget any pending fsync and unlink requests for
 	 * files in the database; else the fsyncs will fail at next checkpoint, or
diff --git a/src/backend/storage/ipc/latch.c b/src/backend/storage/ipc/latch.c
index 061f91b888e..76cc45941a2 100644
--- a/src/backend/storage/ipc/latch.c
+++ b/src/backend/storage/ipc/latch.c
@@ -72,7 +72,7 @@
 #if defined(WAIT_USE_EPOLL) || defined(WAIT_USE_POLL) || \
 	defined(WAIT_USE_KQUEUE) || defined(WAIT_USE_WIN32)
 /* don't overwrite manual choice */
-#elif defined(HAVE_SYS_EPOLL_H) && defined(HAVE_SYS_SIGNALFD_H)
+#elif defined(HAVE_SYS_EPOLL_H)
 #define WAIT_USE_EPOLL
 #elif defined(HAVE_KQUEUE)
 #define WAIT_USE_KQUEUE
@@ -84,6 +84,22 @@
 #error "no wait set implementation available"
 #endif
 
+/*
+ * By default, we use a self-pipe with poll() and a signalfd with epoll(), if
+ * available.  We avoid signalfd on illumos for now based on problem reports.
+ * For testing the choice can also be manually specified.
+ */
+#if defined(WAIT_USE_POLL) || defined(WAIT_USE_EPOLL)
+#if defined(WAIT_USE_SELF_PIPE) || defined(WAIT_USE_SIGNALFD)
+/* don't overwrite manual choice */
+#elif defined(WAIT_USE_EPOLL) && defined(HAVE_SYS_SIGNALFD_H) && \
+	!defined(__illumos__)
+#define WAIT_USE_SIGNALFD
+#else
+#define WAIT_USE_SELF_PIPE
+#endif
+#endif
+
 /* typedef in latch.h */
 struct WaitEventSet
 {
@@ -1644,6 +1660,9 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,
 		if (cur_event->events == WL_LATCH_SET &&
 			cur_epoll_event->events & (EPOLLIN | EPOLLERR | EPOLLHUP))
 		{
+			/* Drain the signalfd. */
+			drain();
+
 			if (set->latch && set->latch->maybe_sleeping && set->latch->is_set)
 			{
 				occurred_events->fd = PGINVALID_SOCKET;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org