Repository navigation
makedb: add --append to extend an existing database - #991
Merged
Merged
Conversation
The offset table (16 bytes per sequence) was collected in a std::vector and written out only at the end of the build. For NCBI nr (1.15 billion sequences) the vector reallocated at 2^30 entries and needed about 51 GB at that moment, so the build was killed by the OOM killer on a 64 GB machine. During the build the table is append-only, and it is read back exactly once, sequentially, when the trailer is written - so it does not have to be in memory. PosSpill buffers 2^20 entries and streams them to <database>.pos_tmp; copy_to() appends that file to the database and removes it, discard() removes it when the build fails. Format and order of the entries are unchanged. Verified on a 2.5 million sequence subset of nr: the resulting .dmnd is byte-identical to the one produced by the unpatched makedb. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Rebuilding a large database from scratch in order to add one day of new sequences is expensive: for NCBI nr a full makedb run takes hours, while the daily delta is a few hundred thousand sequences. --append reads the header of the existing database, truncates the file at pos_array_offset and continues writing sequences there. When the trailer is written, the old offset table is copied back first and the new entries follow; the same is done for the taxon id lists, and TaxonList::build() is called with the number of newly added sequences only. Everything from pos_array_offset to EOF is copied to <database>.append_backup before the database is truncated. If the append fails at any point, or if the backup file already exists from an earlier interrupted run, the database is restored to its previous state. The taxonomy options have to be used exactly as in the original build: --taxonmap if and only if the database contains taxon id lists, and likewise for --taxonnodes and --taxonnames. Protein databases only. Verified on a 2.5 million sequence subset of nr: building it in two steps with --append yields a .dmnd that is byte-identical to the single-step build. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Contributor
Author
|
see flowchart to better understand how it works: https://github.com/gerontec/blastDiamond/blob/main/doc/append_workflow.pdf |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Follow-up to discussion #990.
Rebuilding a large database from scratch to add one day of new sequences is expensive: for NCBI nr a full
makedbrun takes hours, while a daily delta is a few hundred thousand sequences. This PR addsmakedb --appendand one prerequisite change.Commits
1. makedb: write the sequence offset table to disk while building
The offset table (16 bytes per sequence) was collected in a
std::vectorand written only at the end of the build. For nr (1.15 billion sequences) the vector reallocated at 2^30 entries and needed about 51 GB at that moment, so the build was OOM-killed on a 64 GB machine. The table is append-only during the build and read back once, sequentially, so it is now buffered (2^20 entries) and streamed to<database>.pos_tmp, then appended to the database. File format and entry order are unchanged.2. makedb: add --append to add sequences to an existing database
--appendreads the header of the existing database, truncates the file atpos_array_offsetand continues writing sequences there. When the trailer is written, the old offset table is copied back first and the new entries follow; the same is done for the taxon id lists, andTaxonList::build()is called for the newly added sequences only.Everything from
pos_array_offsetto EOF is copied to<database>.append_backupbefore truncating. If the append fails at any point, or if a backup from an earlier interrupted run exists, the database is restored to its previous state.The taxonomy options must match the original build:
--taxonmapif and only if the database contains taxon id lists, likewise--taxonnodes/--taxonnames. Protein databases only.Verification
Rebased onto current
master(ef05efd), built with-DCMAKE_BUILD_TYPE=Release.makedbover all sequences vs.makedbover the first 2.0 M +makedb --appendwith the remaining 0.5 M → byte-identical.dmnd, including the database hash.1e0eb07f…for both)--taxonmap/--taxonnodes/--taxonnames: byte-identical (md5f66d595c…for both)--appendwithout--taxonmapon a database that has taxon lists: rejected with an error, database unchanged, no leftover files..dmndbyte-identical to the unpatchedmakedb.🤖 Generated with Claude Code