Skip to content

Commit 57dc495

Browse files
committed
[performance] Reduce number of files in TAR to verify
1 parent b733978 commit 57dc495

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

core/ratarmountcore/SQLiteIndex.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ class SQLiteIndex:
147147
__version__ = '0.7.0'
148148

149149
MAGIC_BYTES = b'SQLite format 3\x00' # If it is encrypted, the first 16 B are the (random) salt.
150-
NUMBER_OF_METADATA_TO_VERIFY = 1000 # shouldn't take more than 1 second according to benchmarks
150+
# 1000 rows to verify shouldn't take more than 1 second on HDDs according to benchmarks.
151+
# For remote/network/global filesystems and/or large block sizes, it can snowball, therefore it was reduced
152+
# by more than one magnitude to 100.
153+
NUMBER_OF_METADATA_TO_VERIFY = 100
151154

152155
# The maximum blob size configured by SQLite is exactly 1 GB, see https://www.sqlite.org/limits.html
153156
# Therefore, this should be smaller. Another argument for making it smaller is that this blob size

core/ratarmountcore/mountsource/formats/tar.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,13 +1336,14 @@ def _check_metadata2(self, metadata: dict[str, Any]) -> None:
13361336
def _check_index_validity(self) -> bool:
13371337
# Check some of the first and last files in the archive and some random selection in between.
13381338
selectFiles = "SELECT * " + SQLiteIndex.FROM_REGULAR_FILES
1339+
limit = int(max(1, SQLiteIndex.NUMBER_OF_METADATA_TO_VERIFY // 3))
13391340
result = self.index.get_connection().execute(
13401341
f"""
1341-
SELECT * FROM ( {selectFiles} ORDER BY offset ASC LIMIT 100 )
1342+
SELECT * FROM ( {selectFiles} ORDER BY offset ASC LIMIT {limit} )
13421343
UNION
1343-
SELECT * FROM ( {selectFiles} ORDER BY RANDOM() LIMIT {SQLiteIndex.NUMBER_OF_METADATA_TO_VERIFY} )
1344+
SELECT * FROM ( {selectFiles} ORDER BY RANDOM() LIMIT {limit} )
13441345
UNION
1345-
SELECT * FROM ( {selectFiles} ORDER BY offset DESC LIMIT 100 )
1346+
SELECT * FROM ( {selectFiles} ORDER BY offset DESC LIMIT {limit} )
13461347
ORDER BY offset
13471348
"""
13481349
)

0 commit comments

Comments
 (0)