Skip to content

feat(import): import the files of a table in alphabetical order - #71

Merged
mscasso-scanoss merged 2 commits into
crc64from
feat/import-alphabetical-order
Oct 27, 2026
Merged

mscasso-scanoss merged 2 commits into
crc64from
feat/import-alphabetical-order

Conversation

@scanossmining

@scanossmining scanossmining commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Why

bulk insert starts the files of a table (00.csv … ff.csv, 0000.mz … ffff.mz, *.bin) in readdir order, which on ext4 is hash order, so the shards of an import start in an effectively random order (e.g. 55 2a d4 f0 7f 10 c3 a5 …).

When an import is interrupted (here: the uat was hard-reset during the 26.10 file import), working out which shards were imported, which were half-imported and which were never started means matching the log against the files left in the folder. With the files started in order, everything below the THREADS files in progress is done and everything above them has not started.

Change

process_sectors lists the table folder with scandir(..., alphasort) instead of opendir/readdir (same DT_REG filter, entries freed). Tables still run in oss.conf order, THREADS files at a time as before.

Testing

A sample of the 26.10 monthly update (1.9 GB: 16 shards of every csv table, the first 2M records of 16 wfp .bin shards, 12–48 .mz files of sources, notices and metadata, empty semgrep csvs, version.json), imported into an empty KB with the 26.10 oss.conf and the options of ldb-import.sh (KEY_SIZE=8, THREADS=4, FILE_DEL=1, SORT=0), in a private mount namespace so /var/lib/ldb and /usr/local/etc/scanoss pointed at a test folder:

  • Identical KB: the sha256 of every file of the KB (368 files) is the same in all 6 runs (3 with crc64 as is, 3 with the change); the records imported / collate completed lines are identical too.

  • Order: the files start alphabetically, 4 at a time (e.g. wfp: 00 01 0f 10, 2a 3c 55 6e, 7f 80 99 a5, c3 d4 f0 ff).

  • Time: without the change 425, 429, 424 s; with it 464, 449, 419 s. The spread is run-to-run variation (WSL2 disk); per table the times differ by at most ~6 s, in both directions. Sorting the names costs milliseconds.

  • Test suite: ./run_test.sh passes (31 tests: 12 md5, 19 crc64), the same as on crc64. New test_17_import_files_in_alphabetical_order (test/test_kb_crc64): five csvs created in a mixed order, imported with THREADS=1, the log must show 00 0a 10 80 ff. It fails on crc64 and passes with this change.

scanossmining added 2 commits October 27, 2026 13:17
process_sectors listed the table folder with readdir, which returns the
filesystem's order (hash order on ext4), so the shards of a bulk insert
started in an effectively random order. List it with scandir + alphasort:
the files start 00, 01, ... ff (and 0000 ... ffff for mz), THREADS at a
time, so after an interrupted import everything below the files in progress
is done and everything above has not started.

The resulting KB is byte-identical: a 1.9 GB sample of a monthly update
(every table, 16 shards each; csv, wfp and mz) imported into an empty KB
gives the same sha256 for every file with and without the change, and the
import times are within run-to-run variation.
Five csvs created in a mixed order, imported with THREADS=1: the log must
show them as 00 0a 10 80 ff. Fails without the scandir change (readdir
order), passes with it.
@mscasso-scanoss
mscasso-scanoss merged commit 3168c24 into crc64 Oct 27, 2026
1 check passed
@mscasso-scanoss
mscasso-scanoss deleted the feat/import-alphabetical-order branch October 27, 2026 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants