Skip to content

feat(python): Ledger.refresh() takes in another connection's commits - #2037

Closed
bplatz wants to merge 1 commit into
mainfrom
feat/python-ledger-refresh
Closed

bplatz wants to merge 1 commit into
mainfrom
feat/python-ledger-refresh

Conversation

@bplatz

@bplatz bplatz commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Several processes can share one Fluree storage directory, but a Python connection keeps the state of each ledger it has read. Its queries therefore never saw another process's commits until it reconnected. Ledger.refresh() (and fluree.aio's await ledger.refresh()) catches the ledger up with the nameservice head and returns the latest t:

commit = writer.insert(...)          # in another process
reader.refresh()                     # == commit.t
reader.query(...)                    # sees it

Details

  • refresh() wraps the engine's Fluree::refresh. That call only updates a ledger already in the cache: for one this connection hasn't read yet, it reports t 0. So the binding loads the ledger first; a cold load reads the head anyway.
  • Writes need no refresh. A commit that meets a newer head from another process hits a commit conflict, and the engine refreshes and re-stages it on that head. This is true of insert/upsert/update, transaction() and transact() alike, and the docstring says so.
  • It's allowed on a governed (with_policy) handle: it reveals only the head t, which snapshot().t already does.
  • A Snapshot keeps the state it froze.
  • I left out the engine's min_t option. It only compares the returned t, which the caller can do directly.
  • The README's Concurrency section and the book's Python page mention it.

Tests

  • test_a_refresh_takes_in_another_connections_commits: two file connections on one directory stand in for two processes. The test covers a stale read before refresh(), the returned t, and the fresh read after. It also refreshes a ledger the connection hasn't read yet, which pins the cold-load case.
  • test_the_api_end_to_end (aio) calls refresh().

A connection keeps the state of each ledger it has read, so a process
sharing a storage directory saw another process's commits only after
reconnecting. Ledger.refresh() catches the ledger up with the
nameservice head and returns the latest t, loading it first when this
connection has not read it yet (the engine's refresh leaves an uncached
ledger alone and reports t 0). Writes already catch up on their own: a
commit that meets a newer head is retried against it.
@bplatz bplatz added the enhancement New feature or request label Oct 8, 2026
@bplatz
bplatz requested a review from aaj3f October 8, 2026 15:03
@bplatz

bplatz commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Closing for now. refresh() makes reads catch up across processes that share one storage directory, but that isn't a setup we support: indexing and sweep aren't coordinated across processes (#1635). We'll come back to this once we've decided how a second process opening the same directory should be handled. The branch is kept.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant