CRZbulabula opened a new pull request, #18580:
URL: https://github.com/apache/iotdb/pull/18580

   ## Problem
   
   ConfigNode 每次触发 snapshot 都会固定分配 32MB 堆内存(`PartitionInfo` 中硬编码的
   `PARTITION_TABLE_BUFFER_SIZE`),与实际 partition 表大小无关。Edge 节点默认堆仅 224MB
   且 ConfigNode 快照被触发得更频繁(每 5000 条日志 / 每 30 分钟),固定大分配在边缘场景
   容易造成 OOM / GC 尖峰。此外 `TemplateTable` 与 `CNPhysicalPlanGenerator` 在加载/解析
   template 快照文件时会把整个文件读入堆(`IOUtils.toByteArray`),大模板文件会瞬时翻倍
   内存占用。
   
   ## Changes
   
   - 新增 `SnapshotStreamFactory`(node-commons),提供自适应、有上限、可复用的快照缓冲流:
     - 写缓冲按估算数据量自适应(`estimate/8`,下限 64KB),且不超过新配置
       `config_node_snapshot_buffer_size_max`(默认 4MB,0 表示禁用缓冲);
     - 读缓冲按 `min(fileSize, cap)` 决定,加载快照不再超过配置上限;
     - 写缓冲通过 ThreadLocal + SoftReference 复用,避免每次快照重复分配大数组。
   - `PartitionInfo` 移除固定 32MB 缓冲,改用 `SnapshotStreamFactory`,并根据上次快照
     文件大小自适应估算写缓冲;load 时同样受上限约束。
   - `TemplateTable` / `CNPhysicalPlanGenerator` 改用 `FileChannel.map` 内存映射解析
     template 快照文件,消除整文件堆拷贝(`CNPhysicalPlanGenerator` 对 0 字节文件增加保护)。
   - Edge 默认配置 `config_node_snapshot_buffer_size_max=262144`(256KB),
     `iotdb-system.properties.template` 中补充参数说明。
   
   ## Tests
   
   - 新增 `SnapshotStreamFactoryTest`:缓冲大小自适应/上限、禁用缓冲直通、读写往返、
     大写入绕过缓冲、缓冲复用、幂等 close、读缓冲上限。
   - `PartitionInfoTest`:新增“快照大于写缓冲”的往返测试,并在整个测试类中把缓冲上限
     压到 64KB 以回归验证小缓冲下快照正确性。
   - `CNPhysicalPlanGeneratorTest`:新增空模板文件保护测试。
   - 新增 `ConfigNodeConfigTest` 校验新参数默认值。
   - 全部相关 UT 通过(node-commons 7 个、confignode 11 个,另跑 TemplateTable /
     TemplatePreSetTable / ClusterSchemaInfo 共 10 个),spotless 与 checkstyle 通过。


-- 
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