Fix OverflowError in DatasetCoder.estimate_size for datasets > 2 GB#197
Open
chase-dwelle wants to merge 1 commit into
Open
Fix OverflowError in DatasetCoder.estimate_size for datasets > 2 GB#197chase-dwelle wants to merge 1 commit into
OverflowError in DatasetCoder.estimate_size for datasets > 2 GB#197chase-dwelle wants to merge 1 commit into
Conversation
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.
Fixes #196
DatasetCoder.estimate_sizereturnsvalue.nbytesdirectly. For datasets larger than ~2 GB, this overflows a Cintin Apache Beam's Cython internals, crashing the pipeline with:Root cause
The overflow occurs in
CoderImpl._get_nested_size, declared in Beam's Cython layer (coder_impl.pxd) as:Both the parameter and return type are
int, which Cython compiles to a C 32-bit signed integer. The maximum value is2^31 - 1(2,147,483,647 bytes, ~2 GB). Anyestimate_sizeresult at or above2^31overflows this conversion.I first noticed this when loading GRIBs from ECMWF open data, which can create large arrays (51 ensemble members, 13 pressure levels, 721x1440 grid).
Downstream impact of capping the estimate
estimate_sizefeeds into Beam's monitoring and optimization heuristics:MeanByteCountdistribution counters per transform (used in Beam UI/logs)max(1MB, 1000 * sqrt(total_size))GroupIntoBatches.WithShardedKeydistribution decisionsCapping at
2^31 - 1means metrics will underreport and parallelism heuristics may be slightly suboptimal for very large datasets. I prefer this to the alternative of anOverflowErrorthat kills the pipeline.Upstream
The real fix would be for Beam to change
_get_nested_sizeto useint64_tinstead ofint. I'm introducing the workaround here since geospatial workflows offer uniquely large data.