Implementation of Dependency.release() and Depedency.reopen() - #490
Open
superhellth wants to merge 9 commits into
Open
superhellth wants to merge 9 commits into
superhellth wants to merge 9 commits into
Conversation
Allow releasing the DB file handle without saving and re-reading the DB afterwards. Needed by commands (e.g. plugins) that watch task state live without persisting anything. Backends without release() keep working. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Motivation:
Needed for the planned TUI plugin. Ensure TUI can stay open in one terminal, while doit jobs run in another. Generic interface provided for plugins to use.
Provided interface [new]:
has_changes() -> bool: Trueif the backend holds changes not yet written to the file. It is alwaysFalseonce the DB is closed.release(discard=False): closes the handle without saving. It raisesUnsavedChangesErrorifhas_changes()is true and discard is not set. When it raises, the DB stays open andclose()still saves.reopen(discard=False): callsrelease(discard), then reopens the file.Main Cost:
To make that check reliable, all three backends (JsonDB, DbmDB, SqliteDB) now buffer every mutation in memory and touch the file only in
dump(). A read-only user of the DB never writes to it or takes a write lock.Changes:
has_changes()on every backend, backed by a sticky_changedflag.set()andremove_all()set it.remove()sets it only if the id is in the file or in the dirty set. Reads never set it.UnsavedChangesErrorsubclassesDatabaseException, so existingexcept DatabaseExceptionhandlers keep working. When it raises, the DB stays open andclose()still saves.remove()andremove_all()record_removed/_truncateand apply them indump(). Before, they deleted from the file immediately, sorelease()couldnot undo them.
DbmDB.dump()tolerates keys another process already removed.SqliteDB.get()fix. It used to cache a missing row, soin_()then reported an id as present just because it had been read. It now caches only real rows, andin_()checks the file with aread-only query. This also fixes a misleading
get_value()error for unknown task ids.has_changes()orrelease()still work. Dependency usesgetattrand treats a missing method as "no changes" or "keep handle".Testing:
has_changes(), the release guard, deferred removals,in_()after a read, and a sqlite3 no-write-lock check. They run on json, sqlite3, dbm.gnu,dbm.ndbm and dbm.dumb.
test_release_does_not_savenow usesrelease(discard=True).get_status()regression test covers thechecker_changedpath. It fails ifrelease(discard=True)is swapped forclose().