client-query-cache 0.14.0__tar.gz → 0.14.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/PKG-INFO +1 -1
  2. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/native/shared-index/Cargo.lock +24 -0
  3. client_query_cache-0.14.1/native/shared-index/Cargo.toml +38 -0
  4. client_query_cache-0.14.1/native/shared-index/deny.toml +18 -0
  5. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/native/shared-index/src/array/tests.rs +12 -0
  6. client_query_cache-0.14.1/native/shared-index/src/hash/tests.rs +20 -0
  7. client_query_cache-0.14.1/native/shared-index/src/hash.rs +15 -0
  8. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/native/shared-index/src/index/tests.rs +15 -11
  9. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/native/shared-index/src/index.rs +2 -3
  10. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/native/shared-index/src/key_encoder.rs +6 -1
  11. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/native/shared-index/src/lib.rs +2 -0
  12. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/native/shared-index/src/local_cache/shared.rs +13 -128
  13. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/native/shared-index/src/local_cache.rs +73 -99
  14. client_query_cache-0.14.1/native/shared-index/src/probes/tests.rs +89 -0
  15. client_query_cache-0.14.1/native/shared-index/src/probes.rs +133 -0
  16. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/pyproject.toml +22 -22
  17. client_query_cache-0.14.1/rust-toolchain.toml +4 -0
  18. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/collation.py +1 -1
  19. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/namespace_metadata.py +1 -1
  20. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/selective_invalidation.py +1 -1
  21. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_shared/adapters.py +1 -1
  22. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_shared/attachment.py +1 -1
  23. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_shared/coordinator.py +5 -5
  24. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_shared/wire.py +1 -1
  25. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/asynchronous/streams.py +1 -1
  26. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/shared.py +4 -2
  27. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/synchronous/streams.py +1 -1
  28. client_query_cache-0.14.0/native/shared-index/Cargo.toml +0 -39
  29. client_query_cache-0.14.0/native/shared-index/deny.toml +0 -16
  30. client_query_cache-0.14.0/native/shared-index/src/hash/tests.rs +0 -11
  31. client_query_cache-0.14.0/native/shared-index/src/hash.rs +0 -28
  32. client_query_cache-0.14.0/rust-toolchain.toml +0 -5
  33. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/LICENSE +0 -0
  34. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/README.md +0 -0
  35. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/native/shared-index/src/array.rs +0 -0
  36. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/native/shared-index/src/clock.rs +0 -0
  37. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/native/shared-index/src/frames/tests.rs +0 -0
  38. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/native/shared-index/src/frames.rs +0 -0
  39. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/native/shared-index/src/index/support_tests.rs +0 -0
  40. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/native/shared-index/src/keys.rs +0 -0
  41. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/native/shared-index/src/local_cache/selective.rs +0 -0
  42. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/native/shared-index/src/memory/support_tests.rs +0 -0
  43. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/native/shared-index/src/memory/tests.rs +0 -0
  44. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/native/shared-index/src/memory.rs +0 -0
  45. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/native/shared-index/src/python.rs +0 -0
  46. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/native/shared-index/src/ring/tests.rs +0 -0
  47. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/native/shared-index/src/ring.rs +0 -0
  48. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/native/shared-index/src/sync.rs +0 -0
  49. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/__init__.py +0 -0
  50. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/__init__.py +0 -0
  51. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/canonical.py +0 -0
  52. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/codec.py +0 -0
  53. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/collection_metadata.py +0 -0
  54. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/config.py +0 -0
  55. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/contracts.pyi +0 -0
  56. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/count_reads.py +0 -0
  57. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/cursor_capture.py +0 -0
  58. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/entries.py +0 -0
  59. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/errors.py +0 -0
  60. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/find_one_reads.py +0 -0
  61. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/find_reads.py +0 -0
  62. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/identity_reads.py +0 -0
  63. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/keys.py +0 -0
  64. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/native.py +0 -0
  65. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/order_sensitive_keys.py +0 -0
  66. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/projection.py +0 -0
  67. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/query_filters.py +0 -0
  68. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/read_classification.py +0 -0
  69. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/read_validation.py +0 -0
  70. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/selective_projection.py +0 -0
  71. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/snapshots.py +0 -0
  72. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/stream_activation.py +0 -0
  73. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/stream_cost.py +0 -0
  74. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/stream_events.py +0 -0
  75. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/stream_health.py +0 -0
  76. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/stream_options.py +0 -0
  77. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/stream_startup.py +0 -0
  78. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/traversal.py +0 -0
  79. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_core/unique_keys.py +0 -0
  80. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_shared/__init__.py +0 -0
  81. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_shared/diagnostics.py +0 -0
  82. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_shared/shared_index.py +0 -0
  83. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_shared_index.pyi +0 -0
  84. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/_types.py +0 -0
  85. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/asynchronous/__init__.py +0 -0
  86. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/asynchronous/collection.py +0 -0
  87. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/asynchronous/cursors.py +0 -0
  88. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/asynchronous/database.py +0 -0
  89. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/asynchronous/manager.py +0 -0
  90. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/asynchronous/shared.py +0 -0
  91. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/otel.py +0 -0
  92. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/py.typed +0 -0
  93. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/synchronous/__init__.py +0 -0
  94. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/synchronous/collection.py +0 -0
  95. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/synchronous/cursors.py +0 -0
  96. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/synchronous/database.py +0 -0
  97. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/synchronous/manager.py +0 -0
  98. {client_query_cache-0.14.0 → client_query_cache-0.14.1}/src/client_query_cache/synchronous/shared.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: client-query-cache
3
- Version: 0.14.0
3
+ Version: 0.14.1
4
4
  Classifier: Framework :: AsyncIO
5
5
  Classifier: Operating System :: POSIX :: Linux
6
6
  Classifier: Programming Language :: Python :: Implementation :: CPython
@@ -31,10 +31,13 @@ checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
31
31
  name = "client-query-cache-shared-index"
32
32
  version = "0.8.0"
33
33
  dependencies = [
34
+ "itoa",
34
35
  "libc",
35
36
  "loom",
36
37
  "pyo3",
38
+ "rapidhash",
37
39
  "rustc-hash",
40
+ "slab",
38
41
  ]
39
42
 
40
43
  [[package]]
@@ -64,6 +67,12 @@ version = "0.5.0"
64
67
  source = "registry+https://github.com/rust-lang/crates.io-index"
65
68
  checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
66
69
 
70
+ [[package]]
71
+ name = "itoa"
72
+ version = "1.0.19"
73
+ source = "registry+https://github.com/rust-lang/crates.io-index"
74
+ checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
75
+
67
76
  [[package]]
68
77
  name = "lazy_static"
69
78
  version = "1.5.1"
@@ -212,6 +221,15 @@ dependencies = [
212
221
  "proc-macro2",
213
222
  ]
214
223
 
224
+ [[package]]
225
+ name = "rapidhash"
226
+ version = "4.5.1"
227
+ source = "registry+https://github.com/rust-lang/crates.io-index"
228
+ checksum = "5da7e78a036ce858e8d55b7e7dc8ba3a88b78350fd2155d3591bbd966b58589e"
229
+ dependencies = [
230
+ "rustversion",
231
+ ]
232
+
215
233
  [[package]]
216
234
  name = "regex-automata"
217
235
  version = "0.4.18"
@@ -262,6 +280,12 @@ version = "2.0.1"
262
280
  source = "registry+https://github.com/rust-lang/crates.io-index"
263
281
  checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
264
282
 
283
+ [[package]]
284
+ name = "slab"
285
+ version = "0.4.12"
286
+ source = "registry+https://github.com/rust-lang/crates.io-index"
287
+ checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
288
+
265
289
  [[package]]
266
290
  name = "smallvec"
267
291
  version = "1.16.3"
@@ -0,0 +1,38 @@
1
+ [package]
2
+ name = "client-query-cache-shared-index"
3
+ version = "0.8.0"
4
+ description = "Shared index for client-query-cache worker caches."
5
+ repository = "https://github.com/alessio-locatelli/client-query-cache"
6
+ documentation = "https://alessio-locatelli.github.io/client-query-cache/"
7
+ edition = "2024"
8
+ license = "Apache-2.0"
9
+ # The default is publishing to any registry allowed (https://doc.rust-lang.org/1.100.0/cargo/reference/manifest.html#the-publish-field). We override it because the native crate ships only inside the Python distribution.
10
+ publish = false
11
+
12
+ [lib]
13
+ name = "_shared_index"
14
+ crate-type = ["cdylib"]
15
+
16
+ [features]
17
+ python = ["dep:itoa", "dep:pyo3", "dep:rustc-hash", "dep:slab"]
18
+
19
+ [dependencies]
20
+ itoa = { version = "1.0.19", optional = true }
21
+ rapidhash = { version = "4.5.1", default-features = false }
22
+ libc = "0.2.190"
23
+ slab = { version = "0.4.12", optional = true }
24
+ pyo3 = { version = "0.30.1", features = ["abi3-py314"], optional = true }
25
+ rustc-hash = { version = "2.1.3", optional = true }
26
+
27
+ [target.'cfg(loom)'.dependencies]
28
+ loom = "0.7.2"
29
+
30
+ [lints.rust]
31
+ # The default is warning on every cfg name Cargo does not declare (https://doc.rust-lang.org/1.100.0/rustc/check-cfg/cargo-specifics.html). We override it because the loom model tests are selected with --cfg loom.
32
+ unexpected_cfgs = { level = "warn", check-cfg = ["cfg(loom)"] }
33
+
34
+ [profile.release]
35
+ # The default is false (https://doc.rust-lang.org/1.100.0/cargo/reference/profiles.html#lto), which optimizes across a crate's own code generation units only. We override it because whole-program optimization across the crate and PyO3 shortens the native cache entry points (reports/rust-build-profile/summary.md).
36
+ lto = "fat"
37
+ # The default is 16 (https://doc.rust-lang.org/1.100.0/cargo/reference/profiles.html#codegen-units). We override it because a single unit lets the optimizer inline across the whole extension.
38
+ codegen-units = 1
@@ -0,0 +1,18 @@
1
+ # The default license allowlist is empty
2
+ # (https://github.com/EmbarkStudios/cargo-deny/blob/0.20.2/docs/src/checks/licenses/cfg.md#the-allow-field-optional). We override it because these permissive
3
+ # licenses cover the resolved native dependency graph and permit distribution.
4
+ [licenses]
5
+ allow = ["Apache-2.0", "Apache-2.0 WITH LLVM-exception", "MIT", "Unicode-3.0"]
6
+
7
+ [bans]
8
+ # Defaults: https://github.com/EmbarkStudios/cargo-deny/blob/0.20.2/docs/src/checks/bans/cfg.md
9
+ # The default is warn. We override it because duplicate versions must be resolved.
10
+ multiple-versions = "deny"
11
+ # The default is warn. We override it because unbounded dependencies hinder review.
12
+ wildcards = "deny"
13
+
14
+ [sources]
15
+ # Both defaults are warn (https://github.com/EmbarkStudios/cargo-deny/blob/0.20.2/docs/src/checks/sources/cfg.md). We override them because only crates.io is
16
+ # approved.
17
+ unknown-registry = "deny"
18
+ unknown-git = "deny"
@@ -135,3 +135,15 @@ fn clearing_releases_the_buffer() {
135
135
  assert_eq!(builder.bytes.capacity(), 0);
136
136
  assert_eq!(builder.finish().len(), MINIMUM_ENVELOPE);
137
137
  }
138
+
139
+ #[test]
140
+ fn decimal_matches_standard_formatting_at_every_width_boundary() {
141
+ let boundaries = (1..u64::MAX.ilog10() + 1).flat_map(|exponent| {
142
+ let power = 10_u64.pow(exponent);
143
+ [power - 1, power]
144
+ });
145
+ for value in [0, u64::MAX].into_iter().chain(boundaries) {
146
+ let mut digits = [0; 20];
147
+ assert_eq!(decimal(value, &mut digits), value.to_string().as_bytes());
148
+ }
149
+ }
@@ -0,0 +1,20 @@
1
+ use super::key;
2
+
3
+ const KNOWN_KEY: u64 = 0x61c8_a333_db8d_0639;
4
+
5
+ #[test]
6
+ fn separates_identity_and_shape_boundaries() {
7
+ for (identity, shape) in [(&b"a"[..], &b"bc"[..]), (b"", b"abc"), (b"abc", b"")] {
8
+ assert_ne!(key(0, b"ab", b"c"), key(0, identity, shape));
9
+ }
10
+ }
11
+
12
+ #[test]
13
+ fn separates_namespaces() {
14
+ assert_ne!(key(0, b"a", b"b"), key(1, b"a", b"b"));
15
+ }
16
+
17
+ #[test]
18
+ fn keeps_the_published_mapping_of_this_layout_version() {
19
+ assert_eq!(key(1, b"identity", b"find_one"), KNOWN_KEY);
20
+ }
@@ -0,0 +1,15 @@
1
+ use rapidhash::v3::{RapidSecrets, rapidhash_v3_seeded};
2
+
3
+ const SECRETS: RapidSecrets = RapidSecrets::seed(0x9e37_79b9_7f4a_7c15);
4
+
5
+ fn seeded(seed: u64) -> RapidSecrets {
6
+ RapidSecrets { seed, ..SECRETS }
7
+ }
8
+
9
+ pub(crate) fn key(namespace: u64, identity: &[u8], shape: &[u8]) -> u64 {
10
+ let identity_hash = rapidhash_v3_seeded(identity, &seeded(SECRETS.seed ^ namespace));
11
+ rapidhash_v3_seeded(shape, &seeded(identity_hash))
12
+ }
13
+
14
+ #[cfg(test)]
15
+ mod tests;
@@ -443,6 +443,15 @@ fn attaches_only_to_a_complete_layout() {
443
443
  assert!(Index::attach(zeroed(HEADER_WORDS)).is_none());
444
444
  }
445
445
 
446
+ #[test]
447
+ fn rejects_a_mapping_of_another_layout_version() {
448
+ for version in [LAYOUT_VERSION - 1, LAYOUT_VERSION + 1] {
449
+ let (index, _writer) = fixture();
450
+ index.word(H_VERSION).store(version, Ordering::Relaxed);
451
+ assert!(Index::attach(index.memory).is_none());
452
+ }
453
+ }
454
+
446
455
  #[test]
447
456
  fn rejects_a_descriptor_with_an_invalid_published_layout() {
448
457
  let (index, _writer) = fixture();
@@ -481,22 +490,17 @@ fn a_release_after_snapshot_sizing_invalidates_the_copy() {
481
490
 
482
491
  #[test]
483
492
  fn equal_hashes_do_not_replace_or_return_a_different_identity() {
484
- // Each pair has the same full hash in namespace 1, including unequal-length keys.
485
- const COLLISIONS: [(&[u8], &[u8]); 2] = [
493
+ const FULL_HASH_COLLISIONS_IN_NAMESPACE_ONE: [(&[u8], &[u8]); 2] = [
486
494
  (
487
- &[0; 16],
488
- &[
489
- 1, 0, 0, 0, 0, 0, 0, 0, 0xae, 0x52, 0x43, 0x1c, 0xe5, 0xca, 0xe9, 0x37,
490
- ],
495
+ &[0, 0, 0, 0, 0, 0, 0, 0, 85, 215, 220, 90, 67, 123, 207, 157],
496
+ &[0, 0, 0, 0, 0, 0, 0, 0, 107, 59, 89, 66, 252, 252, 74, 143],
491
497
  ),
492
498
  (
493
- &[0; 8],
494
- &[
495
- 0, 0, 0, 0, 0, 0, 0, 0, 0xbf, 0xcc, 0x1e, 0x61, 0x33, 0xe7, 0xf5, 0xc7,
496
- ],
499
+ &[34, 101, 217, 139, 55, 116, 229, 101],
500
+ &[0, 0, 0, 0, 0, 0, 0, 0, 181, 195, 234, 68, 174, 123, 109, 82],
497
501
  ),
498
502
  ];
499
- for (first_identity, second_identity) in COLLISIONS {
503
+ for (first_identity, second_identity) in FULL_HASH_COLLISIONS_IN_NAMESPACE_ONE {
500
504
  let first = query(first_identity);
501
505
  let second = query(second_identity);
502
506
  assert_eq!(first.hash(), second.hash());
@@ -6,7 +6,7 @@ use crate::memory::{WORD_BYTES, Words};
6
6
  use crate::sync::{AtomicU64, Ordering, fence};
7
7
 
8
8
  const MAGIC: u64 = u64::from_le_bytes(*b"cqcsidx3");
9
- const LAYOUT_VERSION: u64 = 3;
9
+ const LAYOUT_VERSION: u64 = 4;
10
10
 
11
11
  const H_MAGIC: usize = 0;
12
12
  const H_VERSION: usize = 1;
@@ -690,8 +690,7 @@ impl<M: Words> Writer<M> {
690
690
  if bits != 0 {
691
691
  return Some(word * u64::BITS as usize + bits.trailing_zeros() as usize);
692
692
  }
693
- for word in word + 1..self.occupied_bins.len() {
694
- let bits = self.occupied_bins[word];
693
+ for (word, &bits) in self.occupied_bins.iter().enumerate().skip(word + 1) {
695
694
  if bits != 0 {
696
695
  return Some(word * u64::BITS as usize + bits.trailing_zeros() as usize);
697
696
  }
@@ -105,7 +105,12 @@ impl FindKeyEncoder {
105
105
  let _recursion = Recursion::enter(value.py())?;
106
106
  let offsets = tuple(buffer, name)?;
107
107
  for (index, item) in items.iter().enumerate() {
108
- self.node(buffer, &index.to_string(), &item, scalar_encoder)?;
108
+ self.node(
109
+ buffer,
110
+ itoa::Buffer::new().format(index),
111
+ &item,
112
+ scalar_encoder,
113
+ )?;
109
114
  }
110
115
  return finish_tuple(buffer, offsets);
111
116
  }
@@ -22,6 +22,8 @@ mod keys;
22
22
  #[cfg(all(feature = "python", not(loom)))]
23
23
  mod local_cache;
24
24
  mod memory;
25
+ #[cfg(not(loom))]
26
+ mod probes;
25
27
  #[cfg(all(feature = "python", not(loom)))]
26
28
  mod python;
27
29
  mod ring;
@@ -1,4 +1,4 @@
1
- use std::collections::{BTreeMap, HashMap, HashSet};
1
+ use std::collections::{HashMap, HashSet};
2
2
  use std::sync::Arc;
3
3
 
4
4
  use pyo3::prelude::*;
@@ -9,131 +9,9 @@ use super::{
9
9
  };
10
10
  use crate::clock::monotonic_ns;
11
11
  use crate::index::{Block, Query};
12
+ use crate::probes::{Names, Probes};
12
13
  use crate::python::{OwnerIndex, SessionRing};
13
14
 
14
- type Names = (Arc<str>, Arc<str>);
15
-
16
- struct Probe {
17
- token: u64,
18
- active: usize,
19
- expires: u64,
20
- sequence: u64,
21
- }
22
-
23
- pub(super) struct Probes {
24
- ttl_ns: u64,
25
- entries: HashMap<Names, Probe>,
26
- order: BTreeMap<u64, Names>,
27
- sequence: u64,
28
- next_token: u64,
29
- }
30
-
31
- impl Probes {
32
- pub(super) fn new(ttl_ns: u64) -> Self {
33
- Self {
34
- ttl_ns,
35
- entries: HashMap::new(),
36
- order: BTreeMap::new(),
37
- sequence: 0,
38
- next_token: 0,
39
- }
40
- }
41
-
42
- fn expire(&mut self, now: u64) {
43
- while let Some((&sequence, names)) = self.order.first_key_value() {
44
- if self.entries[names].expires > now {
45
- return;
46
- }
47
- let names = self.order.remove(&sequence).expect("ordered probe");
48
- self.entries.remove(&names);
49
- }
50
- }
51
-
52
- fn insert(&mut self, names: Names, mut probe: Probe) -> u64 {
53
- self.sequence += 1;
54
- probe.sequence = self.sequence;
55
- self.order.insert(self.sequence, names.clone());
56
- let token = probe.token;
57
- self.entries.insert(names, probe);
58
- token
59
- }
60
-
61
- pub(super) fn begin(&mut self, names: Names, admissible: bool, capacity: usize) -> Option<u64> {
62
- let now = monotonic_ns();
63
- self.expire(now);
64
- if !admissible {
65
- return None;
66
- }
67
- let expires = now.saturating_add(self.ttl_ns);
68
- let probe = if let Some(mut probe) = self.entries.remove(&names) {
69
- self.order.remove(&probe.sequence);
70
- probe.active += 1;
71
- probe.expires = expires;
72
- probe
73
- } else {
74
- if self.entries.len() >= capacity {
75
- return None;
76
- }
77
- let token = self.next_token;
78
- self.next_token += 1;
79
- Probe {
80
- token,
81
- active: 1,
82
- expires,
83
- sequence: 0,
84
- }
85
- };
86
- Some(self.insert(names, probe))
87
- }
88
-
89
- pub(super) fn finish(&mut self, names: &Names, token: u64) {
90
- self.expire(monotonic_ns());
91
- let Some(probe) = self.entries.get_mut(names) else {
92
- return;
93
- };
94
- if probe.token != token {
95
- return;
96
- }
97
- if probe.active == 1 {
98
- let sequence = probe.sequence;
99
- self.entries.remove(names);
100
- self.order.remove(&sequence);
101
- } else {
102
- probe.active -= 1;
103
- }
104
- }
105
-
106
- pub(super) fn active(&mut self, names: &Names, token: u64) -> bool {
107
- self.expire(monotonic_ns());
108
- self.entries
109
- .get(names)
110
- .is_some_and(|probe| probe.token == token)
111
- }
112
-
113
- pub(super) fn invalidate(&mut self, names: &Names) {
114
- if let Some(probe) = self.entries.remove(names) {
115
- self.order.remove(&probe.sequence);
116
- }
117
- }
118
-
119
- pub(super) fn invalidate_database(&mut self, database: &str) {
120
- let matching: Vec<_> = self
121
- .entries
122
- .keys()
123
- .filter(|names| names.0.as_ref() == database)
124
- .cloned()
125
- .collect();
126
- for names in matching {
127
- self.invalidate(&names);
128
- }
129
- }
130
-
131
- pub(super) fn clear(&mut self) {
132
- self.entries.clear();
133
- self.order.clear();
134
- }
135
- }
136
-
137
15
  struct Published {
138
16
  token: u64,
139
17
  namespace: u64,
@@ -487,7 +365,7 @@ impl SharedOwner {
487
365
  let capacity = state.max_namespaces;
488
366
  Ok(shared_state(&mut state)
489
367
  .probes
490
- .begin(key, admissible, capacity))
368
+ .begin(key, admissible, capacity, monotonic_ns()))
491
369
  }
492
370
 
493
371
  fn cancel_namespace_metadata_probe(
@@ -502,7 +380,9 @@ impl SharedOwner {
502
380
  .state
503
381
  .lock()
504
382
  .expect("local owner mutex");
505
- shared_state(&mut state).probes.finish(&key, token);
383
+ shared_state(&mut state)
384
+ .probes
385
+ .finish(&key, token, monotonic_ns());
506
386
  Ok(())
507
387
  }
508
388
 
@@ -541,7 +421,10 @@ impl SharedOwner {
541
421
  .state
542
422
  .lock()
543
423
  .expect("local owner mutex");
544
- let reserved = !state.closed && shared_state(&mut state).probes.active(&key, token);
424
+ let reserved = !state.closed
425
+ && shared_state(&mut state)
426
+ .probes
427
+ .active(&key, token, monotonic_ns());
545
428
  let registered = if reserved {
546
429
  state.register(py, namespace, &python_names)
547
430
  } else {
@@ -556,7 +439,9 @@ impl SharedOwner {
556
439
  });
557
440
  (epoch, index_generation, slot)
558
441
  });
559
- shared_state(&mut state).probes.finish(&key, token);
442
+ shared_state(&mut state)
443
+ .probes
444
+ .finish(&key, token, monotonic_ns());
560
445
  Ok(metadata)
561
446
  }
562
447