Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make ClockSequence wrap correctly #705

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ pub mod context {
// increment the clock sequence we want to wrap once it becomes larger
// than what we can represent in a "u14". Otherwise there'd be patches
// where the clock sequence doesn't change regardless of the timestamp
self.count.fetch_add(1, Ordering::AcqRel) % (u16::MAX >> 2)
self.count.fetch_add(1, Ordering::AcqRel) & (u16::MAX >> 2)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@ mod tests {
let node = [1, 2, 3, 4, 5, 6];

// This context will wrap
let context = Context::new((u16::MAX >> 2) - 1);
let context = Context::new(u16::MAX >> 2);

let uuid1 = Uuid::new_v1(Timestamp::from_unix(&context, time, time_fraction), &node);

let time: u64 = 1_496_854_536;

let uuid2 = Uuid::new_v1(Timestamp::from_unix(&context, time, time_fraction), &node);

assert_eq!(uuid1.get_timestamp().unwrap().to_rfc4122().1, 16382);
assert_eq!(uuid1.get_timestamp().unwrap().to_rfc4122().1, 16383);
assert_eq!(uuid2.get_timestamp().unwrap().to_rfc4122().1, 0);

let time = 1_496_854_535;
Expand Down
4 changes: 2 additions & 2 deletions src/v6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ mod tests {
let node = [1, 2, 3, 4, 5, 6];

// This context will wrap
let context = Context::new((u16::MAX >> 2) - 1);
let context = Context::new(u16::MAX >> 2);

let uuid1 = Uuid::new_v6(Timestamp::from_unix(&context, time, time_fraction), &node);

let time: u64 = 1_496_854_536;

let uuid2 = Uuid::new_v6(Timestamp::from_unix(&context, time, time_fraction), &node);

assert_eq!(uuid1.get_timestamp().unwrap().to_rfc4122().1, 16382);
assert_eq!(uuid1.get_timestamp().unwrap().to_rfc4122().1, 16383);
assert_eq!(uuid2.get_timestamp().unwrap().to_rfc4122().1, 0);

let time = 1_496_854_535;
Expand Down