v9-0001-Create-a-helper-function-for-determining-the-log-.patch

application/octet-stream

Filename: v9-0001-Create-a-helper-function-for-determining-the-log-.patch
Type: application/octet-stream
Part: 6
Message: Re: Add SKIP LOCKED to VACUUM and ANALYZE

Patch

Format: format-patch
Series: patch v9-0001
Subject: Create a helper function for determining the log level for skipped relations.
File+
src/backend/commands/analyze.c 14 31
src/backend/commands/vacuum.c 31 22
src/include/commands/vacuum.h 1 0
From d9ea645ec9eb948e37fe60596872a6715f720126 Mon Sep 17 00:00:00 2001
From: Nathan Bossart <bossartn@amazon.com>
Date: Wed, 5 Sep 2018 14:42:22 +0000
Subject: [PATCH v9 1/7] Create a helper function for determining the log level
 for skipped relations.

---
 src/backend/commands/analyze.c | 45 +++++++++++------------------------
 src/backend/commands/vacuum.c  | 53 ++++++++++++++++++++++++------------------
 src/include/commands/vacuum.h  |  1 +
 3 files changed, 46 insertions(+), 53 deletions(-)

diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index edbdce81f2..b6b78527f4 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -159,38 +159,21 @@ analyze_rel(Oid relid, RangeVar *relation, int options,
 	 */
 	if (!onerel)
 	{
-		/*
-		 * If the RangeVar is not defined, we do not have enough information
-		 * to provide a meaningful log statement.  Chances are that
-		 * analyze_rel's caller has intentionally not provided this
-		 * information so that this logging is skipped, anyway.
-		 */
-		if (relation == NULL)
-			return;
-
-		/*
-		 * Determine the log level.  For autovacuum logs, we emit a LOG if
-		 * log_autovacuum_min_duration is not disabled.  For manual ANALYZE,
-		 * we emit a WARNING to match the log statements in the permissions
-		 * checks.
-		 */
-		if (!IsAutoVacuumWorkerProcess())
-			elevel = WARNING;
-		else if (params->log_min_duration >= 0)
-			elevel = LOG;
-		else
-			return;
+		elevel = get_elevel_for_skipped_relation(relation, params);
 
-		if (!rel_lock)
-			ereport(elevel,
-					(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
-					 errmsg("skipping analyze of \"%s\" --- lock not available",
-							relation->relname)));
-		else
-			ereport(elevel,
-					(errcode(ERRCODE_UNDEFINED_TABLE),
-					 errmsg("skipping analyze of \"%s\" --- relation no longer exists",
-							relation->relname)));
+		if (elevel != 0)
+		{
+			if (!rel_lock)
+				ereport(elevel,
+						(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
+						 errmsg("skipping analyze of \"%s\" --- lock not available",
+								relation->relname)));
+			else
+				ereport(elevel,
+						(errcode(ERRCODE_UNDEFINED_TABLE),
+						 errmsg("skipping analyze of \"%s\" --- relation no longer exists",
+								relation->relname)));
+		}
 
 		return;
 	}
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index f166509734..fc1081663c 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -1480,28 +1480,7 @@ vacuum_rel(Oid relid, RangeVar *relation, int options, VacuumParams *params)
 	 */
 	if (!onerel)
 	{
-		int			elevel = 0;
-
-		/*
-		 * Determine the log level.
-		 *
-		 * If the RangeVar is not defined, we do not have enough information
-		 * to provide a meaningful log statement.  Chances are that
-		 * vacuum_rel's caller has intentionally not provided this information
-		 * so that this logging is skipped, anyway.
-		 *
-		 * Otherwise, for autovacuum logs, we emit a LOG if
-		 * log_autovacuum_min_duration is not disabled.  For manual VACUUM, we
-		 * emit a WARNING to match the log statements in the permission
-		 * checks.
-		 */
-		if (relation != NULL)
-		{
-			if (!IsAutoVacuumWorkerProcess())
-				elevel = WARNING;
-			else if (params->log_min_duration >= 0)
-				elevel = LOG;
-		}
+		int			elevel = get_elevel_for_skipped_relation(relation, params);
 
 		if (elevel != 0)
 		{
@@ -1779,3 +1758,33 @@ vacuum_delay_point(void)
 		CHECK_FOR_INTERRUPTS();
 	}
 }
+
+/*
+ * get_elevel_for_skipped_relation
+ *
+ * This is a helper function for determining the appropriate logging level for
+ * messages related to SKIP_LOCKED or concurrently dropped relations.
+ *
+ * If the RangeVar is not defined, we do not have enough information to provide
+ * a meaningful log statement, and 0 is returned.  Chances are that the caller
+ * has intentionally not provided this information so that the logging is
+ * skipped anyway.
+ *
+ * Otherwise, for autovacuum logs, we emit a LOG if log_autovacuum_min_duration
+ * is not disabled.  For manual commands, we emit a WARNING to match the log
+ * statements in the permission checks for VACUUM and ANALYZE.
+ */
+int
+get_elevel_for_skipped_relation(RangeVar *relation, VacuumParams *params)
+{
+	Assert(params != NULL);
+
+	if (relation == NULL)
+		return 0;
+	else if (!IsAutoVacuumWorkerProcess())
+		return WARNING;
+	else if (params->log_min_duration >= 0)
+		return LOG;
+	else
+		return 0;
+}
diff --git a/src/include/commands/vacuum.h b/src/include/commands/vacuum.h
index 5af96fdc8a..3cf7559728 100644
--- a/src/include/commands/vacuum.h
+++ b/src/include/commands/vacuum.h
@@ -188,6 +188,7 @@ extern void vac_update_datfrozenxid(void);
 extern void vacuum_delay_point(void);
 extern bool vacuum_is_relation_owner(Oid relid, Form_pg_class reltuple,
 						 int options);
+extern int	get_elevel_for_skipped_relation(RangeVar *relation, VacuumParams *params);
 
 /* in commands/vacuumlazy.c */
 extern void lazy_vacuum_rel(Relation onerel, int options,
-- 
2.16.2