fix(hail):尝试修复冰雹算法中可能存在的死锁问题。
This commit is contained in:
parent
d1c19355a5
commit
dbcdfc426e
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user