Commit 2768118
refactor(object_store): lazy fetch returns PayloadView (#103)
* refactor(object_store): lazy fetch returns PayloadView; payload slot uses std::any
The lazy resolver registered with ObjectStore::pushLazy now returns a
PayloadView (Span + BufferAnchor) instead of a std::vector<uint8_t>. This
lets producers hand off bytes they already hold behind a shared_ptr (e.g.
a streaming buffer being reused across stores) without copying — the
returned anchor extends the buffer's lifetime through the read.
For producers whose only payload is a plain std::vector<uint8_t>, the new
sdk::makePayloadView() helper in pj_base wraps the vector into a
shared_ptr (which becomes both owner and type-erased anchor) and returns
a PayloadView pointing at its contents. This is also the contract
resolveEntry() relies on: it recovers the shared_ptr<const vector> from
the anchor via static_pointer_cast.
ObjectEntry::payload now stores a std::any instead of a
std::variant<shared_ptr, std::function>. The dispatch in
ObjectStore::resolveEntry uses std::any_cast for each branch. Rationale:
the variant alternatives are not part of any public discriminator
(callers go through pushOwned/pushLazy), so the variant tag was carrying
no semantic value — std::any keeps the storage slot flexible without
constraining future producer shapes.
* refactor(object_store): preserve BufferAnchor end-to-end; restore typed variant
Builds on the prior commit's PayloadView-returning pushLazy signature, but
fixes two anchor-discarding bugs and restores a typed payload variant.
Bugs in the prior implementation:
1. resolveEntry did static_pointer_cast<const vector<uint8_t>>(pv.anchor),
forcing every producer's anchor to be exactly a shared_ptr<vector>. Any
other anchor type (chunk cache, mmap, parquet column slice) was UB. This
negated the entire point of BufferAnchor = shared_ptr<const void>.
2. resolveEntry discarded PayloadView::bytes (the Span) and returned the
whole anchor's vector. Producers can no longer publish a sub-range of
a larger backing buffer — which is the canonical zero-copy use case
(one decompressed MCAP chunk anchored once, many message Spans into it).
Both bugs traced to a single root cause: ResolvedObjectEntry::data was still
shared_ptr<const vector<uint8_t>>, so resolution had to materialize a vector
somehow. Fixed by making ResolvedObjectEntry carry {BufferAnchor anchor,
Span<const uint8_t> view} — type-erased anchor + producer-published span.
No static_pointer_cast anywhere.
Variant + named aliases:
ObjectEntry::payload returns to std::variant; the prior std::any traded
compile-time exhaustiveness for nothing (still two alternatives, still
typed access via the cast). Two named aliases capture the two payload
shapes at the type level:
using SharedBuffer = std::shared_ptr<const std::vector<uint8_t>>;
using LazyCallback = std::function<sdk::PayloadView()>;
Trampolines (plugin_data_host.cpp):
ObjectBytesBox now holds {BufferAnchor, Span}; toolboxObjectGetBytes
returns view.data()/view.size() — no shared_ptr<vector> in the read path.
Misc consistency:
- pushOwned/pushLazy now return Status (alias for Expected<void, string>);
the one other Expected<void, string> use at service_registry_builder.hpp
also switched.
- PayloadView(shared_ptr<vector>) constructor takes shared_ptr<const vector>
to match SharedBuffer and makePayloadView.
Tests:
- All resolved->data accessors migrated to resolved->view / resolved->anchor
across object_store_test, plugin_data_host_object_test,
plugin_parser_object_write_test.
- Two regression tests added:
PushLazyPreservesAnchorType — anchor is shared_ptr<TestBuffer> (not
vector). Bug-1 regression: ASAN would catch the prior static cast.
PushLazyHonorsSpanSubview — anchor is a 100-byte vector with Span
[20,30). Bug-2 regression: verifies view.data()==chunk+20.
./build.sh --debug && ./test.sh → 62/62 passing under ASAN.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* refactor(object_store): consolidate ResolvedObjectEntry/ObjectBytesBox on PayloadView
ResolvedObjectEntry and ObjectBytesBox both held an inline {anchor, view}
pair — the same shape as sdk::PayloadView. Collapse both onto a single
PayloadView field; one named point of truth for "bytes + their lifetime
anchor" across producer, store, and consumer-handle layers.
Also tightens the doc comments touched in the prior commit.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore: bump version to 0.5.0
Source-incompatible changes in pj_datastore/object_store.hpp:
- ObjectEntry::payload variant tag types
- pushLazy fetch signature (returns PayloadView)
- ResolvedObjectEntry field layout (carries a PayloadView)
Per the pre-1.0 convention, this warrants a MINOR bump.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs(object_store): sync design doc with PayloadView refactor
OBJECT_STORE_DESIGN.md still described the pre-refactor API: a
vector-returning lazy callback and a ResolvedObjectEntry carrying a
shared_ptr<const vector<uint8_t>> data field. Bring it in line with the
code already on this branch:
- ObjectEntry::payload is std::variant<SharedBuffer, LazyCallback>;
document the two named aliases.
- pushLazy's callable returns sdk::PayloadView (Span + type-erased
BufferAnchor), enabling zero-copy sub-range views; the store never
copies on resolve.
- ResolvedObjectEntry carries an sdk::PayloadView; bytes/anchor replace
the old data field, and an empty anchor means "no bytes".
Docs-only; no behavior change.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Davide Faconti <davide.faconti@gmail.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent a8d117d commit 2768118
11 files changed
Lines changed: 163 additions & 57 deletions
File tree
- pj_base/include/pj_base
- pj_datastore
- docs
- include/pj_datastore
- src
- tests
- pj_plugins/include/pj_plugins/host
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
205 | | - | |
| 205 | + | |
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
47 | | - | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
52 | 66 | | |
53 | 67 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
33 | 38 | | |
34 | 39 | | |
35 | | - | |
36 | | - | |
37 | | - | |
| 40 | + | |
38 | 41 | | |
39 | 42 | | |
40 | 43 | | |
| |||
55 | 58 | | |
56 | 59 | | |
57 | 60 | | |
58 | | - | |
59 | | - | |
60 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
61 | 68 | | |
62 | 69 | | |
63 | 70 | | |
| |||
80 | 87 | | |
81 | 88 | | |
82 | 89 | | |
83 | | - | |
| 90 | + | |
84 | 91 | | |
85 | 92 | | |
86 | 93 | | |
87 | | - | |
88 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
89 | 98 | | |
90 | 99 | | |
91 | 100 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
41 | 50 | | |
42 | 51 | | |
43 | | - | |
| 52 | + | |
44 | 53 | | |
45 | 54 | | |
46 | 55 | | |
47 | 56 | | |
48 | | - | |
| 57 | + | |
49 | 58 | | |
50 | 59 | | |
51 | 60 | | |
| |||
106 | 115 | | |
107 | 116 | | |
108 | 117 | | |
109 | | - | |
| 118 | + | |
110 | 119 | | |
111 | | - | |
112 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
113 | 124 | | |
114 | 125 | | |
115 | 126 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
71 | | - | |
| 70 | + | |
72 | 71 | | |
73 | 72 | | |
74 | 73 | | |
| |||
94 | 93 | | |
95 | 94 | | |
96 | 95 | | |
97 | | - | |
98 | | - | |
| 96 | + | |
99 | 97 | | |
100 | 98 | | |
101 | 99 | | |
| |||
306 | 304 | | |
307 | 305 | | |
308 | 306 | | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
314 | 316 | | |
315 | 317 | | |
316 | 318 | | |
| |||
322 | 324 | | |
323 | 325 | | |
324 | 326 | | |
325 | | - | |
| 327 | + | |
326 | 328 | | |
327 | 329 | | |
328 | 330 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1392 | 1392 | | |
1393 | 1393 | | |
1394 | 1394 | | |
1395 | | - | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
1396 | 1398 | | |
1397 | 1399 | | |
1398 | 1400 | | |
| |||
1433 | 1435 | | |
1434 | 1436 | | |
1435 | 1437 | | |
1436 | | - | |
1437 | | - | |
| 1438 | + | |
| 1439 | + | |
1438 | 1440 | | |
1439 | | - | |
| 1441 | + | |
1440 | 1442 | | |
1441 | 1443 | | |
1442 | 1444 | | |
| |||
1506 | 1508 | | |
1507 | 1509 | | |
1508 | 1510 | | |
1509 | | - | |
| 1511 | + | |
1510 | 1512 | | |
1511 | 1513 | | |
1512 | 1514 | | |
1513 | 1515 | | |
1514 | | - | |
| 1516 | + | |
1515 | 1517 | | |
1516 | 1518 | | |
1517 | 1519 | | |
| |||
1540 | 1542 | | |
1541 | 1543 | | |
1542 | 1544 | | |
1543 | | - | |
| 1545 | + | |
1544 | 1546 | | |
1545 | 1547 | | |
1546 | 1548 | | |
1547 | | - | |
| 1549 | + | |
1548 | 1550 | | |
1549 | 1551 | | |
1550 | | - | |
| 1552 | + | |
1551 | 1553 | | |
1552 | 1554 | | |
1553 | 1555 | | |
| |||
1631 | 1633 | | |
1632 | 1634 | | |
1633 | 1635 | | |
1634 | | - | |
| 1636 | + | |
1635 | 1637 | | |
1636 | 1638 | | |
1637 | 1639 | | |
| |||
0 commit comments