Skip to content

Commit c34530e

Browse files
ilevkivskyiJukkaL
authored andcommitted
Only set journal mode in coordinator (#21217)
This should reduce test flakiness (esp. on Windows). IIUC this setting is per database, so setting it only in coordinator (main process) should be enough.
1 parent 79a3ec6 commit c34530e

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

mypy/build.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ def __init__(
874874
]
875875
)
876876

877-
self.metastore = create_metastore(options)
877+
self.metastore = create_metastore(options, parallel_worker=parallel_worker)
878878

879879
# a mapping from source files to their corresponding shadow files
880880
# for efficient lookup
@@ -1613,10 +1613,12 @@ def exclude_from_backups(target_dir: str) -> None:
16131613
pass
16141614

16151615

1616-
def create_metastore(options: Options) -> MetadataStore:
1616+
def create_metastore(options: Options, parallel_worker: bool) -> MetadataStore:
16171617
"""Create the appropriate metadata store."""
16181618
if options.sqlite_cache:
1619-
mds: MetadataStore = SqliteMetadataStore(_cache_dir_prefix(options))
1619+
mds: MetadataStore = SqliteMetadataStore(
1620+
_cache_dir_prefix(options), set_journal_mode=not parallel_worker
1621+
)
16201622
else:
16211623
mds = FilesystemMetadataStore(_cache_dir_prefix(options))
16221624
return mds

mypy/metastore.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,22 @@ def close(self) -> None:
154154
"""
155155

156156

157-
def connect_db(db_file: str) -> sqlite3.Connection:
157+
def connect_db(db_file: str, set_journal_mode: bool) -> sqlite3.Connection:
158158
import sqlite3.dbapi2
159159

160160
db = sqlite3.dbapi2.connect(db_file)
161161
# This is a bit unfortunate (as we may get corrupt cache after e.g. Ctrl + C),
162162
# but without this flag, commits are *very* slow, especially when using HDDs,
163163
# see https://www.sqlite.org/faq.html#q19 for details.
164164
db.execute("PRAGMA synchronous=OFF")
165-
db.execute("PRAGMA journal_mode=WAL")
165+
if set_journal_mode:
166+
db.execute("PRAGMA journal_mode=WAL")
166167
db.executescript(SCHEMA)
167168
return db
168169

169170

170171
class SqliteMetadataStore(MetadataStore):
171-
def __init__(self, cache_dir_prefix: str) -> None:
172+
def __init__(self, cache_dir_prefix: str, set_journal_mode: bool = False) -> None:
172173
# We check startswith instead of equality because the version
173174
# will have already been appended by the time the cache dir is
174175
# passed here.
@@ -177,7 +178,7 @@ def __init__(self, cache_dir_prefix: str) -> None:
177178
return
178179

179180
os.makedirs(cache_dir_prefix, exist_ok=True)
180-
self.db = connect_db(os_path_join(cache_dir_prefix, "cache.db"))
181+
self.db = connect_db(os_path_join(cache_dir_prefix, "cache.db"), set_journal_mode)
181182

182183
def _query(self, name: str, field: str) -> Any:
183184
# Raises FileNotFound for consistency with the file system version

mypyc/codegen/emitmodule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def __init__(
133133
self.group_map[id] = (name, modules)
134134

135135
self.compiler_options = compiler_options
136-
self.metastore = create_metastore(options)
136+
self.metastore = create_metastore(options, parallel_worker=False)
137137

138138
def report_config_data(self, ctx: ReportConfigContext) -> tuple[str | None, list[str]] | None:
139139
# The config data we report is the group map entry for the module.

0 commit comments

Comments
 (0)