lifulong commented on PR #4508:
URL: https://github.com/apache/flink-cdc/pull/4508#issuecomment-7187005397

   > This doesn't seem like the proper way to handle it. Usually, Flink CDC 
relies on JDBC for chunk splitting during the snapshot (full-load) phase, and 
the incremental phase stays in the same process. To prevent OOM errors, we 
should implement rate limiting on the gRPC client side.
   
   Thanks for the review, @Mrart. Agreed that JDBC chunk splitting is the usual 
Flink CDC approach, and that a gRPC rate limit is a reasonable safeguard 
against scan-side OOM. I would like to explain why this connector still splits 
on TiKV regions.
   
   The failure we are fixing comes from the current default split, not from 
scan speed. `getTableKeyRangesByHandle` cuts `[Long.MIN_VALUE, Long.MAX_VALUE]` 
into `parallelism` equal slices and never looks at where handles actually are. 
A clustered `AUTO_INCREMENT` primary key only occupies `[1, maxId]`. With 
parallelism 8, seven slices are empty and one subtask owns the whole table, 
then OOMs inside `KVClient.scan`. Limiting the gRPC client would slow that one 
task down, but the other subtasks would still be idle. The skew stays.
   
   JDBC `min`/`max` chunking would see the real id endpoints and avoid those 
empty slices. On TiDB it is still not the path we want for the snapshot:
   
   - TiDB is a stateless SQL layer. The rows and the CDC change feed both live 
in TiKV. A JDBC scan still becomes coprocessor requests, but every row is 
decoded and shipped through a TiDB server, so throughput stops scaling with 
Flink parallelism. Scanning the TiKV key range directly is the fast path.
   - Snapshot and incremental reads in this connector already share one TiKV 
key range (`CDCClient` + `resolvedTs`). JDBC chunks are SQL predicates. Those 
two boundaries do not line up for common handle, `_tidb_rowid`, or partitioned 
tables, which makes the handoff easy to overlap or to gap.
   - Equal-width chunks on `[minId, maxId]` still ignore holes (deletes, 
non-contiguous ids). TiKV does not. A Region is the physical shard (about 96MB, 
split and merged by PD). Empty handle space collapses into few Regions; dense 
data is split into many. Partitioning contiguous Regions therefore follows the 
real data volume instead of the theoretical `long` domain.
   
   This is also how PingCAP's archived 
[TiBigData](https://github.com/pingcap/TiBigData) connectors (Flink / Presto / 
Hive) read TiDB: metadata may go through SQL, but the scan is split by TiKV 
Region and sent to TiKV. JDBC is kept for catalog and as an optional, slower 
write path (`tidb.sink.impl=tikv` exists specifically to bypass TiDB).
   
   Region count is only a size proxy, so a single hot Region can still be 
larger than its neighbors. A gRPC rate limit would be a good follow-up safety 
valve on top of this split. I do not think it can replace the split, because it 
does not move ownership off the overloaded subtask. Happy to adjust if there is 
a case where Region assignment is still badly skewed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to