-
Notifications
You must be signed in to change notification settings - Fork 550
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
[Core] Turn on WAL mode for cluster job table #3923
Merged
Michaelvll
merged 5 commits into
skypilot-org:master
from
wizenheimer:fix/add-wal-mode-for-cluster-job
Oct 14, 2024
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5113565
fix: add retry wrapper around db operation
wizenheimer 7258eb4
fix: enable wal mode for job table
wizenheimer a48cfb9
fix: remove retries from db utils
wizenheimer c4db3d8
fix: add WAL to jobs table
wizenheimer fe4ad7c
fix: tidy up formatting
wizenheimer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
import contextlib | ||
import sqlite3 | ||
import threading | ||
import time | ||
from typing import Any, Callable, Optional | ||
|
||
|
||
|
@@ -73,6 +74,28 @@ def rename_column( | |
conn.commit() | ||
|
||
|
||
def retry_on_database_locked(func: Callable, | ||
max_retries: int = 5, | ||
retry_delay: float = 0.1): | ||
"""Retry a database operation if it fails due to database lock.""" | ||
for attempt in range(max_retries): | ||
try: | ||
return func() | ||
except sqlite3.OperationalError as e: | ||
if 'database is locked' in str(e) and attempt < max_retries - 1: | ||
time.sleep(retry_delay) | ||
else: | ||
raise | ||
raise sqlite3.OperationalError( | ||
'Database operation failed after maximum retries') | ||
|
||
|
||
def enable_wal_mode(conn: 'sqlite3.Connection'): | ||
"""Enable WAL mode for the given SQLite connection.""" | ||
conn.execute('PRAGMA journal_mode=WAL;') | ||
conn.commit() | ||
|
||
|
||
class SQLiteConn(threading.local): | ||
"""Thread-local connection to the sqlite3 database.""" | ||
|
||
|
@@ -83,4 +106,5 @@ def __init__(self, db_path: str, create_table: Callable): | |
# errors. This is a hack, but it works. | ||
self.conn = sqlite3.connect(db_path, timeout=10) | ||
self.cursor = self.conn.cursor() | ||
enable_wal_mode(self.conn) # Enable WAL mode | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of having this for all table creation, let's keep it in |
||
create_table(self.cursor, self.conn) |
Oops, something went wrong.
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.
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.
Let's leave the retry on locked out to keep this PR only about WAL.