Apache Druid 0.18.1 合并 segements

262 阅读1分钟

文章首发于微信公众号,头条号。

问题

Apache druid 中 的实时任务 默认一个小时生成一个segement (如果是老版本,一个小时生成的数量与Kafka 的partition 数量有关),会导致集群产生大量的 segements.根据druid 的建议 每个 segement大小 300M-700M. 有时需要进行compact .


Apache Druid 0.18.1 合并 segements


向 overlord节点提交任务地址

http://overlord:port/druid/indexer/v1/task
Apache Druid 0.18.1 合并 segements

任务内容

保持原有granularity

{  "type": "compact",  "dataSource": "call_record_test_2",  "interval": "2015-04-01/2020-09-01",  "tuningConfig" : {    "type" : "index_parallel",    "maxRowsPerSegment" : 5000000,    "maxRowsInMemory" : 25000  }}
Apache Druid 0.18.1 合并 segements

修改 granularity ​​​​​​​

{  "type": "compact",  "dataSource": "compaction-tutorial",  "interval": "2015-09-12/2015-09-13",  "segmentGranularity": "DAY",  "tuningConfig" : {    "type" : "index_parallel",    "maxRowsPerSegment" : 5000000,    "maxRowsInMemory" : 25000,    "forceExtendableShardSpecs" : true  }}
Apache Druid 0.18.1 合并 segements

清理深度存储文件

经过 compact 操作的segements 只是将元数据中的 segements used 标记为 0. 不在加载数据,但数据在深度存储中依然存在。

需要另行清除。

深度存储清理任务

{	"type":"kill",	"dataSource":"call_record_test_2",	"interval":"2020-01-01/2020-04-01"	}
Apache Druid 0.18.1 合并 segements

此任务将会进行两个操作。

1.删除元数据表:druid_segments 中used 为 0的 segements .

2.清理深度存储中对应的文件.

总结


Apache Druid 0.18.1 合并 segements


druid 中还提供了一个hadoop的方式进行合并任务。这种Hadoop方式将更加的灵活,基本上的操作在hadoop中 将数据重新按照新的规则重新写入。

hadoop任务的方式将会更加复杂些。

以后在整理相关的文章。