Skip to content

Commit

Permalink
Merge pull request #126 from moka-rs/quanta-v0.10
Browse files Browse the repository at this point in the history
Upgrade quanta to v0.10.0
  • Loading branch information
tatsuya6502 authored May 19, 2022
2 parents 90db6a8 + cc689c5 commit cde3a9c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 23 deletions.
17 changes: 15 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

## Version 0.8.4

### Fixed

- Fix the issue [#119][gh-issue-0119] by upgrading Quanta crate to v0.10.0.
([#126][gh-pull-0126])
- Quanta v0.9.3 or older may not work correctly on some x86_64 machines where
the Time Stamp Counter (TSC) is not synched across the processor cores.
- For more details about the issue, see [the relevant section][panic_in_quanta]
of the README.


### Added

- Add `get_with_if` method to the following caches: ([#123][gh-issue-0123])
Expand All @@ -19,8 +29,10 @@
- Quanta v0.9.3 or older may not work correctly on some x86_64 machines where
the Time Stamp Counter (TSC) is not synched across the processor cores.
([#119][gh-issue-0119])
- You can avoid the issue by disabling the default features of Moka.
See [the relevant section][panic_in_quanta] of the README.
- This issue was fixed by Quanta v0.10.0. You can upgrade Moka to v0.8.4 or newer
to prevent the issue.
- For more details about the issue, see [the relevant section][panic_in_quanta]
of the README.


## Version 0.8.2
Expand Down Expand Up @@ -334,6 +346,7 @@ The minimum supported Rust version (MSRV) is now 1.51.0 (2021-03-25).
[gh-issue-0038]: https://github.com/moka-rs/moka/issues/38/
[gh-issue-0031]: https://github.com/moka-rs/moka/issues/31/

[gh-pull-0126]: https://github.com/moka-rs/moka/pull/126/
[gh-pull-0121]: https://github.com/moka-rs/moka/pull/121/
[gh-pull-0117]: https://github.com/moka-rs/moka/pull/117/
[gh-pull-0116]: https://github.com/moka-rs/moka/pull/116/
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "moka"
version = "0.8.3"
version = "0.8.4"
edition = "2018"
rust-version = "1.51"

Expand Down Expand Up @@ -55,7 +55,7 @@ uuid = { version = "0.8", features = ["v4"] }
triomphe = { version = "0.1", default-features = false }

# Optional dependencies (quanta, enabled by default)
quanta = { version = "0.9.3", optional = true }
quanta = { version = "0.10.0", optional = true }

# Optional dependencies (dashmap)
dashmap = { version = "5.2", optional = true }
Expand Down
23 changes: 8 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,14 @@ change.

### Integer Overflow in Quanta Crate on Some x86_64 Machines

Quanta crate has a known issue on some specific x86_64-based machines. It will cause
intermittent panic due to integer overflow:
Quanta crate up to v0.9.3 has an issue on some specific x86_64-based machines. It
will cause intermittent panic due to integer overflow:

- metrics-rs/quanta — [Intermittent panic due to overflowing our source calibration denominator. #61](https://github.com/metrics-rs/quanta/issues/61)
- metrics-rs/quanta — [Intermittent panic due to overflowing our source calibration denominator. #61](https://github.com/metrics-rs/quanta/issues/61)
(Fixed by Quanta v0.10.0)

The overflows have been reported by a couple of users who use AMD-based Lenovo
laptops or Circle CI. There is no fix available yet as of Quanta v0.9.3.
laptops or Circle CI.

When this issue occurs, you will get a stacktrace containing the following lines:

Expand All @@ -457,18 +458,10 @@ quanta::Clock::new::{{closure}}
...
```

You can avoid the issue by disabling `qanta` feature, which is one of the default
features of Moka. Edit your Cargo.toml to add `default-features = false` to the
dependency declaration.
This issue was fixed by Quanta v0.10.0.

```toml:Cargo.toml
[dependencies]
moka = { version = "0.8", default-feautures = false }
# Or
moka = { version = "0.8", default-feautures = false, features = ["future"] }
```

This will make Moka to opt out Quanta and switch to a fall-back implementation.
You can prevent the issue by upgrading Moka to v0.8.4 or newer, which depends on
Quanta v0.10.0 or newer.


### Compile Errors on Some 32-bit Platforms
Expand Down
2 changes: 1 addition & 1 deletion src/common/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub(crate) use clock::Mock;
/// a wrapper type over Instant to force checked additions and prevent
/// unintentional overflow. The type preserve the Copy semantics for the wrapped
#[derive(PartialEq, PartialOrd, Clone, Copy)]
pub(crate) struct Instant(pub clock::Instant);
pub(crate) struct Instant(clock::Instant);

pub(crate) trait CheckedTimeOps {
fn checked_add(&self, duration: Duration) -> Option<Self>
Expand Down
21 changes: 18 additions & 3 deletions src/common/time/atomic_time.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use super::Instant;

use std::sync::atomic::{AtomicU64, Ordering};
use std::{
any::TypeId,
sync::atomic::{AtomicU64, Ordering},
};

pub(crate) struct AtomicInstant {
instant: AtomicU64,
Expand All @@ -14,6 +17,9 @@ impl Default for AtomicInstant {
}
}

// TODO: Need a safe way to convert between `quanta::Instant` and `u64`.
// quanta v0.10.0 no longer provides `quanta::Instant::as_u64` method.

impl AtomicInstant {
pub(crate) fn reset(&self) {
self.instant.store(std::u64::MAX, Ordering::Release);
Expand All @@ -28,11 +34,20 @@ impl AtomicInstant {
if ts == u64::MAX {
None
} else {
Some(unsafe { std::mem::transmute(ts) })
debug_assert_eq!(
TypeId::of::<super::clock::Instant>(),
TypeId::of::<quanta::Instant>()
);
Some(Instant(unsafe { std::mem::transmute(ts) }))
}
}

pub(crate) fn set_instant(&self, instant: Instant) {
self.instant.store(instant.0.as_u64(), Ordering::Release);
debug_assert_eq!(
TypeId::of::<super::clock::Instant>(),
TypeId::of::<quanta::Instant>()
);
let ts = unsafe { std::mem::transmute(instant.0) };
self.instant.store(ts, Ordering::Release);
}
}

0 comments on commit cde3a9c

Please sign in to comment.