Repository navigation
[core] Reject changes to partition.default-name and partition.legacy-name after data is written - #11527
[core] Reject changes to partition.default-name and partition.legacy-name after data is written#11527leo7martins wants to merge 4 commits into
Conversation
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
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
[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.
There was a problem hiding this comment.
[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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Purpose
Changing
partition.default-nameorpartition.legacy-nameon a table that already has data makes existing partition files unreadable. Both options are part of the physical partition directory name.ALTER TABLE SETandRESETupdated the stored option and left the existing directories unchanged, so the next read looked in a different path and failed withFileNotFoundException. After files existed under both the old and new names, no single option value could read the table.The options are now
@Immutable, consistent withbucket-keyanddata-file.path-directory. Once the table has a snapshot, a real change or reset is rejected withChange '<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
mvn -pl paimon-core -am -Pfast-build -DfailIfNoTests=false -Dtest=SchemaManagerTest#testRejectPartitionNameChangesAfterData testreproduced the bug: Tests run: 1, Failures: 1, Errors: 0. The write succeeded and the alter did not throw.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.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.TestAlterTableOptionsandTestOptionValidation: Ran 14 tests, OK.