Skip to content

[KYUUBI #7244] Ignore null-valued session and batch configurations - #7882

Open
pan3793 wants to merge 2 commits into
apache:masterfrom
pan3793:kyuubi-7244-null-batch-conf
Open

pan3793 wants to merge 2 commits into
apache:masterfrom
pan3793:kyuubi-7244-null-batch-conf

Conversation

@pan3793

@pan3793 pan3793 commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Why are the changes needed?

Closes #7244.

When a batch request contains a null-valued configuration entry (e.g. "sfPassword": null), Kyuubi can fail during REST handling (for special keys such as proxy user, batch id, or priority), persist the null value into the metadata store under Batch API v2, and later throw IllegalArgumentException: value cannot be null for key: ... from KyuubiConf.set during V2 submission, SparkBatchProcessBuilder command building, or batch recovery on KyuubiRestFrontendService startup. Interactive sessions with null-valued configs hit the same KyuubiConf.set failure, as well as NPEs during REST proxy-user resolution and AbstractSession.isForAliveProbe initialization.

This patch filters out null-valued configuration entries across the lifecycle:

  1. SessionManager.validateKey and SessionManager.validateBatchKey: drop entries with null values (logging a warning) so normalizedConf and optimizedConf never carry null values into KyuubiSessionImpl, KyuubiBatchSession, or SparkBatchProcessBuilder.
  2. BatchesResource.openBatchSessionInternal: strip null-valued entries from request.getConf at the REST entry point (keeping a mutable map for extra-resource uploads) before proxy-user lookup, batch-id validation, and V1/V2 metadata persistence.
  3. SessionsResource.openSession: strip null-valued entries from request.getConfigs at the REST entry point before proxy-user lookup and session creation.
  4. JDBCMetadataStore.string2Map: filter null-valued entries (and handle JSON null) when deserializing request_conf so legacy rows already persisted in the metadata store recover and serve cleanly.

Affects 1.8.0+ (Batch API v2, introduced in #4790) and master (batch recovery exists since 1.6.0-incubating, #2373).

How was this patch tested?

Added regression tests in:

  1. SessionManagerValidationSuite: null-valued keys dropped in validateAndNormalizeConf and validateBatchConf.
  2. JDBCMetadataStoreSuite: legacy JSON request_conf with null values and 'null' literal filtered on read.
  3. BatchesResourceSuite (BatchesV1ResourceSuite and BatchesV2ResourceSuite): V1/V2 REST batch creation with null-valued configs, multipart upload with extra resources and null-valued configs, and startup/reassignment recovery with null-valued request_conf.
  4. SessionsResourceSuite: REST session creation with null-valued sfPassword, PROXY_USER, HS2_PROXY_USER, and KYUUBI_SESSION_ALIVE_PROBE.

Verified locally (79 tests passed across 7 suites, plus formatting, style, and RAT checks):

build/mvn --batch-mode --no-transfer-progress test scalastyle:check spotless:check apache-rat:check \
  -pl kyuubi-common,kyuubi-server -am -Pspark-provided,flink-provided,hive-provided \
  -Dtest=none \
  -DwildcardSuites=org.apache.kyuubi.session.SessionManagerValidationSuite,org.apache.kyuubi.server.metadata.jdbc.JDBCMetadataStoreSuite,org.apache.kyuubi.server.metadata.MetadataManagerSuite,org.apache.kyuubi.server.api.v1.BatchesV1ResourceSuite,org.apache.kyuubi.server.api.v1.BatchesV2ResourceSuite,org.apache.kyuubi.server.rest.client.BatchRestApiSuite,org.apache.kyuubi.server.api.v1.SessionsResourceSuite

Was this patch assisted by generative AI tooling?

Assisted-by: Gemini 4 Neon

@pan3793

pan3793 commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

@hutiefang76 hutiefang76 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

At 188dc95f, I checked that REST null filtering runs before proxy-user and batch-id handling, the replacement map remains mutable for uploads, and legacy metadata is filtered before recovery.

I re-ran the six suites listed in this PR on JDK 17/macOS ARM64 with Spark 3.5.9 (verified official PyPI runtime and the tag’s SparkPi example rebuilt locally): all 66 tests pass, with no skips. Scalastyle, Spotless and RAT checks also pass. No blocking finding for the null-valued-entry scope.

Assisted-by: DeepSeek V4 Pro

@moelhoussein

Copy link
Copy Markdown
Contributor

@pan3793 Since this PR covers both session and batch configs, should SessionsResource.openSession also filter null-valued entries at the REST entry point, matching BatchesResource.openBatchSessionInternal?

Right now null-valued entries in request.getConfigs still trigger NPEs in two paths unaffected by SessionManager.validateKey:

  1. {"configs": {"kyuubi.session.proxy.user": null}} (or hive.server2.proxy.user): runs before validateKey in KyuubiRestFrontendService.getProxyUser, where getOrElse returns null, !proxyUser.equals(realUser) throws NPE, and getSessionUser turns it into HTTP 403.
  2. {"configs": {"kyuubi.session.alive.probe": null}}: AbstractSession.isForAliveProbe reads raw conf instead of normalizedConf, so conf.get(...).exists(_.equalsIgnoreCase("true")) throws NPE on Some(null) during AbstractSession initialization.

Filtering request.getConfigs in SessionsResource.openSession (with a case in SessionsResourceSuite) would keep REST session creation consistent with batches.

@pan3793

pan3793 commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

Thanks @moelhoussein, good catch. Filtered null-valued entries in SessionsResource.openSession and added coverage for PROXY_USER, HS2_PROXY_USER, and KYUUBI_SESSION_ALIVE_PROBE in SessionsResourceSuite in e2f9015.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Maintainer agreement is needed on dropping rather than rejecting null configurations, since this changes public REST session/batch semantics, affects proxy-user fallback, and touches high-sensitivity SessionManager validation.

No open issues 🎉

What changed in this PR

This PR addresses #7244 by ignoring null-valued session and batch configurations, preventing request failures and startup crashes caused by legacy batch metadata.

Changes:

  • Filter null values at REST entry points and during session and batch validation.
  • Sanitize legacy JDBC metadata, including JSON null, when reading configurations.
  • Add regression coverage for validation, REST creation, multipart uploads, and recovery.
File Description
kyuubi-server/​src/​test/​scala/​org/​apache/​kyuubi/​server/​metadata/​jdbc/​JDBCMetadataStoreSuite.scala Tests legacy null-valued metadata decoding.
kyuubi-server/​src/​test/​scala/​org/​apache/​kyuubi/​server/​api/​v1/​SessionsResourceSuite.scala Tests session creation with null configurations.
kyuubi-server/​src/​test/​scala/​org/​apache/​kyuubi/​server/​api/​v1/​BatchesResourceSuite.scala Tests batch creation, uploads, and recovery with null configurations.
kyuubi-server/​src/​main/​scala/​org/​apache/​kyuubi/​server/​metadata/​jdbc/​JDBCMetadataStore.scala Removes null values from decoded metadata configurations.
kyuubi-server/​src/​main/​scala/​org/​apache/​kyuubi/​server/​api/​v1/​SessionsResource.scala Filters null configurations before session identity resolution and creation.
kyuubi-server/​src/​main/​scala/​org/​apache/​kyuubi/​server/​api/​v1/​BatchesResource.scala Filters null configurations while preserving mutable upload handling.
kyuubi-common/​src/​test/​scala/​org/​apache/​kyuubi/​session/​SessionManagerValidationSuite.scala Tests null filtering in session and batch validation.
kyuubi-common/​src/​main/​scala/​org/​apache/​kyuubi/​session/​SessionManager.scala Ignores null-valued configuration entries during validation.

Review effort: Max

@aajisaka aajisaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @pan3793

Added a minor comment for test coverage

Comment on lines +283 to +284
val metadata = sessionManager.getBatchMetadata(batch.getId)
assert(metadata.isDefined)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since BatchesResourceSuiteBase runs for both BatchesV1ResourceSuite and BatchesV2ResourceSuite (kyuubi.batch.impl.version=2), in V2 initializeBatchState inserts the initial metadata row during POST /api/v1/batches. As a result, getBatchMetadata is already defined in INITIALIZED state before KyuubiBatchService picks the batch up and runs KyuubiBatchSession.open(), so the test finishes and afterEach() cancels/cleans up the batch before KyuubiBatchSession is created (or can race with KyuubiBatchService calling updateMetadata).

Can we also wait for getBatchSession and clusterManager to be defined (here and in the upload test below) so both V1 and V2 verify the metadata after KyuubiBatchSession.open() completes?

Suggested change
val metadata = sessionManager.getBatchMetadata(batch.getId)
assert(metadata.isDefined)
assert(sessionManager.getBatchSession(SessionHandle.fromUUID(batch.getId)).isDefined)
val metadata = sessionManager.getBatchMetadata(batch.getId)
assert(metadata.isDefined)
assert(metadata.get.clusterManager.isDefined)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] batch recovery crashes startup on null request_conf (KyuubiConf.set)

5 participants