Skip to content

Commit c51a81e

Browse files
authored
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 c90b301 commit c51a81e

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

mypy/build.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ def __init__(
901901
]
902902
)
903903

904-
self.metastore = create_metastore(options)
904+
self.metastore = create_metastore(options, parallel_worker=parallel_worker)
905905

906906
# a mapping from source files to their corresponding shadow files
907907
# for efficient lookup
@@ -1766,10 +1766,12 @@ def exclude_from_backups(target_dir: str) -> None:
17661766
pass
17671767

17681768

1769-
def create_metastore(options: Options) -> MetadataStore:
1769+
def create_metastore(options: Options, parallel_worker: bool) -> MetadataStore:
17701770
"""Create the appropriate metadata store."""
17711771
if options.sqlite_cache:
1772-
mds: MetadataStore = SqliteMetadataStore(_cache_dir_prefix(options))
1772+
mds: MetadataStore = SqliteMetadataStore(
1773+
_cache_dir_prefix(options), set_journal_mode=not parallel_worker
1774+
)
17731775
else:
17741776
mds = FilesystemMetadataStore(_cache_dir_prefix(options))
17751777
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, check_same_thread=False)
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)