Repository navigation
Reduce SpiralDB source metadata round trips - #527
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Connector lookup and table operations src/orcapod/databases/spiraldb_connector.py, tests/test_databases/fake_pyspiral.py |
The connector adds exact table lookup, client sharing, and table-handle batch-scan and row-count operations. The fake SDK adds matching identifier resolution and manifest-statistics behavior. |
Source initialization and connector lifetime src/orcapod/core/sources/spiraldb_table_source.py, tests/test_core/sources/test_spiraldb_table_source.py, tests/test_core/sources/test_spiraldb_lookups.py |
The source owns a connector, uses direct table lookup during construction, and closes the connector on initialization failure or context exit. Restricted copies use separate connectors that share the SDK client. Tests cover connector closure, lookup behavior, and client reuse. |
Read and freshness table resolution src/orcapod/core/sources/spiraldb_table_source.py, tests/test_core/sources/test_spiraldb_lookups.py, tests/test_core/sources/test_spiraldb_table_source_streaming.py, changelog.d/ITL-1431.md |
Reads and freshness checks resolve a table handle and use it for metadata, row-count, and scan operations. Reads use the pinned version and reject a replacement table whose ID differs from the captured ID. Tests cover read lookup counts, freshness checks, and table replacement. |
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Refactor
Sequence Diagram(s)
sequenceDiagram
participant SpiralDBTableSource
participant SpiralDBConnector
participant SpiralDBTable
SpiralDBTableSource->>SpiralDBConnector: lookup_table
SpiralDBConnector-->>SpiralDBTableSource: resolved table handle
opt Row count estimate needed
SpiralDBTableSource->>SpiralDBTable: row_count_estimate at pinned version
SpiralDBTable-->>SpiralDBTableSource: estimated row count
end
SpiralDBTableSource->>SpiralDBTable: scan_batches at pinned version
SpiralDBTable-->>SpiralDBTableSource: record batches
Possibly related PRs
- metamorphic-labs/orcapod-python#479: It changes table lookup behavior in SpiralDBTableSource and adds lookup-count tests in the same test module.
- metamorphic-labs/orcapod-python#333: It introduced metadata-based source construction and batched reads that this PR modifies.
Merge Risk: 
Minimal · up to e5b6a
-
This change reduces SpiralDB round trips by reusing one client and one resolved table handle per read. It adds explicit source closing, and a source that has been closed now raises RuntimeError if used. Reads against a dropped and recreated table are now refused. The reviewed code and test coverage show no concrete merge-blocking problem.
Security architecture risk: 
Low · up to e5b6a
-
Reads now keep the table identity and version consistent. The remaining risk is limited to reads on a source that is closed while work is still in progress, including after async cancellation. Closing the source can interrupt a read, but it does not reliably stop a scan that has already started.
Retained concerns
- Low · reliability · inferred: The head lets source shutdown close a connector still in use by a read; the base kept the connector scoped to the operation. Although callers are told to close only after reads finish, cancelling an async consumer can leave its worker running. An overlapping close can make a read fail between its open check and SDK access, while an already-created scan can continue. The effect is scoped to work using the connector being closed; separately closable copies are not invalidated.
Security review details
-
Security Blast Radius
- inferred — Client sharing couples a source and its restricted copies to the same SDK session, but it does not add another configured principal, project, or dataset. Closing a wrapper is local cleanup, not credential revocation or shutdown of the shared client.
Trust Boundaries and Controls
- observed — The connector qualifies the supplied table name with its configured dataset and rejects empty or dotted dataset and table names before calling the SDK. It translates only the exact SDK not-found error and propagates other failures. The source separately verifies the resolved table ID before scanning or counting.
Hardening Proposals
- proposed — Define shutdown and cancellation behavior together. Let active reads retain the client until they finish, while rejecting new reads after close, or ensure that async consumers wait for their worker before exiting the source context.
Pre-merge checks: 
4
-
Full details: Title check
-
Explanation
The title "Reduce SpiralDB source metadata round trips" matches the main change. The PR resolves the table once per read, reuses the source-owned SDK client across construction, reads, and freshness checks, and reduces visible HTTP requests. The title is short, specific, and reads clearly in history.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Usage-based review receipt
- Mode: Review on demand
- Reviewed files: 7
- Charged: $1.75
- View usage details
Note
This review was completed with usage-based billing: files reviewed beyond your plan's included limits are billed at $0.25/file. View usage-based billing.
Codecov Report❌ Patch coverage is
... and 5 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Fixes ITL-1431
Changes
Findings and coverage
test_a_source_looks_its_table_up_once_to_build,test_missing_table_matches_source_diagnostic,test_lookup_preserves_unrelated_sdk_errorstest_each_read_resolves_once_and_reuses_its_clientacross two key orders in sync and asynctest_each_read_resolves_once_and_reuses_its_client,test_job_reuses_client_but_refreshes_table_each_run,test_restricted_copy_owns_its_client,test_every_connector_is_closedtest_a_check_still_finds_a_table_created_again,test_freshness_catches_metadata_schema_changes,test_freshness_pins_newer_versionFake SDK operation counts
Each case used a fake table with two tags and two data columns. The counts match across both key orders and sync and async execution. A restricted copy opens its own client on first use. Repeated reads of that copy reuse it.
Live before and after
Live wall seconds, before → after. Five interleaved samples per cell.
Live visible HTTP request counts, before → after. Native SDK storage requests are outside this counter.
One-minute load average 2.39–6.20. Retried samples: 0.
The first restricted sample used a new copy in both versions. It still made two HTTP requests. The second job run refreshed the source once and reused the held result.
Validation
Summary by CodeRabbit