client-query-cache 0.12.0__tar.gz → 0.14.0__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.
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/PKG-INFO +2 -1
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/README.md +1 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/src/keys.rs +18 -18
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/src/lib.rs +0 -4
- client_query_cache-0.14.0/native/shared-index/src/local_cache/selective.rs +274 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/src/local_cache/shared.rs +32 -40
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/src/local_cache.rs +417 -167
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/src/python.rs +27 -195
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/src/ring/tests.rs +16 -10
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/src/ring.rs +16 -5
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/pyproject.toml +1 -1
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/__init__.py +14 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/canonical.py +6 -6
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/collection_metadata.py +0 -4
- client_query_cache-0.14.0/src/client_query_cache/_core/config.py +62 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/contracts.pyi +26 -26
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/cursor_capture.py +9 -1
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/entries.py +1 -18
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/errors.py +13 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/keys.py +0 -16
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/native.py +7 -3
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/order_sensitive_keys.py +4 -4
- client_query_cache-0.14.0/src/client_query_cache/_core/selective_invalidation.py +288 -0
- client_query_cache-0.14.0/src/client_query_cache/_core/selective_projection.py +155 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/snapshots.py +3 -81
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/stream_events.py +61 -11
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_shared/adapters.py +165 -67
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_shared/attachment.py +112 -52
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_shared/coordinator.py +188 -119
- client_query_cache-0.14.0/src/client_query_cache/_shared/diagnostics.py +165 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_shared_index.pyi +23 -74
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/asynchronous/__init__.py +19 -1
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/asynchronous/collection.py +63 -16
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/asynchronous/cursors.py +26 -3
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/asynchronous/manager.py +22 -3
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/asynchronous/streams.py +62 -13
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/otel.py +39 -13
- client_query_cache-0.14.0/src/client_query_cache/py.typed +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/shared.py +37 -6
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/synchronous/__init__.py +19 -1
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/synchronous/collection.py +63 -16
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/synchronous/cursors.py +26 -3
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/synchronous/manager.py +22 -3
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/synchronous/streams.py +62 -11
- client_query_cache-0.12.0/native/shared-index/src/echo/tests.rs +0 -303
- client_query_cache-0.12.0/native/shared-index/src/echo.rs +0 -343
- client_query_cache-0.12.0/native/shared-index/src/relay/tests.rs +0 -130
- client_query_cache-0.12.0/native/shared-index/src/relay.rs +0 -134
- client_query_cache-0.12.0/src/client_query_cache/_core/__init__.py +0 -44
- client_query_cache-0.12.0/src/client_query_cache/_core/lifecycle.py +0 -8
- client_query_cache-0.12.0/src/client_query_cache/_core/locking.py +0 -139
- client_query_cache-0.12.0/src/client_query_cache/_core/lru.py +0 -164
- client_query_cache-0.12.0/src/client_query_cache/_core/manager.py +0 -1866
- client_query_cache-0.12.0/src/client_query_cache/_core/namespace.py +0 -64
- client_query_cache-0.12.0/src/client_query_cache/_core/retention.py +0 -219
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/LICENSE +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/Cargo.lock +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/Cargo.toml +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/deny.toml +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/src/array/tests.rs +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/src/array.rs +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/src/clock.rs +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/src/frames/tests.rs +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/src/frames.rs +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/src/hash/tests.rs +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/src/hash.rs +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/src/index/support_tests.rs +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/src/index/tests.rs +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/src/index.rs +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/src/key_encoder.rs +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/src/memory/support_tests.rs +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/src/memory/tests.rs +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/src/memory.rs +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/native/shared-index/src/sync.rs +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/rust-toolchain.toml +0 -0
- {client_query_cache-0.12.0/src/client_query_cache/_shared → client_query_cache-0.14.0/src/client_query_cache/_core}/__init__.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/codec.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/collation.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/count_reads.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/find_one_reads.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/find_reads.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/identity_reads.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/namespace_metadata.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/projection.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/query_filters.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/read_classification.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/read_validation.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/stream_activation.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/stream_cost.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/stream_health.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/stream_options.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/stream_startup.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/traversal.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_core/unique_keys.py +0 -0
- /client_query_cache-0.12.0/src/client_query_cache/py.typed → /client_query_cache-0.14.0/src/client_query_cache/_shared/__init__.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_shared/shared_index.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_shared/wire.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/_types.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/asynchronous/database.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/asynchronous/shared.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/src/client_query_cache/synchronous/database.py +0 -0
- {client_query_cache-0.12.0 → client_query_cache-0.14.0}/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.
|
|
3
|
+
Version: 0.14.0
|
|
4
4
|
Classifier: Framework :: AsyncIO
|
|
5
5
|
Classifier: Operating System :: POSIX :: Linux
|
|
6
6
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
@@ -29,6 +29,7 @@ Project-URL: Repository, https://github.com/alessio-locatelli/client-query-cache
|
|
|
29
29
|
[](https://alessio-locatelli.github.io/client-query-cache/getting-started/installation/)
|
|
30
30
|
[](https://github.com/alessio-locatelli/client-query-cache/actions/workflows/test.yml)
|
|
31
31
|
[](https://pypi.org/project/client-query-cache/)
|
|
32
|
+
[](https://alessio-locatelli.github.io/client-query-cache/getting-started/installation/#verify-release-provenance)
|
|
32
33
|
|
|
33
34
|
**Speed up read-heavy, high-throughput Python applications.** `client-query-cache` serves eligible repeated PyMongo reads from memory, reducing read latency and avoiding MongoDB round trips on cache hits.
|
|
34
35
|
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
[](https://alessio-locatelli.github.io/client-query-cache/getting-started/installation/)
|
|
5
5
|
[](https://github.com/alessio-locatelli/client-query-cache/actions/workflows/test.yml)
|
|
6
6
|
[](https://pypi.org/project/client-query-cache/)
|
|
7
|
+
[](https://alessio-locatelli.github.io/client-query-cache/getting-started/installation/#verify-release-provenance)
|
|
7
8
|
|
|
8
9
|
**Speed up read-heavy, high-throughput Python applications.** `client-query-cache` serves eligible repeated PyMongo reads from memory, reducing read latency and avoiding MongoDB round trips on cache hits.
|
|
9
10
|
|
|
@@ -67,7 +67,7 @@ pub(crate) struct Canonicalizer {
|
|
|
67
67
|
mapping_abc: Py<PyAny>,
|
|
68
68
|
sequence_abc: Py<PyAny>,
|
|
69
69
|
unsupported: Py<PyType>,
|
|
70
|
-
|
|
70
|
+
generic: Py<PyAny>,
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
impl Canonicalizer {
|
|
@@ -227,7 +227,7 @@ impl Canonicalizer {
|
|
|
227
227
|
|| value.is_instance(self.mapping_abc.bind(py))?
|
|
228
228
|
|| (value.is_instance(self.sequence_abc.bind(py))? && !is_string_like(value))
|
|
229
229
|
{
|
|
230
|
-
return self.
|
|
230
|
+
return self.generic.bind(py).call1((value,));
|
|
231
231
|
}
|
|
232
232
|
if let Err(error) = value.hash() {
|
|
233
233
|
if error.is_instance_of::<PyTypeError>(py) {
|
|
@@ -264,7 +264,7 @@ impl Canonicalizer {
|
|
|
264
264
|
mapping_abc: Py<PyAny>,
|
|
265
265
|
sequence_abc: Py<PyAny>,
|
|
266
266
|
unsupported: Py<PyType>,
|
|
267
|
-
|
|
267
|
+
generic: Py<PyAny>,
|
|
268
268
|
) -> Self {
|
|
269
269
|
Self {
|
|
270
270
|
canonical_tag,
|
|
@@ -275,7 +275,7 @@ impl Canonicalizer {
|
|
|
275
275
|
mapping_abc,
|
|
276
276
|
sequence_abc,
|
|
277
277
|
unsupported,
|
|
278
|
-
|
|
278
|
+
generic,
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
|
|
@@ -302,8 +302,8 @@ pub(crate) struct OrderedKeys {
|
|
|
302
302
|
canonical_tags: [Py<PyAny>; 4],
|
|
303
303
|
int64_type: Py<PyAny>,
|
|
304
304
|
decimal_type: Py<PyAny>,
|
|
305
|
-
|
|
306
|
-
|
|
305
|
+
generic: Py<PyAny>,
|
|
306
|
+
generic_discriminator: Py<PyAny>,
|
|
307
307
|
}
|
|
308
308
|
|
|
309
309
|
impl OrderedKeys {
|
|
@@ -374,12 +374,12 @@ impl OrderedKeys {
|
|
|
374
374
|
|| value.is_instance(canonicalizer.mapping_abc.bind(py))?
|
|
375
375
|
|| (value.is_instance(canonicalizer.sequence_abc.bind(py))? && !is_string_like(value))
|
|
376
376
|
{
|
|
377
|
-
let
|
|
378
|
-
&self.
|
|
377
|
+
let generic = if distinguish {
|
|
378
|
+
&self.generic_discriminator
|
|
379
379
|
} else {
|
|
380
|
-
&self.
|
|
380
|
+
&self.generic
|
|
381
381
|
};
|
|
382
|
-
return Ok(Pending::Leaf(
|
|
382
|
+
return Ok(Pending::Leaf(generic.bind(py).call1((value,))?));
|
|
383
383
|
}
|
|
384
384
|
if distinguish {
|
|
385
385
|
if value.is_instance(self.int64_type.bind(py))? {
|
|
@@ -462,8 +462,8 @@ impl OrderedKeys {
|
|
|
462
462
|
pending_tags: [Py<PyAny>; 4],
|
|
463
463
|
int64_type: Py<PyAny>,
|
|
464
464
|
decimal_type: Py<PyAny>,
|
|
465
|
-
|
|
466
|
-
|
|
465
|
+
generic: Py<PyAny>,
|
|
466
|
+
generic_discriminator: Py<PyAny>,
|
|
467
467
|
) -> PyResult<Self> {
|
|
468
468
|
let canonical = |tag: &Py<PyAny>| -> PyResult<Py<PyAny>> {
|
|
469
469
|
Ok(tag.bind(py).getattr(intern!(py, "canonical"))?.unbind())
|
|
@@ -480,8 +480,8 @@ impl OrderedKeys {
|
|
|
480
480
|
canonical_tags,
|
|
481
481
|
int64_type,
|
|
482
482
|
decimal_type,
|
|
483
|
-
|
|
484
|
-
|
|
483
|
+
generic,
|
|
484
|
+
generic_discriminator,
|
|
485
485
|
})
|
|
486
486
|
}
|
|
487
487
|
|
|
@@ -510,13 +510,13 @@ pub(crate) struct UnsafeScan {
|
|
|
510
510
|
prefixes: Vec<String>,
|
|
511
511
|
mapping_abc: Py<PyAny>,
|
|
512
512
|
sequence_abc: Py<PyAny>,
|
|
513
|
-
|
|
513
|
+
generic: Py<PyAny>,
|
|
514
514
|
}
|
|
515
515
|
|
|
516
516
|
impl UnsafeScan {
|
|
517
517
|
fn delegate(&self, node: &Bound<'_, PyAny>) -> PyResult<bool> {
|
|
518
518
|
let py = node.py();
|
|
519
|
-
self.
|
|
519
|
+
self.generic
|
|
520
520
|
.bind(py)
|
|
521
521
|
.call1((node, self.key_set.bind(py)))?
|
|
522
522
|
.is_truthy()
|
|
@@ -599,7 +599,7 @@ impl UnsafeScan {
|
|
|
599
599
|
prefixes: &Bound<'_, PyAny>,
|
|
600
600
|
mapping_abc: Py<PyAny>,
|
|
601
601
|
sequence_abc: Py<PyAny>,
|
|
602
|
-
|
|
602
|
+
generic: Py<PyAny>,
|
|
603
603
|
) -> PyResult<Self> {
|
|
604
604
|
Ok(Self {
|
|
605
605
|
keys: key_set.extract()?,
|
|
@@ -608,7 +608,7 @@ impl UnsafeScan {
|
|
|
608
608
|
prefixes: prefixes.extract()?,
|
|
609
609
|
mapping_abc,
|
|
610
610
|
sequence_abc,
|
|
611
|
-
|
|
611
|
+
generic,
|
|
612
612
|
})
|
|
613
613
|
}
|
|
614
614
|
|
|
@@ -12,8 +12,6 @@
|
|
|
12
12
|
mod array;
|
|
13
13
|
#[cfg(not(loom))]
|
|
14
14
|
mod clock;
|
|
15
|
-
#[cfg(not(loom))]
|
|
16
|
-
mod echo;
|
|
17
15
|
mod frames;
|
|
18
16
|
mod hash;
|
|
19
17
|
mod index;
|
|
@@ -26,7 +24,5 @@ mod local_cache;
|
|
|
26
24
|
mod memory;
|
|
27
25
|
#[cfg(all(feature = "python", not(loom)))]
|
|
28
26
|
mod python;
|
|
29
|
-
#[cfg(not(loom))]
|
|
30
|
-
mod relay;
|
|
31
27
|
mod ring;
|
|
32
28
|
mod sync;
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
use std::collections::{HashMap, HashSet};
|
|
2
|
+
use std::sync::Arc;
|
|
3
|
+
|
|
4
|
+
use super::{Family, Source};
|
|
5
|
+
|
|
6
|
+
const CAPACITY: usize = 1024;
|
|
7
|
+
|
|
8
|
+
#[derive(Hash, PartialEq, Eq)]
|
|
9
|
+
pub(super) struct Descriptor {
|
|
10
|
+
pub partition: Option<Vec<u8>>,
|
|
11
|
+
pub dependencies: Option<Vec<String>>,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
#[derive(Clone, Copy)]
|
|
15
|
+
pub(super) struct Guard {
|
|
16
|
+
pub query_token: u64,
|
|
17
|
+
pub group: u64,
|
|
18
|
+
pub version: u64,
|
|
19
|
+
pub epoch: u64,
|
|
20
|
+
pub index: u64,
|
|
21
|
+
pub fallback: u64,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
struct Group {
|
|
25
|
+
namespace: u64,
|
|
26
|
+
descriptor: Arc<Descriptor>,
|
|
27
|
+
version: u64,
|
|
28
|
+
captures: usize,
|
|
29
|
+
// Only current-version rows reserve selective capacity.
|
|
30
|
+
residents: usize,
|
|
31
|
+
sources: HashMap<u64, Source>,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
impl Group {
|
|
35
|
+
fn invalidate(&mut self, families: &mut HashMap<isize, Family>) {
|
|
36
|
+
self.version += 1;
|
|
37
|
+
self.residents = 0;
|
|
38
|
+
for (slot, source) in std::mem::take(&mut self.sources) {
|
|
39
|
+
Family::unindex(families, source, slot);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
#[derive(Default)]
|
|
45
|
+
struct NamespaceGroups {
|
|
46
|
+
fallback: u64,
|
|
47
|
+
groups: HashSet<u64>,
|
|
48
|
+
partitions: HashMap<Vec<u8>, HashSet<u64>>,
|
|
49
|
+
unpartitioned: HashSet<u64>,
|
|
50
|
+
families: HashMap<isize, Family>,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
#[derive(Default)]
|
|
54
|
+
pub(super) struct Registry {
|
|
55
|
+
nonce: u64,
|
|
56
|
+
groups: HashMap<u64, Group>,
|
|
57
|
+
keys: HashMap<(u64, Arc<Descriptor>), u64>,
|
|
58
|
+
namespaces: HashMap<u64, NamespaceGroups>,
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
impl Registry {
|
|
62
|
+
pub fn sources(&self, namespace: u64) -> Option<&HashMap<isize, Family>> {
|
|
63
|
+
Some(&self.namespaces.get(&namespace)?.families)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
pub fn index_source(&mut self, namespace: u64, group: u64, source: Source, slot: u64) {
|
|
67
|
+
self.groups
|
|
68
|
+
.get_mut(&group)
|
|
69
|
+
.expect("proof group")
|
|
70
|
+
.sources
|
|
71
|
+
.insert(slot, source);
|
|
72
|
+
let groups = self
|
|
73
|
+
.namespaces
|
|
74
|
+
.get_mut(&namespace)
|
|
75
|
+
.expect("proof namespace");
|
|
76
|
+
Family::index(&mut groups.families, source, slot);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
pub fn unindex_source(&mut self, namespace: u64, group: u64, source: Source, slot: u64) {
|
|
80
|
+
let Some(group) = self.groups.get_mut(&group) else {
|
|
81
|
+
return;
|
|
82
|
+
};
|
|
83
|
+
group.sources.remove(&slot);
|
|
84
|
+
if let Some(groups) = self.namespaces.get_mut(&namespace) {
|
|
85
|
+
Family::unindex(&mut groups.families, source, slot);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
pub fn clear_sources(&mut self, namespace: u64) {
|
|
90
|
+
if let Some(groups) = self.namespaces.get_mut(&namespace) {
|
|
91
|
+
groups.families = HashMap::new();
|
|
92
|
+
for id in &groups.groups {
|
|
93
|
+
let group = self.groups.get_mut(id).expect("proof group");
|
|
94
|
+
group.sources = HashMap::new();
|
|
95
|
+
group.version += 1;
|
|
96
|
+
group.residents = 0;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
pub fn is_empty(&self) -> bool {
|
|
101
|
+
self.groups.is_empty()
|
|
102
|
+
}
|
|
103
|
+
pub fn acquire(&mut self, namespace: u64, descriptor: Descriptor) -> Option<(u64, u64, u64)> {
|
|
104
|
+
let key = (namespace, Arc::new(descriptor));
|
|
105
|
+
if let Some(id) = self.keys.get(&key) {
|
|
106
|
+
let group = self.groups.get_mut(id).expect("indexed proof group");
|
|
107
|
+
group.captures += 1;
|
|
108
|
+
return Some((*id, group.version, self.namespaces[&namespace].fallback));
|
|
109
|
+
}
|
|
110
|
+
if self.groups.len() == CAPACITY {
|
|
111
|
+
let obsolete = self.groups.iter().find_map(|(&id, group)| {
|
|
112
|
+
(group.captures == 0 && group.residents == 0).then_some(id)
|
|
113
|
+
})?;
|
|
114
|
+
self.remove(obsolete);
|
|
115
|
+
}
|
|
116
|
+
self.nonce += 1;
|
|
117
|
+
let id = self.nonce;
|
|
118
|
+
let descriptor = key.1.clone();
|
|
119
|
+
let groups = self.namespaces.entry(namespace).or_default();
|
|
120
|
+
groups.groups.insert(id);
|
|
121
|
+
if let Some(partition) = &descriptor.partition {
|
|
122
|
+
groups
|
|
123
|
+
.partitions
|
|
124
|
+
.entry(partition.clone())
|
|
125
|
+
.or_default()
|
|
126
|
+
.insert(id);
|
|
127
|
+
} else {
|
|
128
|
+
groups.unpartitioned.insert(id);
|
|
129
|
+
}
|
|
130
|
+
let fallback = groups.fallback;
|
|
131
|
+
self.keys.insert(key, id);
|
|
132
|
+
self.groups.insert(
|
|
133
|
+
id,
|
|
134
|
+
Group {
|
|
135
|
+
namespace,
|
|
136
|
+
descriptor,
|
|
137
|
+
version: 0,
|
|
138
|
+
captures: 1,
|
|
139
|
+
residents: 0,
|
|
140
|
+
sources: HashMap::new(),
|
|
141
|
+
},
|
|
142
|
+
);
|
|
143
|
+
Some((id, 0, fallback))
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
pub fn valid(&self, guard: Guard) -> bool {
|
|
147
|
+
self.groups.get(&guard.group).is_some_and(|group| {
|
|
148
|
+
group.version == guard.version
|
|
149
|
+
&& self.namespaces[&group.namespace].fallback == guard.fallback
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
pub fn retain_row(&mut self, id: u64) {
|
|
154
|
+
let group = self.groups.get_mut(&id).expect("reserved proof group");
|
|
155
|
+
group.residents += 1;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
pub fn release(&mut self, guard: Guard, capture: bool) {
|
|
159
|
+
let id = guard.group;
|
|
160
|
+
let Some(group) = self.groups.get_mut(&id) else {
|
|
161
|
+
return;
|
|
162
|
+
};
|
|
163
|
+
if capture {
|
|
164
|
+
group.captures -= 1;
|
|
165
|
+
} else if group.version == guard.version {
|
|
166
|
+
group.residents -= 1;
|
|
167
|
+
}
|
|
168
|
+
if group.captures != 0 || group.residents != 0 {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
self.remove(id);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
fn remove(&mut self, id: u64) {
|
|
175
|
+
let group = self.groups.remove(&id).expect("reclaimed proof group");
|
|
176
|
+
let namespace = self
|
|
177
|
+
.namespaces
|
|
178
|
+
.get_mut(&group.namespace)
|
|
179
|
+
.expect("proof namespace");
|
|
180
|
+
namespace.groups.remove(&id);
|
|
181
|
+
if let Some(partition) = &group.descriptor.partition {
|
|
182
|
+
let groups = namespace
|
|
183
|
+
.partitions
|
|
184
|
+
.get_mut(partition)
|
|
185
|
+
.expect("proof partition");
|
|
186
|
+
groups.remove(&id);
|
|
187
|
+
if groups.is_empty() {
|
|
188
|
+
namespace.partitions.remove(partition);
|
|
189
|
+
}
|
|
190
|
+
} else {
|
|
191
|
+
namespace.unpartitioned.remove(&id);
|
|
192
|
+
}
|
|
193
|
+
if namespace.groups.is_empty() {
|
|
194
|
+
self.namespaces.remove(&group.namespace);
|
|
195
|
+
}
|
|
196
|
+
self.keys.remove(&(group.namespace, group.descriptor));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
pub fn insert(&mut self, namespace: u64, partition: &[u8]) {
|
|
200
|
+
if let Some(groups) = self.namespaces.get_mut(&namespace) {
|
|
201
|
+
for ids in [
|
|
202
|
+
Some(&groups.unpartitioned),
|
|
203
|
+
groups.partitions.get(partition),
|
|
204
|
+
]
|
|
205
|
+
.into_iter()
|
|
206
|
+
.flatten()
|
|
207
|
+
{
|
|
208
|
+
for id in ids {
|
|
209
|
+
self.groups
|
|
210
|
+
.get_mut(id)
|
|
211
|
+
.expect("indexed partition group")
|
|
212
|
+
.invalidate(&mut groups.families);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
pub fn unknown(&mut self, namespace: u64) {
|
|
219
|
+
if let Some(groups) = self.namespaces.get_mut(&namespace) {
|
|
220
|
+
groups.fallback += 1;
|
|
221
|
+
groups.families = HashMap::new();
|
|
222
|
+
for id in &groups.groups {
|
|
223
|
+
let group = self.groups.get_mut(id).expect("proof group");
|
|
224
|
+
group.sources = HashMap::new();
|
|
225
|
+
group.version += 1;
|
|
226
|
+
group.residents = 0;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
pub fn update(&mut self, namespace: u64, paths: &[String]) {
|
|
232
|
+
if let Some(groups) = self.namespaces.get_mut(&namespace) {
|
|
233
|
+
for id in &groups.groups {
|
|
234
|
+
let group = self.groups.get_mut(id).expect("indexed namespace group");
|
|
235
|
+
let independent =
|
|
236
|
+
group
|
|
237
|
+
.descriptor
|
|
238
|
+
.dependencies
|
|
239
|
+
.as_ref()
|
|
240
|
+
.is_some_and(|dependencies| {
|
|
241
|
+
!dependencies.iter().any(|dependency| {
|
|
242
|
+
paths.iter().any(|path| {
|
|
243
|
+
path == dependency
|
|
244
|
+
|| path
|
|
245
|
+
.strip_prefix(dependency)
|
|
246
|
+
.is_some_and(|suffix| suffix.starts_with('.'))
|
|
247
|
+
|| dependency
|
|
248
|
+
.strip_prefix(path)
|
|
249
|
+
.is_some_and(|suffix| suffix.starts_with('.'))
|
|
250
|
+
})
|
|
251
|
+
})
|
|
252
|
+
});
|
|
253
|
+
if !independent {
|
|
254
|
+
group.invalidate(&mut groups.families);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
pub fn close(&mut self) {
|
|
261
|
+
for namespace in self.namespaces.values_mut() {
|
|
262
|
+
namespace.families = HashMap::new();
|
|
263
|
+
}
|
|
264
|
+
let ids: Vec<_> = self.groups.keys().copied().collect();
|
|
265
|
+
for id in ids {
|
|
266
|
+
let group = self.groups.get_mut(&id).expect("closing proof group");
|
|
267
|
+
group.sources = HashMap::new();
|
|
268
|
+
group.residents = 0;
|
|
269
|
+
if group.captures == 0 {
|
|
270
|
+
self.remove(id);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
@@ -132,21 +132,6 @@ impl Probes {
|
|
|
132
132
|
self.entries.clear();
|
|
133
133
|
self.order.clear();
|
|
134
134
|
}
|
|
135
|
-
|
|
136
|
-
fn snapshot(&self) -> Vec<(String, String, u64, usize)> {
|
|
137
|
-
self.order
|
|
138
|
-
.values()
|
|
139
|
-
.map(|names| {
|
|
140
|
-
let probe = &self.entries[names];
|
|
141
|
-
(
|
|
142
|
-
names.0.to_string(),
|
|
143
|
-
names.1.to_string(),
|
|
144
|
-
probe.token,
|
|
145
|
-
probe.active,
|
|
146
|
-
)
|
|
147
|
-
})
|
|
148
|
-
.collect()
|
|
149
|
-
}
|
|
150
135
|
}
|
|
151
136
|
|
|
152
137
|
struct Published {
|
|
@@ -167,7 +152,7 @@ pub(super) struct Residency {
|
|
|
167
152
|
tokens: HashMap<u64, Handle>,
|
|
168
153
|
queries: HashMap<u64, HashSet<u64>>,
|
|
169
154
|
identities: HashMap<u64, HashSet<u64>>,
|
|
170
|
-
available_since: HashMap<Arc<str>, Option<f64
|
|
155
|
+
available_since: Option<HashMap<Arc<str>, Option<f64>>>,
|
|
171
156
|
}
|
|
172
157
|
|
|
173
158
|
fn now_seconds() -> f64 {
|
|
@@ -175,8 +160,13 @@ fn now_seconds() -> f64 {
|
|
|
175
160
|
}
|
|
176
161
|
|
|
177
162
|
impl Residency {
|
|
178
|
-
pub(super) fn new(
|
|
179
|
-
|
|
163
|
+
pub(super) fn new(
|
|
164
|
+
index: Py<OwnerIndex>,
|
|
165
|
+
databases: Vec<String>,
|
|
166
|
+
capacity: usize,
|
|
167
|
+
enable_telemetry: bool,
|
|
168
|
+
) -> Self {
|
|
169
|
+
let now = enable_telemetry.then(now_seconds);
|
|
180
170
|
let databases: HashMap<Arc<str>, usize> = databases
|
|
181
171
|
.into_iter()
|
|
182
172
|
.enumerate()
|
|
@@ -186,10 +176,12 @@ impl Residency {
|
|
|
186
176
|
index.get().index.set_available(*slot, true);
|
|
187
177
|
}
|
|
188
178
|
Self {
|
|
189
|
-
available_since:
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
179
|
+
available_since: now.map(|now| {
|
|
180
|
+
databases
|
|
181
|
+
.keys()
|
|
182
|
+
.map(|name| (name.clone(), Some(now)))
|
|
183
|
+
.collect()
|
|
184
|
+
}),
|
|
193
185
|
index,
|
|
194
186
|
databases,
|
|
195
187
|
capacity,
|
|
@@ -247,14 +239,22 @@ impl Residency {
|
|
|
247
239
|
let Some(slot) = self.database(database) else {
|
|
248
240
|
return;
|
|
249
241
|
};
|
|
250
|
-
if let Some(since) = self
|
|
242
|
+
if let Some(since) = self
|
|
243
|
+
.available_since
|
|
244
|
+
.as_mut()
|
|
245
|
+
.and_then(|history| history.get_mut(database))
|
|
246
|
+
{
|
|
251
247
|
*since = available.then(now_seconds);
|
|
252
248
|
}
|
|
253
249
|
self.index.get().index.set_available(slot, available);
|
|
254
250
|
}
|
|
255
251
|
|
|
256
252
|
pub(super) fn available_since(&self, database: &str) -> Option<f64> {
|
|
257
|
-
self.available_since
|
|
253
|
+
self.available_since
|
|
254
|
+
.as_ref()
|
|
255
|
+
.and_then(|history| history.get(database))
|
|
256
|
+
.copied()
|
|
257
|
+
.flatten()
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
pub(super) fn store(&self, payload: &[u8]) -> Option<Block> {
|
|
@@ -458,9 +458,11 @@ impl SharedOwner {
|
|
|
458
458
|
namespaces: usize,
|
|
459
459
|
probe_ttl_seconds: f64,
|
|
460
460
|
) -> PyResult<PyClassInitializer<Self>> {
|
|
461
|
+
let enable_telemetry = config.getattr("enable_telemetry")?.extract::<bool>()?;
|
|
461
462
|
let shared = SharedState {
|
|
462
463
|
probes: Probes::new((probe_ttl_seconds * 1e9) as u64),
|
|
463
|
-
residency: index
|
|
464
|
+
residency: index
|
|
465
|
+
.map(|index| Residency::new(index, databases, namespaces, enable_telemetry)),
|
|
464
466
|
};
|
|
465
467
|
Ok(
|
|
466
468
|
PyClassInitializer::from(LocalOwner::create(py, Some(config), Some(shared))?)
|
|
@@ -693,18 +695,6 @@ impl SharedOwner {
|
|
|
693
695
|
}
|
|
694
696
|
}
|
|
695
697
|
|
|
696
|
-
fn _probes(slf: &Bound<'_, Self>) -> Vec<(String, String, u64, usize)> {
|
|
697
|
-
let mut state = slf
|
|
698
|
-
.as_super()
|
|
699
|
-
.get()
|
|
700
|
-
.state
|
|
701
|
-
.lock()
|
|
702
|
-
.expect("local owner mutex");
|
|
703
|
-
let probes = &mut shared_state(&mut state).probes;
|
|
704
|
-
probes.expire(monotonic_ns());
|
|
705
|
-
probes.snapshot()
|
|
706
|
-
}
|
|
707
|
-
|
|
708
698
|
fn published(slf: &Bound<'_, Self>) -> usize {
|
|
709
699
|
slf.as_super()
|
|
710
700
|
.get()
|
|
@@ -715,13 +705,15 @@ impl SharedOwner {
|
|
|
715
705
|
.map_or(0, Residency::published_count)
|
|
716
706
|
}
|
|
717
707
|
|
|
718
|
-
fn available_since(slf: &Bound<'_, Self>, database: &str) -> Option<f64
|
|
719
|
-
slf.as_super()
|
|
708
|
+
fn available_since(slf: &Bound<'_, Self>, database: &str) -> PyResult<Option<f64>> {
|
|
709
|
+
slf.as_super().get().require_telemetry(slf.py())?;
|
|
710
|
+
Ok(slf
|
|
711
|
+
.as_super()
|
|
720
712
|
.get()
|
|
721
713
|
.state
|
|
722
714
|
.lock()
|
|
723
715
|
.expect("local owner mutex")
|
|
724
716
|
.residency()
|
|
725
|
-
.and_then(|residency| residency.available_since(database))
|
|
717
|
+
.and_then(|residency| residency.available_since(database)))
|
|
726
718
|
}
|
|
727
719
|
}
|