cultcache-rs: delete::<T> runs the retype judge; changelog; record the accepted per-write decode cost
Some checks failed
CultMesh portability and performance / ubuntu-latest reactive semantics and leases (pull_request) Has been cancelled
Some checks failed
CultMesh portability and performance / ubuntu-latest reactive semantics and leases (pull_request) Has been cancelled
delete of an unheld key held by another registered type (or a foreign record) is refused like put and is_writable. The held-payload check's decode cost is stated as deliberately accepted, with no cached mark. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e6b02d7d65
commit
ee5b4940db
3 changed files with 25 additions and 4 deletions
|
|
@ -13,6 +13,7 @@ only in git history.
|
|||
|
||||
### Changed
|
||||
|
||||
- `CultCache::delete::<T>` of a key nothing holds now refuses, as `put` and `is_writable` do, when `T` has no home store ("No backing store is registered…") or when a store carries a foreign record at the key or another registered type holds it (before: `Ok(false)`).
|
||||
- `is_stored_at_stamp(&str)` (new, public) is the one shape a peer's `storedAt` must parse as, pinned by `tests/vectors/stored-at-stamp` (RFC 3339 `YYYY-MM-DDThh:mm:ss`, a 1 to 9 digit fraction, `Z` or `+hh:mm`/`-hh:mm`; uppercase `T`/`Z`, a real date, seconds 00-59, years 0001-9999), hand-checked because `chrono`'s RFC 3339 reader takes other shapes. `put_raw_envelope` and `put_prepared_batch` refuse a `stored_at` that is not a stamp (before: only a blank one) and mint nothing (variants:ruling:raw-put-without-stamp-refused).
|
||||
- The single-file store's `push`, `push_all` and `commit_if` stamp a replacing write strictly later than the record it replaces at the same key (a staged stamp stands only when it parses and is strictly later; otherwise the stamp is minted as the replaced stamp plus one microsecond, or now if later), with no identical-content exception, as C# does. A stamp with no successor (the replaced stamp is at year 9999's last microsecond) refuses the write and writes nothing, as C# `MintStoredAt` does. `commit_if` replaces only the record of the entry's own type under the key, so a retype is refused as `push` refuses it. The cache holds the stamp the store wrote. The redb stores and the store-level exact-envelope writes (`compare_and_swap_entry` and its family) still write the caller's envelope unchanged.
|
||||
- The single-file store re-checks for a link once the store lock is held (every write and the try-exchange), so a link put at the path while a writer waited on the lock is refused with `StoreLinkedError` and the lock released, as C# does, instead of being replaced. Pinned by a test that puts the link while a second holder owns the lock.
|
||||
|
|
|
|||
|
|
@ -3487,6 +3487,8 @@ impl CultCache {
|
|||
|
||||
/// The one decode behind every write entry and [`CultCache::is_writable`]: the held envelope at `(type_id, key)`
|
||||
/// read under the registered type's mark.
|
||||
/// Each write over a held key pays one full typed decode of the held payload (about 40% of a `put` of a 200,000-element
|
||||
/// record, measured in release); this cost is accepted deliberately, with no cached mark, so the check keeps no second state.
|
||||
fn held_finding(&self, type_id: &str, key: &str) -> Result<HeldFinding> {
|
||||
let Some(definition) = self.definitions.get(type_id) else {
|
||||
bail!("No entry type registered for CultCache envelope type {type_id:?}");
|
||||
|
|
@ -3988,9 +3990,15 @@ impl CultCache {
|
|||
let home = self.home_index(T::TYPE)?;
|
||||
let id = entry_id_parts(T::TYPE, key);
|
||||
let Some(entry) = self.entries.get(&id).cloned() else {
|
||||
if let Some((_, foreign)) = self.foreign.iter().find(|(_, foreign)| foreign.key == key) {
|
||||
return Err(foreign_conflict(foreign, T::TYPE));
|
||||
}
|
||||
// The retype judge a write runs: a foreign record or another registered type holding the key refuses the removal.
|
||||
let probe = CultCacheEnvelope {
|
||||
key: key.to_string(),
|
||||
r#type: T::TYPE.to_string(),
|
||||
payload: Vec::new(),
|
||||
stored_at: String::new(),
|
||||
schema_id: None,
|
||||
};
|
||||
self.refuse_retype(&self.entries, &self.foreign, &probe)?;
|
||||
return Ok(false);
|
||||
};
|
||||
let released = self.projected_slots(&entry)?;
|
||||
|
|
|
|||
|
|
@ -477,7 +477,7 @@ fn is_writable_is_false_for_a_type_with_no_home_store() {
|
|||
assert!(cache.is_writable(SlotUnit::TYPE, "k").unwrap());
|
||||
}
|
||||
|
||||
// is_writable and delete agree for a homeless type: removal of an unheld key is refused like the write, not answered false.
|
||||
// For a homeless type, is_writable, put and delete of an unheld key agree: removal is refused like the write, not answered false.
|
||||
#[test]
|
||||
fn delete_of_an_unheld_key_of_a_type_with_no_home_store_is_refused_like_the_put() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
|
@ -573,3 +573,15 @@ fn a_store_attached_after_a_refused_load_keeps_the_refusal_reason() {
|
|||
let refused = error.downcast_ref::<CultCacheLoadRefused>().unwrap_or_else(|| panic!("{error:#}"));
|
||||
assert!(refused.reason.contains("bytes after"), "refusal reason lost: {}", refused.reason);
|
||||
}
|
||||
|
||||
// A key held by another registered type: put, is_writable and typed delete all refuse (delete used to answer Ok(false)).
|
||||
#[test]
|
||||
fn delete_of_a_key_held_by_another_registered_type_is_refused_like_the_put() {
|
||||
let (mut cache, _dir, _path) = held_marked_and_clean();
|
||||
assert!(!cache.is_writable(SlotUnit::TYPE, "clean").unwrap());
|
||||
let put = cache.put("clean", &SlotUnit { name: "n".into(), outcome: UnitOutcome::Denied });
|
||||
assert!(put.is_err());
|
||||
let error = cache.delete::<SlotUnit>("clean").unwrap_err();
|
||||
assert!(!format!("{error:#}").is_empty());
|
||||
assert!(cache.snapshot_envelopes().iter().any(|held| held.key == "clean" && held.r#type == UnionSurface::TYPE));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue