You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "PDGGK (via GitHub)" <gi...@apache.org> on 2026/08/26 01:37:55 UTC
[PR] fix(services/memcached): send a TTL over 30 days as an absolute expiry [opendal]
PDGGK opened a new pull request, #8150:
URL: https://github.com/apache/opendal/pull/8150
# Which issue does this PR close?
None.
# Rationale for this change
`set` passes the configured TTL straight through:
```rust
conn.set(
&percent_encode_path(key),
&value.to_vec(),
// Set expiration to 0 if ttl not set.
self.default_ttl.map(|v| v.as_secs() as u32).unwrap_or_default(),
)
```
memcached's protocol gives that field two meanings, split at thirty days: a
value up to `60*60*24*30` is an offset from now, and anything larger is read as
an **absolute Unix timestamp**.
So `default_ttl = 60d` is sent as `5184000`, which the server reads as a moment
in February 1970. The item is stored already expired. `set` returns success, the
server returns `STORED`, nothing is logged, and the next `get` misses.
The failure is quiet in the worst way: it looks exactly like a cache that is
working, and it gets worse the longer the TTL — the value a user picks precisely
because they want the entry to survive.
# What changes are included in this PR?
A TTL over thirty days is converted to the absolute form memcached will read it
as:
```rust
const MAX_RELATIVE_EXPIRATION_SECS: u64 = 60 * 60 * 24 * 30;
fn expiration_secs(ttl: Option<Duration>, now_unix_secs: u64) -> u32 {
let Some(ttl) = ttl else { return 0 };
let secs = ttl.as_secs();
if secs <= MAX_RELATIVE_EXPIRATION_SECS {
secs as u32
} else {
now_unix_secs.saturating_add(secs).min(u32::MAX as u64) as u32
}
}
```
Thirty days and under is untouched, an unset TTL still maps to `0` meaning never
expire, and the saturation replaces what was previously a silent `as u32`
truncation.
The clock is a parameter rather than read inside, so the conversion is testable
without one; `set` supplies `SystemTime::now()`.
# Are there any user-facing changes?
Yes. A `default_ttl` over thirty days now results in an entry that lives for
that long, instead of one discarded at write time. Configurations of thirty days
or less behave exactly as before.
# Test
Three cases, all deterministic — the clock is injected:
- under and exactly at thirty days stays relative, and an unset TTL is `0`
- thirty days plus one second, and sixty days, become `now + ttl`
- `Duration::from_secs(u64::MAX)` saturates at `u32::MAX` rather than wrapping
Reverting only the conversion fails the second of those and leaves the other two
green, so the tests separate the three regimes rather than moving together.
# Note on evidence
The service-side fact is memcached's documented protocol behaviour for the
expiration field, not something I observed on a running server — I do not have
one to point at and am not claiming otherwise. Everything else is in the tree.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(services/memcached): reject a TTL over 30 days [opendal]
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo merged PR #8150:
URL: https://github.com/apache/opendal/pull/8150
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(services/memcached): send a TTL over 30 days as an absolute expiry [opendal]
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on PR #8150:
URL: https://github.com/apache/opendal/pull/8150#issuecomment-5421843924
Please review https://github.com/apache/opendal/blob/main/CONTRIBUTING.md#ai-assisted-contributions.
Using agents to reply to messages is discouraged. I will stop engaging with your contribution if you continue to communicate in this manner.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(services/memcached): send a TTL over 30 days as an absolute expiry [opendal]
Posted by "PDGGK (via GitHub)" <gi...@apache.org>.
PDGGK commented on PR #8150:
URL: https://github.com/apache/opendal/pull/8150#issuecomment-5421800707
Done in `d233f95` — the builder now rejects it instead of rewriting it.
```rust
if let Some(ttl) = default_ttl
&& ttl.as_secs() > MAX_RELATIVE_EXPIRATION_SECS
{
return Err(Error::new(
ErrorKind::ConfigInvalid,
"default_ttl is larger than 30 days, which memcached reads as an absolute \
unix timestamp rather than an offset, storing the entry already expired",
)
.with_context("service", MEMCACHED_SCHEME)
.with_context("default_ttl", ttl.as_secs().to_string()));
}
```
`set` goes back to passing the value straight through, since anything that reaches it is now known to be an offset, and the clock is gone from the write path entirely — which makes this the smaller change of the two.
`MAX_RELATIVE_EXPIRATION_SECS` stays in `core.rs` next to the explanation of why the boundary is where it is, and the test moved to `backend.rs`: exactly thirty days still builds, thirty days plus one second is `ConfigInvalid`. Removing the guard fails it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(services/memcached): reject a TTL over 30 days [opendal]
Posted by "PDGGK (via GitHub)" <gi...@apache.org>.
PDGGK commented on PR #8150:
URL: https://github.com/apache/opendal/pull/8150#issuecomment-5421934705
Sorry about that, fair call. I'll keep replies short and plain from here.
No argument on closing #8149 either. I hadn't run it against a real DBFS and shouldn't have leaned on the reasoning instead. Thanks for looking at the rest.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org