Repository navigation
Allow clj api to work with closed api ledger - #158
Merged
Merged
Conversation
cap10morgan
approved these changes
Mar 9, 2022
cap10morgan
left a comment
Contributor
There was a problem hiding this comment.
Some questions but no blockers. Is the JSON vs. AVRO in closed API due to the need to filter based on permissions or something?
Also update `default-read-fn` to request json, and remove redundant reader conditionals.
Contributor
Author
|
@cap10morgan No, it's not permissions based, it's actually a pretty arbitrary (I checked with Brian) check in ledger that just refuses to serve avro over a closed api: I could have changed it there, and still might, but I wanted to get it working really quickly, which made me look at ways to change the client to get it working instead of re-deploying the server. Now that I know this works, I would rather fix it on the server and then change the client back to speak avro, since it's lighter on the wire. |
7 of 8 tasks
aaj3f
added a commit
that referenced
this pull request
Apr 30, 2026
Two paired fixes that together unblock first-time reindex on lambdas where a long commit chain forces `LedgerState::load` to walk every commit before the rebuild can start. ## What's wrong `LedgerState::load_novelty` walks the full chain via `trace_commits_by_id` and replays each commit's flakes through `Novelty::apply_commit`. That per-commit path runs an LSM-style two-way merge per index (4 indexes × M commits) — `O(target.len() + batch.len())` per merge accruing to `O(M·N̄)` over the chain. For a 787-commit production ledger with ~9k ops/commit this measured at ~13 minutes on a 10 GB single-vCPU lambda, exceeding the 900s reindex ceiling. The hang was silent because `apply_commit`'s progress emit lives in `fluree_db_novelty` (not in any rebuild log target), so cloudwatch saw 11+ minutes of nothing between `Loaded ledger state for queued indexing work` and a timeout — masking which phase was at fault. `BranchedContentStore` (`fluree-db-core/src/storage.rs`) implemented `get`, `has`, `put`, etc., but **not** `get_range`. The trait default falls back to `get` + slice. Branched ledgers therefore silently nullify PR #158's envelope-only byte-range probe in `load_commit_envelope_by_id` — every Phase A envelope read becomes a full-blob fetch. The blocking production case here is non-branched so this isn't its proximal cause, but it's a regression vector waiting for the next branched ledger reindex. ## What changes `fluree-db-novelty/src/lib.rs` — adds `Novelty::bulk_apply_commits`: - Routes every flake into a per-graph bucket in one ingest pass. - Sorts each graph by an identity-then-t key (`s, p, o, dt, m, t, op`) via `par_sort_unstable_by`. - Walks each `(s, p, o, dt, m)` group linearly to apply set semantics — drops an assertion only when the prior kept flake for the same identity was also an assertion (mirrors `apply_commit`'s `fact_currently_asserted_in_graph` skip rule); always keeps retractions. - Re-sorts the deduped set into the 4 index orders (SPOT/PSOT/POST/OPST) once each. Total work is `O(N log N)` regardless of how many commits the chain contains. For the 787-commit case this drops the catch-up from minutes to under ten seconds on lambda. Existing graph contents are merged into the dedup pass alongside the new batches so the post-condition matches what a sequential per-commit `apply_commit` chain would have produced. `epoch` bumps once per call. Helper functions `cmp_object`, `cmp_meta`, and `same_identity` mirror `fluree_db_core::comparator`'s private comparators so the dedup walk groups by exactly the same `(s, p, o, dt, m)` identity that `apply_commit` checks. They're file-local — no public API surface added beyond the new method itself. `fluree-db-ledger/src/lib.rs::load_novelty` — switches the deferred-batch replay loop from per-commit `apply_commit` to a single `bulk_apply_commits` call. The dict-novelty population still runs per-batch in commit order so overlay translation invariants are preserved before the bulk apply. `fluree-db-core/src/storage.rs` — implements `ContentStore::get_range` on `BranchedContentStore`. Mirrors the `get` semantics: try the branch's own store first, fall through to ancestor stores on `NotFound`. Crucially calls `get_range` on each ancestor (not the trait default fallback), so range-capable backends keep their byte- range optimization across the entire branch ancestry. ## Verification - `cargo check -p fluree-db-core -p fluree-db-novelty -p fluree-db-ledger` passes. - `cargo nextest run -p fluree-db-novelty -p fluree-db-ledger --no-fail-fast` — 62/62 pass, including the existing set-semantics tests (`test_apply_commit_skips_duplicate_assertions_across_commits`, `test_apply_commit_allows_reassert_after_retract`, `test_apply_commit_does_not_dedup_distinct_metadata`, `test_per_graph_isolation`) which exercise the dedup invariants `bulk_apply_commits` is required to preserve. End-to-end lambda validation + multi-commit perf regression test land in the next commits in this branch (orchestrator-path test asserting wall-clock budget + a streaming envelope-aware `ApiFulltextConfigProvider` that skips full novelty load when only the config graph is needed).
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.
A closed api ledger will not send avro/binary on the wire. This commit changes the
default clojure connection to speak json - the default-read-fn now requests json instead
of avro, and the serializer now expects json.
FC-1372
FC-1370