You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by za...@apache.org on 2021/11/08 14:21:56 UTC

[hive] branch master updated: HIVE-25675: Intermittent PSQLException when trying to connect to Postgres in tests (Stamatis Zampetakis, reviewed by Peter Vary)

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

zabetak pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/master by this push:
     new a72db99  HIVE-25675: Intermittent PSQLException when trying to connect to Postgres in tests (Stamatis Zampetakis, reviewed by Peter Vary)
a72db99 is described below

commit a72db99676ca6a79b414906ab78963a3e955ae69
Author: Stamatis Zampetakis <za...@gmail.com>
AuthorDate: Fri Nov 5 14:50:29 2021 +0100

    HIVE-25675: Intermittent PSQLException when trying to connect to Postgres in tests (Stamatis Zampetakis, reviewed by Peter Vary)
    
    Sometimes when we try to connect to Postgres, the database is not yet
    completely ready despite the fact that the respective port is open thus
    leading to the following exception.
    
    PSQLException: FATAL: the database system is starting up
    
    1. Ensure the database is ready by checking a certain message appears
    two times in the logs.
    2. Remove the now unused logger.
    
    Closes #2767
---
 .../hive/ql/externalDB/PostgresExternalDB.java      | 16 ++--------------
 .../hive/metastore/dbinstall/rules/Postgres.java    | 21 ++-------------------
 2 files changed, 4 insertions(+), 33 deletions(-)

diff --git a/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/PostgresExternalDB.java b/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/PostgresExternalDB.java
index eaa427b..8f118d6 100644
--- a/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/PostgresExternalDB.java
+++ b/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/PostgresExternalDB.java
@@ -17,10 +17,6 @@
  */
 package org.apache.hadoop.hive.ql.externalDB;
 
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-
 /**
  * MySQLExternalDB is a extension of abstractExternalDB
  * Designed for MySQL external database connection
@@ -52,16 +48,8 @@ public class PostgresExternalDB extends AbstractExternalDB {
     }
 
     public boolean isContainerReady(ProcessResults pr) {
-        if (pr.stdout.contains("PostgreSQL init process complete; ready for start up")) {
-            try (Socket socket = new Socket()) {
-                socket.connect(new InetSocketAddress(getContainerHostAddress(), 5432), 1000);
-                return true;
-            } catch (IOException e) {
-                LOG.info("cant connect to postgres; {}", e.getMessage());
-                return false;
-            }
-        }
-        return false;
+        return pr.stdout.contains("database system is ready to accept connections") &&
+            pr.stderr.contains("database system is ready to accept connections");
     }
 
 }
\ No newline at end of file
diff --git a/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/Postgres.java b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/Postgres.java
index dc43fb0..eda1f97 100644
--- a/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/Postgres.java
+++ b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/Postgres.java
@@ -17,19 +17,10 @@
  */
 package org.apache.hadoop.hive.metastore.dbinstall.rules;
 
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 /**
  * JUnit TestRule for Postgres.
  */
 public class Postgres extends DatabaseRule {
-  private static final Logger LOG = LoggerFactory.getLogger(Postgres.class);
-
   @Override
   public String getDockerImageName() {
     return "postgres:11.6";
@@ -72,16 +63,8 @@ public class Postgres extends DatabaseRule {
 
   @Override
   public boolean isContainerReady(ProcessResults pr) {
-    if (pr.stdout.contains("PostgreSQL init process complete; ready for start up")) {
-      try (Socket socket = new Socket()) {
-        socket.connect(new InetSocketAddress(getContainerHostAddress(), 5432), 1000);
-        return true;
-      } catch (IOException e) {
-        LOG.info("cant connect to postgres; {}", e.getMessage());
-        return false;
-      }
-    }
-    return false;
+    return pr.stdout.contains("database system is ready to accept connections") &&
+        pr.stderr.contains("database system is ready to accept connections");
   }
 
   @Override