feat(pj_datastore): add ObjectStore::findTopic(dataset_id, name)#84
Merged
pabloinigoblasco merged 1 commit intomainfrom May 6, 2026
Merged
feat(pj_datastore): add ObjectStore::findTopic(dataset_id, name)#84pabloinigoblasco merged 1 commit intomainfrom
pabloinigoblasco merged 1 commit intomainfrom
Conversation
Add a pure-lookup API to `ObjectStore`:
std::optional<ObjectTopicId>
ObjectStore::findTopic(DatasetId, std::string_view) const noexcept;
Returns the existing handle if a topic with the given
`(dataset_id, topic_name)` is registered, `nullopt` otherwise. Does not
mutate the store.
`registerTopic` keeps its strict semantics: it still returns
`unexpected("topic already registered: ...")` when a duplicate is
attempted. Callers that need find-or-register semantics compose the
two explicitly.
Why
---
`OBJECT_STORE_DESIGN.md` documents that DataSource plugins register
object topics on the source-side path (`pj.source_object_write.v1`),
and host-side runtime code resolves an existing id when binding parser-
side write surfaces (`pj.parser_object_write.v1`) — i.e. the source
owns registration; the host looks up.
Without a lookup-only API the host had to call `registerTopic` from its
parser-binding flow. When a source had already registered the same
topic via its own service, the second caller failed with
`"topic already registered: ..."`, the source-side `pushLazy` path went
silently unwired, and blob channels lost retention.
`findTopic` lets the host honour the documented contract: bind to an
existing id without creating one.
Tests
-----
- `FindTopicReturnsRegisteredId` — happy path lookup after register.
- `FindTopicMissingReturnsNullopt` — explicit miss returns nullopt.
- `DuplicateRegistrationFails` (existing) is left untouched —
`registerTopic`'s strict contract is preserved.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a pure-lookup API to
ObjectStore:Returns the existing handle if a topic with the given
(dataset_id, topic_name)is registered,nulloptotherwise. Does not mutate the store.registerTopickeeps its strict semantics: it still returnsunexpected("topic already registered: ...")when a duplicate is attempted. Callers that need find-or-register semantics compose the two explicitly.Why
pj_datastore/docs/OBJECT_STORE_DESIGN.mddocuments the responsibility split:pj.source_object_write.v1).pj.parser_object_write.v1).In other words: the source owns registration; the host looks up.
Until now the host had no lookup-only API, so it called
registerTopicfrom its parser-binding flow. When a source had already registered the same topic via its own service, the second caller failed with"topic already registered: ...", the source-sidepushLazypath went silently unwired, and blob channels lost retention.findTopiclets the host honour the documented contract: bind to an existing id without creating one.Diff
pj_datastore/include/pj_datastore/object_store.hppfindTopicpj_datastore/src/object_store.cppstd::shared_lockon the store mutex; linear scan overtopics_keyed by(dataset_id, name), same shape asregisterTopic's duplicate check)pj_datastore/tests/object_store_test.cppTotal: +32 / −0 across 3 files.
Tests
FindTopicReturnsRegisteredId— happy path lookup after register.FindTopicMissingReturnsNullopt— explicit miss returns nullopt.DuplicateRegistrationFails(existing) is left untouched —registerTopic's strict contract is preserved.Backward compatibility
Pure addition. Existing callers of
registerTopicare unchanged. No semantic changes to existing APIs.