Skip to content

[FLINK-39965][runtime] Correct schema state after DropTableEvent#4448

Open
taoran92 wants to merge 1 commit into
apache:masterfrom
taoran92:fix-drop-table-schema-state
Open

[FLINK-39965][runtime] Correct schema state after DropTableEvent#4448
taoran92 wants to merge 1 commit into
apache:masterfrom
taoran92:fix-drop-table-schema-state

Conversation

@taoran92

@taoran92 taoran92 commented Jun 22, 2026

Copy link
Copy Markdown
Member

What is the purpose of the change

Jira: FLINK-39965 This PR fixes incorrect runtime state after DropTableEvent in Flink CDC pipeline jobs.

When a source table is dropped, the downstream table may be removed while Flink CDC still keeps original/evolved schema state and table-level caches for the same TableId. If the source table is later created again with the same identifier, the following CreateTableEvent may be treated as redundant, skipped by sink initialization, or forwarded as a duplicate create event when drop.table is filtered out.

This can cause sinks such as StarRocks to fail when writing data to the recreated table because the downstream table was dropped but not initialized again.

This PR makes DropTableEvent end the table lifecycle in runtime state and clears related table-level caches so recreated tables can be initialized with their latest schema. It also covers the pre-partition hash function issue reported in FLINK-39328.

Brief change log

  • Remove original/evolved schema state from SchemaManager when applying DropTableEvent
  • Update regular schema derivation to forward DropTableEvent only when no upstream dependency remains
  • Derive schema differences instead of forwarding duplicate CreateTableEvent when drop.table is filtered out and the downstream table still exists
  • Update distributed schema coordination to remove dropped upstream schema entries and return null evolved schema views for dropped sink tables
  • Clear table-level caches in transform, pre-partition, and sink wrapper operators after DropTableEvent
  • Add unit tests for drop-and-recreate table handling in regular and distributed schema evolution
  • Add unit tests for sink wrapper, transform, partitioning, and schema manager drop-table behavior

Verifying this change

This change is verified by unit tests:

  • SchemaManagerTest#testHandlingDropTableEvent
  • org.apache.flink.cdc.runtime.operators.schema.regular.SchemaEvolveTest#testDropAndRecreateTable
  • org.apache.flink.cdc.runtime.operators.schema.regular.SchemaEvolveTest#testDropAndRecreateTableWithDropTableExcluded
  • org.apache.flink.cdc.runtime.operators.schema.regular.SchemaEvolveTest#testIgnoreDropAndRecreateTableKeepsEvolvedSchema
  • org.apache.flink.cdc.runtime.operators.schema.distributed.SchemaEvolveTest#testDropAndRecreateTable
  • org.apache.flink.cdc.runtime.operators.schema.distributed.SchemaEvolveTest#testDropTableClearsAllSourcePartitionSchemas
  • org.apache.flink.cdc.runtime.operators.schema.distributed.SchemaEvolveTest#testDropTableEventMatchesOnlyAffectedSinkTable
  • org.apache.flink.cdc.runtime.operators.schema.distributed.SchemaEvolveTest#testIgnoreDropTableRejectsLaterDataWithoutRecreate
  • DataSinkOperatorWithSchemaEvolveTest#testDataChangeEventAfterDropTable
  • PreTransformOperatorTest#testDropAndRecreateTable
  • PrePartitionOperatorTest#testBroadcastingDropTableEvent
  • PrePartitionOperatorTest#testDistributedDropTableEventDoesNotRecreateHashFunction

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): no
  • The public API, i.e. is any changed class annotated with @public(@PublicEvolving): no
  • The serializers: no
  • The runtime per-record code paths (performance sensitive): yes
  • Anything that affects deployment or recovery: yes

Documentation

  • Does this pull request introduce a new feature? no
  • If yes, how is the feature documented? not applicable

@taoran92 taoran92 force-pushed the fix-drop-table-schema-state branch from f53db1d to 96d395e Compare June 22, 2026 06:19
DropTableEvent can remove a downstream table while the runtime still keeps original/evolved schema state and table-level caches for the same table id. When the upstream table
is created again, the following CreateTableEvent may be treated as redundant, skipped by sink initialization, or forwarded as a duplicate create event if drop.table was
filtered out.

This change removes schema state for dropped tables and updates the regular schema derivation to distinguish between two cases: forward DropTableEvent only when no upstream
dependency remains, and derive schema differences when a later CreateTableEvent targets an existing downstream schema. It also clears table-level caches in transform,
pre-partition, and sink wrapper operators so recreated tables can be initialized with their new schema.

This also avoids recreating pre-partition hash functions for dropped tables, covering the DROP TABLE failure reported in FLINK-39328.
@taoran92 taoran92 force-pushed the fix-drop-table-schema-state branch from 96d395e to 69821d1 Compare June 22, 2026 07:02
@leonardBang leonardBang requested a review from yuxiqian June 25, 2026 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant