You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fluss.apache.org by ja...@apache.org on 2026/04/09 07:59:57 UTC
(fluss) branch main updated: [server] Fix TableChangeWatcher missing CreateTableEvent due to CuratorCache async getData race (#2710)
This is an automated email from the ASF dual-hosted git repository.
jark pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fluss.git
The following commit(s) were added to refs/heads/main by this push:
new ab618ea6d [server] Fix TableChangeWatcher missing CreateTableEvent due to CuratorCache async getData race (#2710)
ab618ea6d is described below
commit ab618ea6d1e9287c518efa1fe1798854f166f375
Author: yunhong <33...@qq.com>
AuthorDate: Thu Apr 9 15:59:52 2026 +0800
[server] Fix TableChangeWatcher missing CreateTableEvent due to CuratorCache async getData race (#2710)
---
.../event/watcher/TableChangeWatcher.java | 18 ++++++
.../event/watcher/TableChangeWatcherTest.java | 67 ++++++++++++++++++++++
2 files changed, 85 insertions(+)
diff --git a/fluss-server/src/main/java/org/apache/fluss/server/coordinator/event/watcher/TableChangeWatcher.java b/fluss-server/src/main/java/org/apache/fluss/server/coordinator/event/watcher/TableChangeWatcher.java
index 51e934c2a..862092dfd 100644
--- a/fluss-server/src/main/java/org/apache/fluss/server/coordinator/event/watcher/TableChangeWatcher.java
+++ b/fluss-server/src/main/java/org/apache/fluss/server/coordinator/event/watcher/TableChangeWatcher.java
@@ -114,6 +114,24 @@ public class TableChangeWatcher {
if (tablePathIntegerTuple2 != null) {
processSchemaChange(
tablePathIntegerTuple2.f0, tablePathIntegerTuple2.f1);
+ break;
+ }
+
+ // Handle the case where CuratorCache fires NODE_CREATED with
+ // full table data. This happens in two scenarios:
+ // 1. CuratorCache async getData race: the table node is created
+ // empty (via creatingParentsIfNeeded) and setData follows
+ // immediately. CuratorCache's async getData() may read the
+ // post-setData state, causing NODE_CREATED to carry full data
+ // while NODE_CHANGED is suppressed.
+ // 2. CuratorCache initial sync: when the watcher starts, existing
+ // table nodes are reported as NODE_CREATED with full data.
+ // See CuratorCacheRaceConditionTest for details on the race.
+ TablePath tablePath = TableZNode.parsePath(newData.getPath());
+ if (tablePath != null
+ && newData.getData() != null
+ && newData.getData().length > 0) {
+ processCreateTable(tablePath, newData);
}
}
break;
diff --git a/fluss-server/src/test/java/org/apache/fluss/server/coordinator/event/watcher/TableChangeWatcherTest.java b/fluss-server/src/test/java/org/apache/fluss/server/coordinator/event/watcher/TableChangeWatcherTest.java
index bb0cb8a7b..72697b7a9 100644
--- a/fluss-server/src/test/java/org/apache/fluss/server/coordinator/event/watcher/TableChangeWatcherTest.java
+++ b/fluss-server/src/test/java/org/apache/fluss/server/coordinator/event/watcher/TableChangeWatcherTest.java
@@ -397,4 +397,71 @@ class TableChangeWatcherTest {
assertThat(eventManager.getEvents())
.containsExactlyInAnyOrderElementsOf(expectedEvents));
}
+
+ /**
+ * Tests that table creation is correctly detected via NODE_CREATED events with full data. This
+ * exercises the fix for the CuratorCache async getData race condition.
+ *
+ * <p>When CuratorCache starts (or during the race), it fires NODE_CREATED for table nodes that
+ * already contain full data. Without the fix, only NODE_CHANGED triggers {@code
+ * processCreateTable}, so these events would be missed. The fix adds table path handling in the
+ * NODE_CREATED branch to cover this case.
+ */
+ @Test
+ void testTableCreationDetectedViaNodeCreatedEvent() {
+ // Stop the watcher started in @BeforeEach to prevent it from processing events
+ tableChangeWatcher.stop();
+
+ // Create tables BEFORE starting a new watcher. This ensures that when
+ // CuratorCache starts and does its initial sync, the table nodes already
+ // have full data. CuratorCache fires NODE_CREATED (not NODE_CHANGED) for
+ // existing nodes, exercising the same code path that handles the race
+ // condition where NODE_CHANGED is lost due to async getData.
+ List<CoordinatorEvent> expectedEvents = new ArrayList<>();
+ for (int i = 0; i < 3; i++) {
+ TablePath tablePath = TablePath.of(DEFAULT_DB, "table_nc_" + i);
+ TableAssignment tableAssignment =
+ generateAssignment(
+ 3,
+ 3,
+ new TabletServerInfo[] {
+ new TabletServerInfo(0, "rack0"),
+ new TabletServerInfo(1, "rack1"),
+ new TabletServerInfo(2, "rack2")
+ });
+ long tableId =
+ metadataManager.createTable(tablePath, TEST_TABLE, tableAssignment, false);
+ SchemaInfo schemaInfo = metadataManager.getLatestSchema(tablePath);
+ long currentMillis = System.currentTimeMillis();
+ expectedEvents.add(
+ new CreateTableEvent(
+ TableInfo.of(
+ tablePath,
+ tableId,
+ schemaInfo.getSchemaId(),
+ TEST_TABLE,
+ remoteDataDir,
+ currentMillis,
+ currentMillis),
+ tableAssignment));
+ expectedEvents.add(new SchemaChangeEvent(tablePath, schemaInfo));
+ }
+
+ // Verify that the watcher has not processed any events
+ assertThat(eventManager.getEvents()).isEmpty();
+
+ // Start a new watcher. CuratorCache initial sync fires NODE_CREATED for
+ // existing nodes with full data - the same code path as when the async
+ // getData race causes NODE_CHANGED to be lost.
+ TestingEventManager newEventManager = new TestingEventManager();
+ TableChangeWatcher newWatcher = new TableChangeWatcher(zookeeperClient, newEventManager);
+ newWatcher.start();
+
+ retry(
+ Duration.ofMinutes(1),
+ () ->
+ assertThat(newEventManager.getEvents())
+ .containsExactlyInAnyOrderElementsOf(expectedEvents));
+ newWatcher.stop();
+ }
}