From dbcdfc426ed9f6f0da2f9dbcc267ef5030c81abf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Tue, 4 Jul 2023 09:07:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(hail):=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=86=B0=E9=9B=B9=E7=AE=97=E6=B3=95=E4=B8=AD=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E7=9A=84=E6=AD=BB=E9=94=81=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/serial_code/hail.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/serial_code/hail.rs b/src/serial_code/hail.rs index 6fcbb34..d349f78 100644 --- a/src/serial_code/hail.rs +++ b/src/serial_code/hail.rs @@ -69,13 +69,6 @@ impl HailSerialCodeAlgorithm { current_time - *HAIL_PERIOD_START } - /// 判断指定时间戳是否比已经存储的最后一次使用的时间戳要大。否则时间发生了回拨。 - fn validate_timestamp(&self, timestamp: i64) -> bool { - let last_timestamp = self.last_timestamp.clone(); - let last_timestamp = last_timestamp.lock().unwrap(); - timestamp >= *last_timestamp - } - /// 生成一个64位长整型序列ID。 pub fn generate_serial(&self) -> i64 { let last_timestamp = self.last_timestamp.clone(); @@ -93,7 +86,7 @@ impl HailSerialCodeAlgorithm { std::thread::sleep(time::Duration::from_secs(1)); continue; } - } else if !self.validate_timestamp(timestamp) { + } else if timestamp < *last_timestamp { std::thread::sleep(time::Duration::from_secs(1)); continue; }