From a82b7d9b41181e6f391a204adb70cbef292e9e15 Mon Sep 17 00:00:00 2001 From: CookiePieWw Date: Thu, 26 Dec 2024 15:04:06 +0800 Subject: [PATCH] chore: follow review comments --- src/common/meta/src/kv_backend/postgres.rs | 7 ++++++- src/meta-srv/src/bootstrap.rs | 9 +++++---- src/meta-srv/src/election/postgres.rs | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/common/meta/src/kv_backend/postgres.rs b/src/common/meta/src/kv_backend/postgres.rs index 8add65cd49c4..f67f527871ea 100644 --- a/src/common/meta/src/kv_backend/postgres.rs +++ b/src/common/meta/src/kv_backend/postgres.rs @@ -16,6 +16,7 @@ use std::any::Any; use std::borrow::Cow; use std::sync::Arc; +use common_telemetry::error; use snafu::ResultExt; use tokio_postgres::types::ToSql; use tokio_postgres::{Client, NoTls}; @@ -97,7 +98,11 @@ impl PgStore { let (client, conn) = tokio_postgres::connect(url, NoTls) .await .context(ConnectPostgresSnafu)?; - tokio::spawn(async move { conn.await.context(ConnectPostgresSnafu) }); + tokio::spawn(async move { + if let Err(e) = conn.await { + error!(e; "connection error"); + } + }); Self::with_pg_client(client).await } diff --git a/src/meta-srv/src/bootstrap.rs b/src/meta-srv/src/bootstrap.rs index 3dfa03d66774..b4408db7acde 100644 --- a/src/meta-srv/src/bootstrap.rs +++ b/src/meta-srv/src/bootstrap.rs @@ -26,6 +26,8 @@ use common_meta::kv_backend::memory::MemoryKvBackend; #[cfg(feature = "pg_kvbackend")] use common_meta::kv_backend::postgres::PgStore; use common_meta::kv_backend::{KvBackendRef, ResettableKvBackendRef}; +#[cfg(feature = "pg_kvbackend")] +use common_telemetry::error; use common_telemetry::info; use etcd_client::Client; use futures::future; @@ -281,10 +283,9 @@ async fn create_postgres_client(opts: &MetasrvOptions) -> Result ts, @@ -238,7 +239,7 @@ impl PgElection { } .fail()?, }; - + // Safety: Checked if res is empty above. let value_and_expire_time = res[0].get(0); let (value, expire_time) = parse_value_and_expire_time(value_and_expire_time)?;