Skip to content

[core] Skip unchanged schema commits - #11466

Open
junmuz wants to merge 5 commits into
apache:masterfrom
junmuz:fix/skip-unchanged-schema-commits
Open

junmuz wants to merge 5 commits into
apache:masterfrom
junmuz:fix/skip-unchanged-schema-commits

Conversation

@junmuz

@junmuz junmuz commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Schema alterations currently create a new schema revision even when they leave the schema unchanged, such as setting an option to its existing value or submitting an empty list of changes. This produces redundant schema files and unnecessarily advances the schema ID. Such patterns are common if you have a streaming FlinkSQL job with ALTER TABLE statements. Any crash looping jobs can cause a large number of schema version creation.

Update FileSystemSchemaManager to return the existing schema when the generated schema content, schema format version, and highest field ID are unchanged. The comparison ignores the generated revision ID and timestamp. Actual schema changes, field-ID allocation, and schema format upgrades continue to create new revisions.

Tests

Added regression coverage for unchanged and reverted alterations, tables with existing snapshots, mixed changes, type and option updates, field-ID allocation, schema format upgrades, and missing-table validation.

Validated with SchemaManagerTest: 80 tests passed, with no failures, errors, or skipped tests. Normal Maven style checks also passed.

@junmuz

junmuz commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

@JingsongLi Can I get a review on the PR? Having more schemas can slow down table operations as finding the latest schema lists the entire schema directory.

@JingsongLi JingsongLi 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.

All 80 SchemaManagerTest cases passed locally on JDK 8.

@junmuz

junmuz commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

I have identified a regression with Hive catalog as well where the assumption is that a commit operation will always result in schema change. This is fixed in ee9c6bc

@junmuz
junmuz requested a review from JingsongLi November 27, 2026 11:21
@junmuz junmuz closed this Nov 27, 2026
@junmuz junmuz reopened this Nov 27, 2026
@junmuz junmuz closed this Nov 27, 2026
@junmuz junmuz reopened this Nov 27, 2026

@JingsongLi JingsongLi 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.

All 423 focused JDK 8 tests passed. A legacy filesystem catalog fixture exposed a change in ALTER validation.

&& Objects.equals(oldTableSchema.comment(), newTableSchema.comment())) {
// Branch existence can change even when the schema is unchanged.
SchemaValidation.validateFallbackBranch(this, newTableSchema);
return oldTableSchema;

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.

[P2] Validate persisted schema history before returning on a no-op ALTER

The regular commit(newTableSchema) path validates Iceberg metadata compatibility across all historical schemas. This early return only validates the fallback branch. I opened a legacy metadata.iceberg.storage=table-location table with a VECTOR in schema 0 that had already been dropped in schema 1. Reapplying table-location is rejected by the existing validate-and-write path. The new FileSystemCatalog.alterTable path reports success using schema 1, but the first actual data commit still rejects schema 0 and publishes no snapshot. Please share the schema validation with the regular commit path before reusing the old schema. The write itself can still be skipped.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, fixed. Unchanged ALTERs now share the regular commit validation, including historical Iceberg compatibility checks, while still skipping the schema write. Added regression coverage; all 87 focused tests pass.

Report whether a schema change committed a new version and only delete that version when the Hive Metastore update fails. Cover unchanged and changed ALTER failures, plus retries after a concurrent schema commit.
Validate fallback and primary branch references before returning an unchanged schema. Cover repeated SET operations after branch deletion and preserve schema versions for valid unchanged changes.
Keep separate schema revisions for main-branch Hive ALTERs so an HMS rollback cannot undo a successful concurrent ALTER. Continue skipping unchanged commits for filesystem ALTERs and Hive branches.

Compare persisted schema fields and options directly to preserve explicitly permitted nullability changes in legacy primary-key schemas. Add regression coverage for both cases and concurrent commit retries.
Share validation between schema reuse and regular commits so unchanged ALTERs still reject incompatible historical Iceberg types. Cover changed and unchanged ALTERs against legacy schema history.
@junmuz
junmuz force-pushed the fix/skip-unchanged-schema-commits branch from ee9c6bc to fd5d0d7 Compare November 30, 2026 10:22
@junmuz

junmuz commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

The docs test failure regression is introduced in this PR.

@junmuz
junmuz requested a review from JingsongLi November 30, 2026 12:30
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.

2 participants