Skip to content

Commit

Permalink
Merge pull request ClickHouse#57515 from ClickHouse/fix-materialized-…
Browse files Browse the repository at this point in the history
…pg-issue-with-incorrect-connection-options

MaterializedPostgreSQL: fix issue ClickHouse#41922, add test for ClickHouse#41923
  • Loading branch information
kssenii authored Dec 7, 2023
2 parents 0159a4d + e02883c commit b3f2244
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/Storages/PostgreSQL/PostgreSQLReplicationHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,11 +714,9 @@ void PostgreSQLReplicationHandler::shutdownFinal()
dropReplicationSlot(tx, /* temporary */false);
});
}
catch (Exception & e)
catch (...)
{
e.addMessage("while dropping replication slot: {}", replication_slot);
LOG_ERROR(log, "Failed to drop replication slot: {}. It must be dropped manually.", replication_slot);
throw;
LOG_ERROR(log, "Failed to drop replication slot: {}. It must be dropped manually. Error: {}", replication_slot, getCurrentExceptionMessage(true));
}
}

Expand Down
4 changes: 3 additions & 1 deletion tests/integration/helpers/postgres_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,14 @@ def create_materialized_db(
postgres_database="",
settings=[],
table_overrides="",
user="postgres",
password="mysecretpassword",
):
postgres_database = self.database_or_default(postgres_database)
self.created_materialized_postgres_db_list.add(materialized_database)
self.instance.query(f"DROP DATABASE IF EXISTS {materialized_database}")

create_query = f"CREATE DATABASE {materialized_database} ENGINE = MaterializedPostgreSQL('{ip}:{port}', '{postgres_database}', 'postgres', 'mysecretpassword')"
create_query = f"CREATE DATABASE {materialized_database} ENGINE = MaterializedPostgreSQL('{ip}:{port}', '{postgres_database}', '{user}', '{password}')"
if len(settings) > 0:
create_query += " SETTINGS "
for i in range(len(settings)):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,35 @@ def test_replica_consumer(started_cluster):
pg_manager_instance2.clear()


def test_bad_connection_options(started_cluster):
table = "test_bad_connection_options"

pg_manager.create_postgres_table(table)
instance.query(
f"INSERT INTO postgres_database.{table} SELECT number, number from numbers(0, 50)"
)

pg_manager.create_materialized_db(
ip=started_cluster.postgres_ip,
port=started_cluster.postgres_port,
settings=[
f"materialized_postgresql_tables_list = '{table}'",
"materialized_postgresql_backoff_min_ms = 100",
"materialized_postgresql_backoff_max_ms = 100",
],
user="postrges",
password="kek",
)

instance.wait_for_log_line('role "postrges" does not exist')
assert instance.contains_in_log(
"<Error> void DB::DatabaseMaterializedPostgreSQL::startSynchronization(): std::exception. Code: 1001, type: pqxx::broken_connection"
)
assert "test_database" in instance.query("SHOW DATABASES")
assert "" == instance.query("show tables from test_database").strip()
pg_manager.drop_materialized_db("test_database")


if __name__ == "__main__":
cluster.start()
input("Cluster created, press any key to destroy...")
Expand Down

0 comments on commit b3f2244

Please sign in to comment.