Skip to content

bag_of_holding: move persistence to async - #4222

Open
nicoschmdt wants to merge 1 commit into
bluerobotics:masterfrom
nicoschmdt:async-boh
Open

bag_of_holding: move persistence to async#4222
nicoschmdt wants to merge 1 commit into
bluerobotics:masterfrom
nicoschmdt:async-boh

Conversation

@nicoschmdt

Copy link
Copy Markdown
Collaborator

as discussed in #4180 (comment)

@github-actions

Copy link
Copy Markdown

Automated PR Review

0. Summary

  • Verdict: LGTM :shipit:

Moves bag_of_holding persistence off the event loop: replaces the call_later + SimpleNamespace handle pattern with an asyncio.Event-driven background flusher, offloads the actual disk write via asyncio.to_thread, and guards mutation/serialization with db_lock and the temp-file write with disk_lock. Shutdown drains the flusher between writes and performs one final flush. The tricky invariants (clearing the dirty flag with the snapshot; not cancelling mid-thread-write) are called out in comments in the diff.

No further comments, nice job 👍

Generated by PR Review Bot. This is advisory, a human reviewer must still approve.

except Exception:
logger.exception("Failed to persist database")
_pending.handle = asyncio.get_running_loop().call_later(FLUSH_INTERVAL, _flush)
db_dirty.set()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to be sure.. how are we supposed to know that the write operation failed ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pint here is that: It failed to write in disk, we still return success.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should put the write_db logic inside flush, to raise any issues when writing to disk.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants