-
Notifications
You must be signed in to change notification settings - Fork 1.4k
refactor(sqlite): add check_cursor_valid method for cursor state validation #6342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(sqlite): add check_cursor_valid method for cursor state validation #6342
Conversation
WalkthroughExtracts cursor state checks in the SQLite module into helper functions ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (1)**/*.rs📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
🔇 Additional comments (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
crates/stdlib/src/sqlite.rs (1)
1592-1627: Centralized cursor state checking looks correct; minor optional API tweakThe extraction into
cursor_state_errorand reuse in bothinnerandcheck_cursor_validcorrectly preserves existing error conditions for closed and uninitialized cursors while reducing duplication. The short‑lived mutex guard incheck_cursor_validachieves the goal of not retaining the lock across later work.If you want to simplify the helper further, you could consider returning
PyResult<()>fromcursor_state_errorand using?at call sites instead ofOption<PyBaseExceptionRef>, but this is purely stylistic.
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/stdlib/src/sqlite.rs(2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style by runningcargo fmtto format Rust code
Always run clippy to lint Rust code (cargo clippy) before completing tasks and fix any warnings or lints introduced by changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass,pymodule,pyfunction, etc.) when implementing Python functionality in Rust
Files:
crates/stdlib/src/sqlite.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Run snippets and cpython tests on wasm-wasi
- GitHub Check: Check the WASM package and demo
- GitHub Check: Run tests under miri
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
- GitHub Check: Run rust tests (windows-latest)
- GitHub Check: Run rust tests (macos-latest)
- GitHub Check: Run rust tests (ubuntu-latest)
- GitHub Check: Check Rust code with clippy
- GitHub Check: Ensure compilation on various targets
🔇 Additional comments (1)
crates/stdlib/src/sqlite.rs (1)
1785-1792: executescript no longer holds the cursor mutex for the whole script executionSwitching
executescriptto callcheck_cursor_valid(vm)?instead of relying oninner(vm)?means the cursor’s state is validated, but the cursor mutex is not held while running the prepare/step loop on the connection. This aligns with the PR objective and should reduce unnecessary lock contention without changing the observable error behavior for closed or uninitialized cursors.
89d1bdc to
d07bb03
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
crates/stdlib/src/sqlite.rs (1)
1592-1619: Nice consolidation of cursor state checks; minor doc nit onlyThe new
check_cursor_state, updatedinner, andcheck_cursor_validnicely centralize the “closed/uninitialized” logic and keep the existing error messages/behavior while avoiding holding the cursor mutex longer than necessary. Theunwrap_uncheckedremains justified by the prior state check.One tiny suggestion: the doc comment on
check_cursor_validsays “without holding the lock”, but the method does acquire the lock briefly and just doesn’t retain the guard. Consider rephrasing to “without retaining the lock/guard” to avoid confusion for future readers.
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/stdlib/src/sqlite.rs(2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style by runningcargo fmtto format Rust code
Always run clippy to lint Rust code (cargo clippy) before completing tasks and fix any warnings or lints introduced by changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass,pymodule,pyfunction, etc.) when implementing Python functionality in Rust
Files:
crates/stdlib/src/sqlite.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Run tests under miri
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
- GitHub Check: Run snippets and cpython tests on wasm-wasi
- GitHub Check: Check the WASM package and demo
- GitHub Check: Check Rust code with clippy
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Ensure compilation on various targets
- GitHub Check: Run rust tests (macos-latest)
- GitHub Check: Run rust tests (ubuntu-latest)
- GitHub Check: Run rust tests (windows-latest)
🔇 Additional comments (1)
crates/stdlib/src/sqlite.rs (1)
1778-1799: Usingcheck_cursor_validinexecutescriptachieves the intended lock‑lifetime reductionSwitching
executescriptto callzelf.check_cursor_valid(vm)?before operating on the connection keeps the existing cursor‑state validation (closed / uninitialized) but stops holding the cursor’sinnermutex acrossdb_lock,sql_limit, and statement execution. This is a good refactor for reducing lock contention without changing observable behavior.
…dation Extract cursor validity check into a separate method that doesn't hold the lock. This is useful for executescript which only needs to verify the cursor state but doesn't need to modify CursorInner. - Add check_cursor_valid() method that checks if cursor is initialized and not closed without retaining the mutex guard - Use check_cursor_valid() in executescript instead of inner() since executescript doesn't modify CursorInner
d07bb03 to
2f6c11e
Compare
youknowone
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Extract cursor validity check into a separate method that doesn't hold the lock. This is useful for executescript which only needs to verify the cursor state but doesn't need to modify CursorInner.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.