跳至主要內容

...大约 2 分钟

时间分区

主要功能

时间分区按照时间分割数据,一个时间分区用于保存某个时间范围内的所有数据。时间分区编号使用自然数表示,0 表示 1970 年 1 月 1 日,每隔 partition_interval 秒后加一。数据通过计算 timestamp / partition_interval 得到自己所在的时间分区编号,主要配置项如下所示:

注意:当前不建议开启此功能。 如果打开,请计算合适的 concurrent_writing_time_partition 和 wal_buffer_size, 计算公式如 wal_buffer_size = MaxDirectMemorySizeInBytes * 0.3 / (storage_group_num * virtual_storage_group_num) / concurrent_writing_time_partition

  • enable_partition
名字enable_partition
描述是否开启将数据按时间分区存储的功能,如果关闭,所有数据都属于分区 0 (不建议开启此功能。 如果打开,请计算合适的 concurrent_writing_time_partition 和 wal_buffer_size)
类型Bool
默认值false
改后生效方式仅允许在第一次启动服务前修改
  • partition_interval
名字partition_interval
描述存储组分区的时间段长度,用户指定的存储组下会使用该时间段进行分区,单位:秒
类型Int64
默认值604800
改后生效方式仅允许在第一次启动服务前修改

配置示例

开启时间分区功能,并设置 partition_interval 为 86400(一天),则数据的分布情况如下图所示:

time partition example
  • 插入一条时间戳为 0 的数据,计算 0 / 86400 = 0,则该数据会被存储到 0 号文件夹下的TsFile中

  • 插入一条时间戳为 1609459200010 的数据,计算 1609459200010 / 86400 = 18628,则该数据会被存储到 18628 号文件夹下的TsFile中

使用建议

使用时间分区功能时,建议同时打开 Memtable 的定时刷盘功能和 TsFileProcessor 的定时关闭功能,共 9 个相关配置参数(详情见 timed_flush与timed_close配置项)。

  • enable_timed_flush_unseq_memtable: 是否开启乱序 Memtable 的定时刷盘,默认打开。

  • enable_timed_flush_seq_memtable: 是否开启顺序 Memtable 的定时刷盘,默认关闭。应当在开启时间分区后打开,定时刷盘非活跃时间分区下的 Memtable,为定时关闭 TsFileProcessor 作准备。

  • enable_timed_close_tsfile: 是否开启 TsFileProcessor 的定时关闭,默认关闭。应当在开启时间分区后打开,定时关闭非活跃时间分区下的 TsFileProcessor,减少内存占用。

Copyright © 2024 The Apache Software Foundation.
Apache IoTDB, IoTDB, Apache, the Apache feather logo, and the Apache IoTDB project logo are either registered trademarks or trademarks of The Apache Software Foundation in all countries

Have a question? Connect with us on QQ, WeChat, or Slack. Join the community now.