Skip to content

[SPARK-41246][CORE] Fail fast on RDD id overflow; parse negative block ids as safety net - #57893

Open
giriprakash wants to merge 3 commits into
apache:masterfrom
giriprakash:SPARK-41246-negative-rdd-block-id
Open

[SPARK-41246][CORE] Fail fast on RDD id overflow; parse negative block ids as safety net#57893
giriprakash wants to merge 3 commits into
apache:masterfrom
giriprakash:SPARK-41246-negative-rdd-block-id

Conversation

@giriprakash

@giriprakash giriprakash commented Aug 10, 2026

Copy link
Copy Markdown

What changes were proposed in this pull request?

  1. Fail-fast (primary fix): SparkContext.newRddId throws if the 32-bit counter would wrap to a negative value after Int.MaxValue, so long-running apps no longer mint negative RDD ids that break BlockManager / other id-keyed state.
  2. Parse safety net: BlockId RDD regex accepts an optional minus (rdd_(-?[0-9]+)_...) so names like rdd_-1330910599_36 from pre-upgrade caches or tests still parse instead of throwing UnrecognizedBlockId.

Under fail-fast, newly created RDDs never get negative ids; the parser change is defense in depth.

Why are the changes needed?

After more than Int.MaxValue RDDs, AtomicInteger wraps to negatives. Cached partitions then use names such as rdd_-1330910599_36, and BlockId.apply failed with UnrecognizedBlockId (e.g. on UpdateBlockInfo). Parsing negatives alone would let the app continue with wrapped ids and cover up overflow elsewhere. Fail-fast makes overflow an explicit error; the regex remains for in-flight / old negative names.

Does this PR introduce any user-facing change?

Yes. Creating an RDD after Int.MaxValue throws a clear SparkException instead of wrapping. Restart the application to reset the counter. Positive block-id parsing is unchanged. Java int id = rdd.id() still compiles.

How was this patch tested?

  • BlockIdSuite: negative RDD block name round-trip (safety net)
  • SparkContextSuite: fail-fast when counter is at Int.MaxValue
build/sbt "core/testOnly org.apache.spark.storage.BlockIdSuite"
build/sbt "core/testOnly org.apache.spark.SparkContextSuite -- -z SPARK-41246"

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Cursor Agent

@uros-b

uros-b commented Aug 10, 2026

Copy link
Copy Markdown
Member

Thank you @giriprakash!

…gative

RDD ids are handed out by a 32-bit counter that never resets while the
application runs, so an application creating more than Int.MaxValue RDDs
wraps around to negative ids. RDDBlockId.name already renders those with a
leading minus sign, but BlockId.apply only accepted digits, so it could not
parse its own output and every path reconstructing a BlockId from its name
(such as UpdateBlockInfo.readExternal) failed with UnrecognizedBlockId until
the application was restarted.

Allow an optional minus sign on the RDD id group so the name round-trips.
The split index stays non-negative and no other block id pattern changes.
Prevent silent AtomicInteger wrap past Int.MaxValue by throwing from
newRddId before a negative id is minted. Keep BlockId's optional-minus
RDD regex as a safety net for pre-upgrade cached blocks and tests.
@giriprakash giriprakash changed the title [SPARK-41246][CORE] Parse RDD block ids whose RDD id overflowed to negative [SPARK-41246][CORE] Fail fast on RDD id overflow; parse negative block ids as safety net Aug 11, 2026

@cloud-fan cloud-fan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 blocking, 0 non-blocking, 1 nit.
The overflow and compatibility behavior is sound; only one comment typo needs cleanup.

Nits: 1 minor item (see inline comments).

Verification

Traced RDD construction through RDD.id to SparkContext.newRddId: AtomicInteger allocation remains unique through Int.MaxValue, and every negative return path throws before exposing an id. Also traced RDDBlockId.name through BlockId's signed RDD regex and Int conversion, confirming the full signed Int name representation round-trips.

Comment thread core/src/main/scala/org/apache/spark/storage/BlockId.scala Outdated
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.

3 participants