Skip to content

[flink] Stop lookup matches when dynamic partition selection is empty - #11355

Open
zhangyue19921010 wants to merge 4 commits into
apache:masterfrom
zhangyue19921010:contrib/fix-empty-dynamic-lookup-partitions
Open

zhangyue19921010 wants to merge 4 commits into
apache:masterfrom
zhangyue19921010:contrib/fix-empty-dynamic-lookup-partitions

Conversation

@zhangyue19921010

@zhangyue19921010 zhangyue19921010 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Fixes #11354.

Dynamic lookup joins can keep returning cached rows after the last selected partition is removed. Keep lookups empty until a cache built after that empty selection is installed. Tag both asynchronous cache results and failures with their refresh generation, so an obsolete rebuild cannot restore stale rows or fail a later lookup. Current-generation failures still propagate.

Tests

Real-table regressions cover full, memory and automatic caches, synchronous/asynchronous partition refresh, and recreating the same partition. Four additional async FULL/MEMORY cases cover a rebuild failing after the selection is cleared and current-generation failures. The two obsolete-failure cases fail before the follow-up fix; both propagation controls pass.

FileStoreLookupFunctionTest and PartitionRefresherTest: 26 tests passed with the normal Maven quality checks (JDK 11, Flink 1.20.1).

@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 original stale lookup reproduces in all five cases with the base lookup class. The patch passes all 25 selected Flink tests, including three SQL lookup join cases. I found a separate stale result on the empty-to-nonempty transition.

if (partitionLoader.partitions().isEmpty()) {
return Collections.emptyList();
}
List<BinaryRow> partitions =

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] Keep the pre-drop cache invalid after the selection becomes empty. I extended the existing real-table regression with a check on the first lookup after recreating pt=1. The join returned no matches after the truncate, but the first lookup after writing (1, 2, 4) then returned the deleted value 3 in both async FULL and async MEMORY modes. The partition loader becomes nonempty and schedules a rebuild, while currentPartitions() still refers to the pre-truncate cache. Preserve the empty lookup state until a cache built after that empty selection is installed. The existing test waits for 4, which misses this interval.

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.

Fixed in 4976a0d: when the selection becomes empty, the refresher now clears its current partitions and drops async refreshes started before that, so lookups stay empty until a cache built after the empty selection is installed (the test now checks the first lookup after recreating pt=1).

@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 five real-table cases for dropping and recreating the selected partition passed. I reproduced one more case with an asynchronous cache build still in flight when the partition selection became empty.

if (refreshResult == null) {
return null;
}
if (refreshResult.generation != generation) {

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] Discard failures from obsolete refresh generations

The generation check covers completed caches. Exceptions still enter the shared partitionRefreshException slot without their generation and are thrown on the next lookup. I paused an async FULL cache rebuild on a real partitioned table, truncated both partitions, and verified the join returned no matches. I then injected FileNotFoundException in the obsolete rebuild. The next lookup threw that exception even though its selection was already empty. Carry the generation on the failure path as well, so current-generation failures still propagate and superseded rebuilds cannot fail a later lookup.

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.

Fixed in 76eaeb0: obsolete refresh errors are ignored; current-generation errors still propagate.

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] Dynamic lookup returns cached rows after all selected partitions are removed

2 participants