[server] Stale or wrong metadata served for missing and re-created tables
Search before asking
- [x] I searched in the issues and found nothing similar.
Fluss version
main (1.1-SNAPSHOT)
Please describe the bug 🐞
Found while working on #4706. Two server-side problems with missing and re-created tables:
1. Metadata requests for a missing table return UNKNOWN_SERVER_ERROR instead of TABLE_NOT_EXIST
MetadataManager#getTables throws TableNotExistException for a missing table, but its own catch (Exception e) wraps it in a FlussRuntimeException("Failed to get tables ..."). The metadata RPC then answers with UNKNOWN_SERVER_ERROR, so clients can't tell that the table was dropped. This is one reason why lookups on a dropped table never return (#4706).
2. Tablet servers serve stale metadata after a table is dropped and re-created under the same path
Until a tablet server receives the UpdateMetadata for the re-created table, TabletServerMetadataCache can combine metadata of the dropped and the new table:
getTableMetadatacombines the new table's info from ZK with the dropped table's cached buckets.getPartitionMetadatacan return the new table id together with the dropped table's partition id for the same partition name, e.g.TableBucket{tableId=4, partitionId=2}where partition 2 belonged to the dropped table 3.
Clients then route writes to buckets or partitions that don't exist. Depending on timing, writes fail fast or hang forever in flush(). This happens on main, mostly under load (e.g. a full mvn verify -pl fluss-server,fluss-client run):
FlussTableITCase#testAppendAndPollhangs, or fails withInvalidBucketRoutingException: ... requested bucket count 10, expected 1.FlussLakeTableITCase#testPrimaryKeyTableandAutoPartitionedTableITCase#testPartitionedTablePrefixLookupfail withIllegalArgumentException: table path not found for tableId 3 in cluster.
Solution
- Rethrow
TableNotExistExceptioninMetadataManager#getTablesinstead of wrapping it, so clients getTABLE_NOT_EXIST. - In
TabletServerMetadataCache, serve cached table metadata only if the table id in ZK matches the cached one, and serve a cached partition only if ZK registers that partition name with the same table id and partition id. Otherwise fall back to ZK.
Are you willing to submit a PR?
- [x] I'm willing to submit a PR!