From 3ed989039f0635493c3c79ebf3b3205e6b0cb85c Mon Sep 17 00:00:00 2001 From: "Lei, HUANG" Date: Tue, 9 Jan 2024 04:03:21 +0000 Subject: [PATCH] fix: resolve review comments --- Cargo.lock | 1 + src/log-store/Cargo.toml | 1 + src/log-store/src/raft_engine/log_store.rs | 14 +++++--------- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 97e7f48e922e..2e32a7c8707c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4505,6 +4505,7 @@ dependencies = [ "common-runtime", "common-telemetry", "common-test-util", + "common-time", "dashmap", "futures", "futures-util", diff --git a/src/log-store/Cargo.toml b/src/log-store/Cargo.toml index 7941cd11e918..d9a3d62d8e0e 100644 --- a/src/log-store/Cargo.toml +++ b/src/log-store/Cargo.toml @@ -21,6 +21,7 @@ common-macro.workspace = true common-meta.workspace = true common-runtime.workspace = true common-telemetry.workspace = true +common-time.workspace = true dashmap.workspace = true futures-util.workspace = true futures.workspace = true diff --git a/src/log-store/src/raft_engine/log_store.rs b/src/log-store/src/raft_engine/log_store.rs index 0f0ef6bb17f8..df44cb528faa 100644 --- a/src/log-store/src/raft_engine/log_store.rs +++ b/src/log-store/src/raft_engine/log_store.rs @@ -16,7 +16,6 @@ use std::collections::HashMap; use std::fmt::{Debug, Formatter}; use std::sync::atomic::{AtomicI64, Ordering}; use std::sync::Arc; -use std::time::{SystemTime, UNIX_EPOCH}; use async_stream::stream; use common_config::wal::{RaftEngineConfig, WalOptions}; @@ -217,14 +216,11 @@ impl LogStore for RaftEngineLogStore { } let mut sync = self.config.sync_write; - if let Some(sync_period) = self.config.sync_period.as_ref() - && let Ok(now) = SystemTime::now().duration_since(UNIX_EPOCH) - { - let now_millis = now.as_millis() as i64; - if now_millis - self.last_sync_time.load(Ordering::Relaxed) - >= sync_period.as_millis() as i64 - { - self.last_sync_time.store(now_millis, Ordering::Relaxed); + + if let Some(sync_period) = self.config.sync_period.as_ref() { + let now = common_time::util::current_time_millis(); + if now - self.last_sync_time.load(Ordering::Relaxed) >= sync_period.as_millis() as i64 { + self.last_sync_time.store(now, Ordering::Relaxed); sync = true; } }