Skip to content

[core] Reject changes to partition.default-name and partition.legacy-name after data is written - #11527

Open
leo7martins wants to merge 4 commits into
apache:masterfrom
leo7martins:fix/11459-reject-partition-name-change
Open

leo7martins wants to merge 4 commits into
apache:masterfrom
leo7martins:fix/11459-reject-partition-name-change

Conversation

@leo7martins

Copy link
Copy Markdown

Purpose

Changing partition.default-name or partition.legacy-name on a table that already has data makes existing partition files unreadable. Both options are part of the physical partition directory name. ALTER TABLE SET and RESET updated the stored option and left the existing directories unchanged, so the next read looked in a different path and failed with FileNotFoundException. After files existed under both the old and new names, no single option value could read the table.

The options are now @Immutable, consistent with bucket-key and data-file.path-directory. Once the table has a snapshot, a real change or reset is rejected with Change '<key>' is not supported yet. An empty table can still set or reset them, and setting the value that is already stored remains a no-op. PyPaimon uses the same immutable set, and the option descriptions state that they cannot be changed after the table has data.

Fixes #11459

This was written with help from an AI coding assistant.

Tests

  • Before the fix, mvn -pl paimon-core -am -Pfast-build -DfailIfNoTests=false -Dtest=SchemaManagerTest#testRejectPartitionNameChangesAfterData test reproduced the bug: Tests run: 1, Failures: 1, Errors: 0. The write succeeded and the alter did not throw.
  • After the fix, the same command passed: Tests run: 1, Failures: 0, Errors: 0, Skipped: 0.
  • mvn -pl paimon-core -am -Pfast-build -DfailIfNoTests=false -Dtest=SchemaManagerTest test: Tests run: 65, Failures: 0, Errors: 0, Skipped: 0.
  • mvn -pl paimon-flink/paimon-flink-common -am -Pfast-build -DfailIfNoTests=false -Dtest=SchemaChangeITCase#testRejectPartitionNameChangesAfterData test: Tests run: 1, Failures: 0, Errors: 0, Skipped: 0. This covers the Flink SQL reproduction for a string partition and a DATE partition, including an empty table and restating the stored value.
  • Existing SchemaChangeITCase#testSetAndResetImmutableOptionsOnEmptyTables+testSetAndResetImmutableOptionsOnNonEmptyTables: Tests run: 2, Failures: 0, Errors: 0, Skipped: 0.
  • mvn -pl paimon-api,paimon-core,paimon-flink/paimon-flink-common -DskipTests checkstyle:check spotless:check: BUILD SUCCESS.
  • mvn -pl paimon-docs -am -Pfast-build -DfailIfNoTests=false -Dtest=ConfigOptionsDocsCompletenessITCase test: Tests run: 1, Failures: 0, Errors: 0, Skipped: 0.
  • PyPaimon TestAlterTableOptions and TestOptionValidation: Ran 14 tests, OK.

partition.default-name and partition.legacy-name are part of the
physical partition directory name. ALTER TABLE SET/RESET updated the
schema without renaming existing directories, so later reads looked
in the new path and failed with FileNotFoundException.

Mark both options immutable, the same way bucket-key and
data-file.path-directory already are. An empty table can still change
them. Once a snapshot exists, a real change or reset is rejected.

Fixes apache#11459
CliTableTest changed partition.default-name and partition.legacy-name
after data was written, which is now rejected. Each directory layout is
set at create time. Snapshot explain and read still use that layout, and
a catalog override still cannot retarget the written files.

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

The committed-table guard addresses #11459. I ran 65 Core tests, three Flink SQL cases, and 15 Python tests. Two upgrade and recovery cases need coverage before this becomes immutable.

+ " disabled, ordinary manifest compaction uses the legacy"
+ " full-entry merger.");

@Immutable

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.

[P1] Fence the first checkpoint or preserve partition-layout recovery

I opened a stream writer on an empty filesystem table and buffered a NULL partition. ALTER TABLE SET ('partition.default-name'='EMPTY') succeeded before its first checkpoint. The old writer then committed under __DEFAULT_PARTITION__, and a fresh reader failed looking under p=EMPTY. Master can recover the table via RESET ('partition.default-name'). On this revision the same reset is rejected after that checkpoint, leaving the committed row unreadable.

The same recovery loss affects upgrades where an older client changed either option after writing files and has yet to write into the new layout. I reproduced both keys through PyPaimon. Please reject a stale-layout commit before publication or retain a guarded recovery path for an existing affected table, and cover the first-checkpoint interleaving in the regression test.

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] Preserve reads that restate the effective partition defaults

I also verified a healthy table created without either option. On master, reading through Table.copy with partition.default-name=__DEFAULT_PARTITION__ or partition.legacy-name=true returns the committed row. Both calls now throw UnsupportedOperationException because the schema omits the option. Spark passes datasource read options into this same copy path in PaimonSparkTableBase.newScanBuilder. Please compare the effective stored value or declared default when deciding whether an override changes the layout.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in ef95d74. The commit now rejects ADD files written with a different partition.default-name or partition.legacy-name before the snapshot is published, so a writer opened before ALTER cannot commit under __DEFAULT_PARTITION__. A schema that an older client already changed can still be restored when every live file uses that layout; any other value stays rejected. Both keys are covered for the first-checkpoint case and for the upgrade case, in Java and in PyPaimon.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

On the P2 point (also in ef95d74): Table.copy and ALTER now compare these options with the stored value, or with the declared default when the schema omits the key. Restating partition.default-name=__DEFAULT_PARTITION__ or partition.legacy-name=true (including TRUE) is not a layout change. A different value still raises UnsupportedOperationException. Spark read options use this same copy path.

A writer opened before ALTER still names directories with the old
partition.default-name or partition.legacy-name. That commit is rejected
before a snapshot is published, in Java and PyPaimon.

An older client can already have stored the new schema. Changing it back is
allowed only when every live file uses the restored layout. Restating the
effective default, including Table.copy of the declared default, is not a
layout change.
The pre-commit layout check must not load schema files that are absent.
Skip an ADD entry when its schema id cannot be resolved on the branch or on
main. Branch tables may reference schema ids that main published first.

PyPaimon mirrors the same resolution and skip behaviour.
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.

[Bug] Changing partition.default-name on a non-empty table makes existing files unreadable

2 participants