Apache Druid删除深度存储(Deep Storage)中的数据

参考 https://blog.csdn.net/Alongpo/article/details/89604655

Druid安装及demo测试请参考  https://blog.csdn.net/qq_34864753/article/details/100080664

假如我们只想保留Druid中某张表7天的数据,为了减少磁盘开销,删除前7天的数据

1. 设置表的保留规则  

参考 

https://blog.csdn.net/qq_34864753/article/details/100554508

设置了保留规则后会发现前7天的数据都不显示在页面上了,不过前七天的数据仍然保存在深度存储中,如果是hdfs作为深度存储,可以到segments目录下查看,导入的数据都存在

2. 编写删除json文件 delete_druid_data.json    # dataSource为表名,interval去表表示要删除21号的interval数据

{
  "type": "kill",
  "dataSource": "user_profile_cc",
  "interval" : "2019-10-20/2019-10-21"
}

执行

curl -X 'POST' -H 'Content-Type:application/json' -d @/home/admin/scripts/delete_druid_data.json http://overload节点ip:8090/druid/indexer/v1/task

再去hdfs下查看,发现表user_profile_cc的25号interval已经从hdfs中删除了

3. crontab批量定时删除druid深度存储数据(前提已经设置过数据保留规则

1. 创建一个txt文件存要删除的表名  druid_pre_deleted_table_list.txt

2.编写一个shell脚本   delete_druid_deepstorage_data.sh

#! /bin/bash

readonly SOURCE_FILE="表txt文件目录"

interval_less=$(date -d "9 days ago" "+%Y-%m-%d")
interval_more=$(date -d "8 days ago" "+%Y-%m-%d")
echo $interval_less
echo $interval_more

while read line 

do
  echo $line

curl -X 'POST' -H 'Content-Type:application/json' -d '{
  "type": "kill",
  "dataSource": "'$line'",
  "interval" : "'$interval_less'/'$interval_more'"
}
' http://overload节点ip:8090/druid/indexer/v1/task

done < ${SOURCE_FILE}

 

注意:如果不设置保留规则,需要先disable segments,否则删不掉数据,请参考  https://blog.csdn.net/Alongpo/article/details/89604655

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章