Repository navigation
Run a study import's Java steps in one JVM - #203
Conversation
|
@jamesqo The Problem section should say why one JVM is required. Each file is its own Java process, and each process loads samples, patients, profiles, and clinical data into static maps with SELECT *. Lookups read those maps. On ClickHouse Cloud that read can hit a replica that does not yet have the rows the previous file wrote, so a later file skips data that is missing from its cache and the import can still exit successfully. Keeping the maps in one JVM is what prevents that. The sentence later in the description, that reloading the caches would "read from whichever replica answers," is this problem and belongs at the top. The startup time and the study_es_0 timing are a benefit of the same change. UPDATE: This is done. The Problem section now leads with the reason one JVM is required: a later file can miss rows the previous file wrote, and the import can still succeed. Keeping that state in one JVM is the fix, and the startup time is a secondary benefit. |
|
@jamesqo Since the race can silently drop rows on a ClickHouse Cloud replica lag, and that can happen within a single study's import once it has more than one data file, this pull request should only have the single-JVM directory import. The multi-JVM directory import should not stay in this branch, even behind CBIOPORTAL_IMPORTER_SINGLE_JVM and even temporarily. That path is already on main. One-step commands can keep calling run_java once. UPDATE: This is done. The multi-JVM directory-import path and CBIOPORTAL_IMPORTER_SINGLE_JVM are both removed (16f6949). Directory imports always run in one JVM now. Single-file subcommands still use run_java once, through run_single_step. |
mandawilson
left a comment
There was a problem hiding this comment.
Requesting changes because a single-JVM import still resets sequence counters and reloads DAO caches from the database between steps, so a later step can reuse an id or miss rows this same run just wrote.
|
Some reads can still see a stale replica during the single-JVM import, and each of these can drop or mis-attach data while the import exits 0. 1. IDs from
A second file of the same type can read an old max and reuse the first file's IDs. These tables have no unique key, so the duplicates are kept. The sequences are already registered in ClickHouseAutoIncrement.java#L86-L92. Please call 2. Generic-assay entities are reread right after they are inserted. ImportProfileData.java#L113 inserts the missing 3. Full reload of genetic profiles. GeneticProfileReader.java#L171-L176 calls 4. A deleted |
|
@mandawilson Addressed all four points from your later review comment in 72eb631.
Validation: 132 unit tests and 16 targeted local ClickHouse integration tests passed. Added stale-read regression coverage for sequence retention across files, entity-map reuse, missing-source handling, and existing case lists. The integration checks cover all four ID importers, both generic assay paths, and genetic-profile loading. These were local ClickHouse tests; this revision has not been validated against ClickHouse Cloud. |
|
This is the beginning of a readthrough of this PR. My first comment is about the PR description:
This seems to combine multiple problems ... so perhaps this PR could be split into smaller pieces. One piece could be to focus on the asynchronous nature of the import process --- the "a replica may not yet contain rows written by the preceding step" issue. Trying to fix that problem at the same time that we try to maintain state and speed up the running of the JVM probably blends together two different efforts. (I have not yet seen the changes yet though) The validation reports probably don't belong in the PR description. These results are regenerated on every revision of the PR and can be seen in the validation reports under the "Checks" tab. So I would drop all that as noise. But maybe one good thing about this noise is this: "Local ClickHouse 24.3: all six integration tests passed. Covers full study import, reimport in the same JVM, stopping/recovering after a failed step, sample and patient removal followed by another step, and rejection of an invalid manifest. Cache assertions run without a test-only reload." Why are we running tests under Clickhouse 24.3 ? The standard Clickhouse version we released under was 24.10 --- so I'm confused why we would downgrade Clickhouse in order to run tests. Please comment on this. |
sheridancbio
left a comment
There was a problem hiding this comment.
I've got the gist of this PR now, but not the details yet. Here are some shallow issues I saw which we can discuss. Deeper review needed.
cbioportalImporter.py starts a JVM for every file it imports. With CBIOPORTAL_IMPORTER_SINGLE_JVM=1, a study or data directory import instead writes the same steps, in the same order, to a JSON manifest and runs them with ImportStepRunner in one JVM. The version check becomes the first step. Python keeps the ordering logic; without the variable nothing changes. ImportStepRunner runs each ConsoleRunnable in-process and stops at the first failed step with that step's exit status, writing the failed step's index to a result file so Python can report it as before. Between steps it resets what a fresh JVM would start without: pending bulk loads and deletes, the bulk load and relaxed mode flags, sequence counters (persisted first, as the shutdown hook would) and ProgressMonitor, and it reloads the study caches. The gene cache is kept. Importing study_es_0 with cbioportalImporter.py took about 28 s with a JVM per step and about 5.5 s in one JVM, with identical contents in all 60 tables. Also import JavaRunException in cbioportalImporter and give it the java_process_status attribute its error handlers already read.
The DAOs keep the study, patient, sample, profile and clinical attribute caches current as they insert rows, so reloading every cache from the database before each step only repeated work and read from whichever replica answered. Reload them only after RemoveSamples or RemovePatients, which clear the sample and patient caches without reloading them.
The per-step path reloads the study, patient and sample caches in every step's JVM. On ClickHouse Cloud that reload can miss rows the previous step wrote, and several importers then skip the missing sample or patient with only a warning. Make the single JVM the default; CBIOPORTAL_IMPORTER_SINGLE_JVM=0 (or false/no) keeps one JVM per step as a temporary opt-out until the per-step path is removed. The existing per-step tests now set the opt-out explicitly, and new tests cover the default and the opt-out values.
Study and data directory imports now always run their steps in one JVM, and CBIOPORTAL_IMPORTER_SINGLE_JVM is gone. Single-file subcommands still run their one step in its own JVM. Drop the process_case_lists, import_incremental_data and update_case_lists_from_folder wrappers, which nothing calls any more. The directory import tests now read the step manifest instead of separate java calls, and the single-JVM tests move into system_tests_import_data.py.
AddCaseList now refuses to keep an existing case list, so the tests that run it after RemoveSamples or RemovePatients delete study_es_0_all first and check that it is rebuilt from the remaining cached samples.
350d951 to
051f0b3
Compare
sheridancbio
left a comment
There was a problem hiding this comment.
Java main code review (not including test code).
Overall, looks very good.
|
In response to Rob’s feedback: The single JVM is how this change retains the state written by earlier files, so the correctness fix and the process change are coupled |
|
In response to Rob’s feedback: Thanks. I have separated the specific changes and open questions below so each can be reviewed on its own. |
sheridancbio
left a comment
There was a problem hiding this comment.
I've quickly read over the generated tests, and tests seem to be testing reasonable conditions. The only think that jumped out for me is the license reference header containing references to Affero, but we switched to Apache for the cbioportal codebase (which this is really a part of)
sheridancbio
left a comment
There was a problem hiding this comment.
This requested change is in the base branch for the work in this PR. See comment (which is placed in a class which references the altered class just to have a placeholder)
|
The Clickhouse version for running integration tests has been updated now to 24.10, which matches our currently recommended default deployment of cBioPortal. ✅ |
sheridancbio
left a comment
There was a problem hiding this comment.
all of my requested changes have been made, so I am approving this PR which will be system/regression tested before merge
Depends on #168. This PR is based on its branch and retains DAO-assigned IDs across import steps; the four importer ID-allocation changes are supplied by #168.
Problem
Running each file of a study import in a separate JVM reloads the study, patient, sample, profile and clinical caches from the database between files. On ClickHouse Cloud, a replica may not yet contain rows written by the preceding step. Some importers skip a missing sample with only a warning, so an import can finish successfully with data missing.
Study and incremental directory imports now run their ordered Java steps in one JVM and retain the state written by earlier steps. Reduced JVM startup time is a secondary benefit.
Changes
Limitations
This revision has not been tested against ClickHouse Cloud. Initial cache loading and concurrent independent importers remain outside the consistency guarantee provided by retaining state within one process.