File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed
Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -509,7 +509,6 @@ func (pgw *PostgresWriter) DeleteOldPartitions() {
509509func (pgw * PostgresWriter ) MaintainUniqueSources () {
510510 logger := log .GetLogger (pgw .ctx )
511511
512- sqlGetAdvisoryLock := `SELECT pg_try_advisory_lock(1571543679778230000) AS have_lock` // 1571543679778230000 is just a random bigint
513512 sqlTopLevelMetrics := `SELECT table_name FROM admin.get_top_level_metric_tables()`
514513 sqlDistinct := `
515514 WITH RECURSIVE t(dbname) AS (
@@ -528,13 +527,13 @@ func (pgw *PostgresWriter) MaintainUniqueSources() {
528527 RETURNING *`
529528
530529 var lock bool
531- logger .Infof ("Trying to get admin.all_distinct_dbname_metrics maintainer advisory lock..." ) // to only have one "maintainer" in case of a "push" setup, as can get costly
532- if err := pgw .sinkDb .QueryRow (pgw .ctx , sqlGetAdvisoryLock ).Scan (& lock ); err != nil {
533- logger .Error ("Getting admin.all_distinct_dbname_metrics maintainer advisory lock failed:" , err )
530+ logger .Infof ("Trying to get maintenance advisory lock..." ) // to only have one "maintainer" in case of a "push" setup, as can get costly
531+ if err := pgw .sinkDb .QueryRow (pgw .ctx , "SELECT admin.try_get_maintenance_lock();" ).Scan (& lock ); err != nil {
532+ logger .Error ("Getting maintenance advisory lock failed:" , err )
534533 return
535534 }
536535 if ! lock {
537- logger .Info ("Skipping admin.all_distinct_dbname_metrics maintenance as another instance has the advisory lock..." )
536+ logger .Info ("Skipping maintenance as another instance has the advisory lock..." )
538537 return
539538 }
540539
Original file line number Diff line number Diff line change @@ -139,3 +139,14 @@ BEGIN
139139 RETURN i;
140140END;
141141$SQL$ LANGUAGE plpgsql;
142+
143+ CREATE OR REPLACE FUNCTION admin .try_get_maintenance_lock(
144+ OUT have_lock BOOLEAN
145+ )
146+ AS
147+ $SQL$
148+ BEGIN
149+ -- 1571543679778230000 is just a random bigint
150+ SELECT pg_try_advisory_lock(1571543679778230000 ) INTO have_lock;
151+ END;
152+ $SQL$ LANGUAGE plpgsql;
You can’t perform that action at this time.
0 commit comments