Skip to content

[Kernel] Add specific exception subclasses for loadSnapshotAt version failures - #7055

Open
GabrielBBaldez wants to merge 3 commits into
delta-io:masterfrom
GabrielBBaldez:kernel-typed-version-load-exceptions
Open

GabrielBBaldez wants to merge 3 commits into
delta-io:masterfrom
GabrielBBaldez:kernel-typed-version-load-exceptions

Conversation

@GabrielBBaldez

Copy link
Copy Markdown
Contributor

Which Delta project/connector is this regarding?

  • Kernel

Description

When loading a snapshot at a specific version, SnapshotManager currently signals both out-of-range failures with a generic KernelException, so callers can only tell them apart by string-matching the message.

This adds two typed subclasses of KernelException and returns them from the corresponding DeltaErrors factory methods:

  • VersionToLoadAfterLatestCommitException — the requested version is higher than the latest commit (not materialized yet; typically recoverable by retrying).
  • VersionTruncatedException — the requested version is lower than the earliest available commit because the log has been truncated (unrecoverable for that version).

Both extend KernelException, mirroring how DeltaErrors#missingCheckpoint already returns an InvalidTableException. Connectors can now catch the specific type instead of parsing the message — e.g. the delta-spark V2 CDC SparkMicroBatchStream can swallow VersionToLoadAfterLatestCommitException to wait for the version to be committed.

Resolves #6745.

How was this patch tested?

Updated the existing SnapshotManagerSuite cases that exercise these two paths (getLogSegmentForVersion: versionToLoad higher than possible and ... not constructable from history) to assert the specific exception type is thrown instead of the generic RuntimeException.

Does this PR introduce any user-facing changes?

No behavioral change: both new types extend KernelException, so existing catch (KernelException ...) keeps working and the messages are unchanged. Callers simply gain the option to catch the narrower types.

seewishnew added a commit that referenced this pull request Oct 5, 2026
#### Which Delta project/connector is this regarding?

- [ ] Spark
- [ ] Standalone
- [ ] Flink
- [x] Kernel
- [ ] Other (fill in here)

## Description

`UCCatalogManagedClient` throws `IllegalArgumentException` when a
requested snapshot version or commit-range boundary exceeds UC's latest
ratified version. CDF streaming with `startingVersion=latest` requests
`latest + 1`, so consumers need to distinguish an unavailable version
from malformed arguments and other failures.

Add `VersionToLoadAfterLatestCommitException` and use it for snapshot
versions and explicit start/end versions above the catalog maximum,
preserving the diagnostic messages. Invalid argument combinations,
negative snapshot versions, and reversed ranges retain
`IllegalArgumentException`. This supplies the precise UC failure type
needed by #7754.

Tests cover both the Kernel client and Spark snapshot-manager
boundaries. This change shares the exception definition proposed in
#7055, with contributor credit preserved, but does not include or depend
on that PR's path-based or truncated-history changes. Either PR can
merge first; the other can then reuse the shared class. Related to
#6745.

## How was this patch tested?

- Regression tests cover snapshot, range-start, and range-end versions
at `latest + 1` and farther ahead, including exact exception type and
diagnostic messages in the Kernel tests. The new future-version cases
failed with the old `IllegalArgumentException` before their production
changes.
- All 52 tests passed across `UCCatalogManagedClientSuite`,
`UCCatalogManagedClientCommitRangeSuite`, and
`UcLoadSnapshotTelemetrySuite`.
- All 10 `UCManagedTableSnapshotManagerSuite` tests passed on Spark 4.0,
including propagation of the typed exception for future snapshot and
range-boundary versions.
- Earlier validation passed all 51 `SnapshotManagerSuite` tests without
the path-based changes from #7055; that code is unchanged by the
commit-range update.
- Build-enforced Java/Scala formatting and Checkstyle, plus `git diff
--check`, passed.

Commands (Java 17):

```sh
./build/sbt 'kernelUnityCatalog/testOnly io.delta.kernel.unitycatalog.UCCatalogManagedClientSuite io.delta.kernel.unitycatalog.UCCatalogManagedClientCommitRangeSuite io.delta.kernel.unitycatalog.UcLoadSnapshotTelemetrySuite'
./build/sbt 'kernelApi/testOnly io.delta.kernel.internal.SnapshotManagerSuite'
./build/sbt -DsparkVersion=4.0 'sparkV2/testOnly io.delta.spark.internal.v2.snapshot.unitycatalog.UCManagedTableSnapshotManagerSuite'
```

## Does this PR introduce _any_ user-facing changes?

Yes. A UC snapshot request or explicit commit-range start/end version
above the latest ratified version now throws
`VersionToLoadAfterLatestCommitException` (a `KernelException`) instead
of `IllegalArgumentException`. The messages are unchanged. Callers
handling this condition should catch the specific type.

---------

Signed-off-by: Vishnu Chandrashekhar <vishnu.c.9965@gmail.com>
Co-authored-by: GabrielBBaldez <130607246+GabrielBBaldez@users.noreply.github.com>
@seewishnew
seewishnew requested a review from chiinlquah October 15, 2026 23:53

This branch has not been deployed

No deployments
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.

[Kernel] Specific exception subclasses for loadSnapshotAt version failures

2 participants