学习 Druid(九):数据规划

Druid 为数据规划提供了 Tier 和 Rule 机制:

  • Tier 用于标识 Historical
  • Rule 用于 Historical 如何加载 Segment

Tier

数据温度就是以数据的访问频次划分:

  • 热数据,访问频次高
  • 温数据,访问频次中
  • 冷数据,访问频次低

为了最大限度的利用资源,热数据存放在速度快的介质(如内存),冷数据存放在廉价的介质上(如硬盘)。

Tier 是 Druid 提供的用于区分不同 Historical 使用介质的特性。通过编辑 Historical 的 runtime.properties 文件,修改 druid.server.tier 配置项,为 Historical 指定 Tier,默认为 _default_tier

例如,为使用固态硬盘的 Historical 指定 Tier 为 ssd,为使用机械硬盘的 Historal 指定 Tier 为 hdd。

Rule

在 Druid 的使用场景中,时间越近的数据访问频次越高,时间越久的数据访问频次越低。

Druid 提供 Rule 决定了:

  1. 加载还是丢弃 Segment?
  2. 加载 Segment 到哪个 Tier?
  3. Tier 中保留多少 Segment 副本?
  4. 哪些 DataSource 的 Segment 加载到相同的 Historical?

按类型 Rule 分为以下三类:

  • Load Rule
  • DropRule
  • BroadcastRule

规则可以按 顺序 进行组合,从而实现更复杂的规则。

Load Rule

定义了如何加载 Segment 的规则。

加载全部:

{
  "type" : "loadForever",
  "tieredReplicants": {
    "_default_tier" : 1
  }
}

加载时间区间:

{
  "type" : "loadByInterval",
  "interval": "2019-10-01/2019-10-08",
  "tieredReplicants": {
    "_default_tier" : 1
  }
}

加载时间周期:

{
  "type" : "loadByPeriod",
  "period" : "P1M",
  "includeFuture" : true,
  "tieredReplicants": {
      "_default_tier" : 1
  }
}

Drop Rule

定义了如何丢弃 Segment 的规则。

丢弃全部:

{
  "type" : "dropForever"
}

丢弃时间区间:

{
  "type" : "dropByInterval",
  "interval" : "2019-10-01/2019-10-08"
}

丢弃时间周期:

{
  "type" : "dropByPeriod",
  "period" : "P1M",
  "includeFuture" : true
}

丢弃时间周期之前:

{
  "type" : "dropBeforeByPeriod",
  "period" : "P1M"
}

Broadcast Rule

定义了如何共同存放Segment不同(Co-located)DataSource 下 Segment 的规则。

共同存放全部:

{
  "type" : "broadcastForever",
  "colocatedDataSources" : [ "target_source1", "target_source2" ]
}

共同存放时间区间:

{
  "type" : "broadcastByInterval",
  "colocatedDataSources" : [ "target_source1", "target_source2" ],
  "interval" : "2012-01-01/2013-01-01"
}

共同存放时间周期:

{
  "type" : "broadcastByPeriod",
  "colocatedDataSources" : [ "target_source1", "target_source2" ],
  "period" : "P1M",
  "includeFuture" : true
}

以保留最近一个月数据举:chestnut::

首先,加载最近一个月:

{
  "type" : "loadByPeriod",
  "period" : "P1M",
  "includeFuture" : true,
  "tieredReplicants": {
      "_default_tier" : 1
  }
}

然后,删除全部:

{
  "type" : "dropForever"
}

其等价于,先删除一个月前:

{
  "type" : "dropBeforeByPeriod",
  "period" : "P1M"
}

然后,加载全部:

{
  "type" : "loadForever",
  "tieredReplicants": {
    "_default_tier" : 1
  }
}

参考