Skip to content

Commit

Permalink
chore: follow review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
CookiePieWw committed Dec 26, 2024
1 parent c03ab3c commit a82b7d9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/common/meta/src/kv_backend/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
}

Expand Down
9 changes: 5 additions & 4 deletions src/meta-srv/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -281,10 +283,9 @@ async fn create_postgres_client(opts: &MetasrvOptions) -> Result<tokio_postgres:
.context(error::ConnectPostgresSnafu)?;

tokio::spawn(async move {
connection
.await
.context(error::PostgresExecutionSnafu)
.unwrap()
if let Err(e) = connection.await {
error!(e; "connection error");
}
});
Ok(client)
}
3 changes: 2 additions & 1 deletion src/meta-srv/src/election/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ impl PgElection {
if res.is_empty() {
Ok(None)
} else {
// Safety: Checked if res is empty above.
let current_time_str = res[0].get(1);
let current_time = match Timestamp::from_str(current_time_str, None) {
Ok(ts) => ts,
Expand All @@ -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)?;

Expand Down

0 comments on commit a82b7d9

Please sign in to comment.