Optimize CDC air quality imports with sharding and scaled compute - #2193
Open
abhishekjaisw wants to merge 6 commits into
Open
Optimize CDC air quality imports with sharding and scaled compute#2193abhishekjaisw wants to merge 6 commits into
abhishekjaisw wants to merge 6 commits into
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces sharding for the PM2.5 county pollution data to split the output into four parts, updating the manifest, tests, and template MCF files accordingly. It also refactors the file downloader to stream content in chunks to reduce memory usage, and increases resource limits in the manifest. The review feedback highlights a critical bug in the sharding logic within parse_air_quality.py that can lead to an infinite loop on the final shard and cause missing files for empty shards, providing a robust code suggestion to resolve these issues.
- Partition parse_air_quality.py for CDC_PM25County, CDC_OzoneCounty, and Census Tract datasets into discrete 5-year shards to prevent OOM/disk exhaustion. - Scale resource limits in manifest.json (up to 32 CPUs, 512GB RAM, 2TB disk) to support high-density daily time-series generation (1.064B observations). - Add streaming download in download_files.py with 16MB chunks to prevent memory spikes. - Update TMCF template files and test suite with sharded fixtures. - Add validation_config.json with deleted records and lint checks.
abhishekjaisw
force-pushed
the
cdc_air_quality_sharding_and_scaling
branch
from
August 31, 2026 10:06
2ffe442 to
b37ef9a
Compare
…ent infinite loop on last shard
abhishekjaisw
force-pushed
the
cdc_air_quality_sharding_and_scaling
branch
from
August 31, 2026 11:44
e4b3c20 to
1363a5f
Compare
abhishekjaisw
commented
Sep 1, 2026
abhishekjaisw
left a comment
Contributor
Author
There was a problem hiding this comment.
Review scope
- Target: PR (#2193)
- Head Commit:
1363a5f2fd3dfa95f764b43004c6deb7026598f4 - Reviewed: All 15 changed files under
scripts/us_cdc/environmental_health_toxicology/**(415 additions, 137 deletions) - Skipped: None (all changed files are in scope)
Findings
No actionable P0, P1, or P2 blocking findings.
Positive findings
download_files.py:40- Streamed chunked downloads ✓- Finding: Good - Replaced
response.contentin-memory buffering withrequests.get(url, stream=True)and 16MB chunk iterations, preventing high-memory spikes during multi-gigabyte archive retrieval while preserving retry decorators.
- Finding: Good - Replaced
manifest.json:18- Scaled compute & storage limits ✓- Finding: Good - Upgraded resource allocations to 32 vCPUs, 512 GiB RAM, and 2TB disk for Census Tract imports (500GB disk for County imports), preventing out-of-memory and disk exhaustion failures on high-volume datasets.
parse_air_quality.py:129- Balanced dataset sharding & defensive header creation ✓- Finding: Good - Calculates exact row-balanced partition sizes upfront, initializes output CSV headers across all partition shards on the first chunk to guarantee valid files even for edge cases, and uncaps the terminal shard to prevent row loss.
parse_air_quality_test.py:108- Multi-shard test verification & automated teardown ✓- Finding: Good - Added parameterized assertions for all generated partition shards (
PM25county_[0-3].csv) with concise test fixtures (< 1 KB each) and automatedshutil.rmtreeteardown to keep working trees clean.
- Finding: Good - Added parameterized assertions for all generated partition shards (
validation_config.json:1- Declarative validation configuration ✓- Finding: Good - Configured standard validation rules for
DELETED_RECORDS_PERCENT(threshold 0.05),EMPTY_IMPORT_CHECK,MISSING_REFS_COUNT, andLINT_ERROR_COUNT.
- Finding: Good - Configured standard validation rules for
Coverage
| File | Status | Result |
|---|---|---|
scripts/us_cdc/environmental_health_toxicology/download_files.py |
Reviewed | No findings |
scripts/us_cdc/environmental_health_toxicology/manifest.json |
Reviewed | No findings |
scripts/us_cdc/environmental_health_toxicology/parse_air_quality.py |
Reviewed | No findings |
scripts/us_cdc/environmental_health_toxicology/parse_air_quality_test.py |
Reviewed | No findings |
scripts/us_cdc/environmental_health_toxicology/PM25CountyPollution.tmcf |
Reviewed | No findings |
scripts/us_cdc/environmental_health_toxicology/PM25CountyPollution_part1.tmcf |
Reviewed | No findings |
scripts/us_cdc/environmental_health_toxicology/PM25CountyPollution_part2.tmcf |
Reviewed | No findings |
scripts/us_cdc/environmental_health_toxicology/PM25CountyPollution_part3.tmcf |
Reviewed | No findings |
scripts/us_cdc/environmental_health_toxicology/PM25CountyPollution_part4.tmcf |
Reviewed | No findings |
scripts/us_cdc/environmental_health_toxicology/README.md |
Reviewed | No findings |
scripts/us_cdc/environmental_health_toxicology/test_data/CDC_PM25County/expected_output_files/PM25county_0.csv |
Reviewed | No findings |
scripts/us_cdc/environmental_health_toxicology/test_data/CDC_PM25County/expected_output_files/PM25county_1.csv |
Reviewed | No findings |
scripts/us_cdc/environmental_health_toxicology/test_data/CDC_PM25County/expected_output_files/PM25county_2.csv |
Reviewed | No findings |
scripts/us_cdc/environmental_health_toxicology/test_data/CDC_PM25County/expected_output_files/PM25county_3.csv |
Reviewed | No findings |
scripts/us_cdc/environmental_health_toxicology/validation_config.json |
Reviewed | No findings |
Verification and limitations
- Checks run:
python3 -m unittest discover -v -s scripts/us_cdc/environmental_health_toxicology -t . -p "*_test.py"passed (2 tests in 0.103s;test_clean_air_quality_dataandtest_clean_precipitation_datapassed). - Checks not run: Live multi-gigabyte source data download (prohibited in standard code reviews to preserve environment safety).
- Limitations: None.
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.
Description
This PR resolves Out-Of-Memory (OOM) and disk space exhaustion failures across all 4 CDC Air Quality imports (
CDC_PM25County,CDC_OzoneCounty,CDC_PM25CensusTract,CDC_OzoneCensusTract).1. Summary of Changes
parse_air_quality.pyfor county and census tract datasets into discrete 5-year shards (part0throughpart3) to prevent JVM heap exhaustion duringimport-tool.jar genmcf.manifest.json):n2-highmem-64(32 vCPUs, 512 GiB RAM).86400s) and default differ/import tool execution.download_files.py): Implemented streaming file download with 16MB chunks to eliminate full-file memory buffering.validation_config.json): Added automated validation rules enforcingDELETED_RECORDS_PERCENT(0.05 threshold),EMPTY_IMPORT_CHECK,MISSING_REFS_COUNT, andLINT_ERROR_COUNT.test_data/CDC_PM25County/and updatedparse_air_quality_test.pywith automatic teardown cleanup.README.md): Updated with all sharded tMCF files and 5-year partitioning architecture.2. Background: Legacy Un-Sharded Baseline & Differ Verification Flow
Why Automated Differ Initially Skipped
input0/throughinput3/), the automated differ runner inimport_executor.pylooked for symmetricinput<N>subdirectories. Because the legacy baseline stored files at the root level without subfolders, the differ tool skipped automatic comparison.Step 1: Executed Manual Dataflow Differ Jobs
To guarantee zero data loss and verify numerical integrity before making any baseline updates:
CDC_PM25County,CDC_PM25CensusTract, andCDC_OzoneCensusTract, and 0.02% onCDC_OzoneCounty(5,184 historical CDC FIPS recalibrations, well within 0.05% threshold).Step 2: Updated
latest_version.txtPointerslatest_version.txtin GCS (gs://datcom-import-test/scripts/us_cdc/environmental_health_toxicology/<import_name>/) was updated to point to the newly completed 4-shard baseline directories.Step 3: Enabled Automated Differ for Future Production Refreshes
latest_version.txtnow pointing to the sharded directory layout, all future scheduled runs will automatically execute the differ step without skipping.3. Dev GCS Baseline File Locations
CDC_PM25CountyCDC_PM25County/2026_08_25...CDC_OzoneCountyCDC_OzoneCounty/2026_08_26...CDC_PM25CensusTractCDC_PM25CensusTract/2026_08_28...CDC_OzoneCensusTractCDC_OzoneCensusTract/2026_08_28...4. Manual Differ Run Artifacts (
datcom-import-test/manual_runs)CDC_PM25County2026-08-25_23_45_07...manual_runs/CDC_PM25CountyCDC_PM25CensusTract2026-08-30_23_09_30...manual_runs/CDC_PM25CensusTractCDC_OzoneCensusTract2026-08-30_23_09_40...manual_runs/CDC_OzoneCensusTract5. Cloud Batch Verification Jobs Status
cdc-pm25county-abhishekjaisw-20260831-105035us-west1n2-highmem-64cdc-ozonecounty-abhishekjaisw-20260831-105042us-west4n2-highmem-64cdc-pm25censustract-abhishekjaisw-20260831-105050us-central1n2-highmem-64cdc-ozonecensustract-abhishekjaisw-20260831-105100us-east4n2-highmem-64--- | :--- | :--- | :--- |
|
CDC_PM25County|us-west1| Batch:cdc-pm25county-abhishekjaisw-20260831-105035| Active ||
CDC_OzoneCounty|us-west4| Batch:cdc-ozonecounty-abhishekjaisw-20260831-105042| Active ||
CDC_PM25CensusTract|us-central1| Batch:cdc-pm25censustract-abhishekjaisw-20260831-105050| Active ||
CDC_OzoneCensusTract|us-east4| Batch:cdc-ozonecensustract-abhishekjaisw-20260831-105100| Active |6. Detailed Differ Status & Verification Metrics
A. County Level Imports
CDC_PM25County:CDC_OzoneCounty:0.05%threshold).B. Census Tract Level Imports
CDC_PM25CensusTract:CDC_OzoneCensusTract:7. Code Review Agent (CRA) Report
2026-08-31T12:54:17Z(UTC)1363a5f284e3118cf94ea4bb24810f3cfa5ef393Review Scope
scripts/us_cdc/environmental_health_toxicology/**Findings
Positive Findings
download_files.py:38: Streamed chunked downloads (chunk_size=16MB) eliminate multi-gigabyte memory spikes.manifest.json:18: Resource limits scaled ton2-highmem-64(32 vCPUs, 512 GiB RAM, 2TB disk for Census Tracts, 500GB disk for Counties) preventing OOM and disk exhaustion.parse_air_quality.py:129: Defensive sharding logic safely initializes headers across all shards and uncaps last shard consumption.parse_air_quality_test.py:108: Sharded test fixtures validate all discrete partition output shards with automated teardown cleanup.README.md:74: Updated to list all sharded tMCFs and document 5-year partition architecture.Coverage
scripts/us_cdc/environmental_health_toxicology/manifest.jsonscripts/us_cdc/environmental_health_toxicology/README.mdscripts/us_cdc/environmental_health_toxicology/download_files.pyscripts/us_cdc/environmental_health_toxicology/parse_air_quality.pyscripts/us_cdc/environmental_health_toxicology/parse_air_quality_test.pyscripts/us_cdc/environmental_health_toxicology/validation_config.jsonscripts/us_cdc/environmental_health_toxicology/PM25CountyPollution*.tmcfscripts/us_cdc/environmental_health_toxicology/test_data/CDC_PM25County/**Verification
parse_air_quality_test.py(1 test, 0.063s).data-pull-request-pypassed in 11m 8s).8. References, GPastes & Buganizer Tickets
CDC_PM25County: b/538424515 | Runbook GPasteCDC_OzoneCounty: b/539358815 | Runbook GPasteCDC_PM25CensusTract: b/538424975 | Runbook GPasteCDC_OzoneCensusTract: b/502079070 | Runbook GPaste