跳转到主要内容

自动压缩 API

本主题介绍了 Apache Druid 中使用 Coordinator 职责进行自动压缩的状态和配置 API 端点。您可以在 Druid Web 控制台或 API 中配置自动压缩。

实验性功能

除了使用自动压缩 API 外,您还可以使用 supervisor API 通过压缩主管(compaction supervisors)提交自动压缩作业。有关更多信息,请参阅使用压缩主管进行自动压缩

在本主题中,http://ROUTER_IP:ROUTER_PORT 是您 Router 服务地址和端口的占位符。请将其替换为您部署环境的实际信息。例如,快速入门部署可以使用 https://:8888

管理自动压缩

创建或更新自动压缩配置

为数据源创建或更新自动压缩配置。在请求体中以 JSON 对象形式传入自动压缩配置。

自动压缩配置仅需要 dataSource 属性。如果未指定其他属性,Druid 将使用默认值进行填充。有关配置的详细信息,请参阅 自动压缩动态配置

请注意,即使数据源名称不存在,此端点也会返回 HTTP 200 OK 状态码。

URL

POST /druid/coordinator/v1/config/compaction

响应

成功提交自动压缩配置


请求示例

以下示例为数据源 wikipedia_hour 创建了自动压缩配置,该数据源是以 HOUR(小时)作为段粒度摄入的。此自动压缩配置会对 wikipedia_hour 执行压缩,产生的压缩段代表一天的数据间隔。

在此示例中

  • wikipedia_hour 是一个段粒度为 HOUR 的数据源。
  • skipOffsetFromLatest 设置为 PT0S,表示不跳过任何数据。
  • partitionsSpec 设置为默认的 dynamic,允许 Druid 动态确定最佳分区策略。
  • type 设置为 index_parallel,表示使用并行索引。
  • segmentGranularity 设置为 DAY,表示每个压缩后的段包含一天的数据。
curl "http://ROUTER_IP:ROUTER_PORT/druid/coordinator/v1/config/compaction"\
--header 'Content-Type: application/json' \
--data '{
"dataSource": "wikipedia_hour",
"skipOffsetFromLatest": "PT0S",
"tuningConfig": {
"partitionsSpec": {
"type": "dynamic"
},
"type": "index_parallel"
},
"granularitySpec": {
"segmentGranularity": "DAY"
}
}'

响应示例

请求成功时返回 HTTP 200 OK 状态码和空响应体。

移除自动压缩配置

移除数据源的自动压缩配置。这会将数据源的压缩状态更新为“未启用”(Not enabled)。

URL

DELETE /druid/coordinator/v1/config/compaction/{dataSource}

响应

成功删除自动压缩配置


请求示例

curl --request DELETE "http://ROUTER_IP:ROUTER_PORT/druid/coordinator/v1/config/compaction/wikipedia_hour"

响应示例

请求成功时返回 HTTP 200 OK 状态码和空响应体。

更新压缩任务的容量

信息

此 API 现已弃用。请改用更新集群级压缩配置

更新压缩任务的容量。压缩任务的最小数量为 1,最大数量为 2147483647。

请注意,虽然最大压缩任务数理论上可设置为 2147483647,但实际限制取决于集群的可用容量,并被限制在集群总容量的 10%。

URL

POST /druid/coordinator/v1/config/compaction/taskslots

查询参数

要限制压缩任务的最大数量,请使用可选的查询参数 ratiomax

  • ratio (可选)
    • 类型:Float
    • 默认值:0.1
    • 限制总任务槽位与压缩任务槽位的比率。
  • max (可选)
    • 类型: Int
    • 默认值:2147483647
    • 限制压缩任务的最大任务槽位数量。

响应

成功更新压缩配置


请求示例

curl --request POST "http://ROUTER_IP:ROUTER_PORT/druid/coordinator/v1/config/compaction/taskslots?ratio=0.2&max=250000"

响应示例

请求成功时返回 HTTP 200 OK 状态码和空响应体。

查看自动压缩配置

获取所有自动压缩配置

检索所有自动压缩配置。返回一个 compactionConfigs 对象,其中包含所有数据源的活动自动压缩配置。

您可以使用此端点检索 compactionTaskSlotRatiomaxCompactionTaskSlots 值,以管理压缩任务的资源分配。

URL

GET /druid/coordinator/v1/config/compaction

响应

成功检索自动压缩配置


请求示例

curl "http://ROUTER_IP:ROUTER_PORT/druid/coordinator/v1/config/compaction"

响应示例

查看响应
{
"compactionConfigs": [
{
"dataSource": "wikipedia_hour",
"taskPriority": 25,
"inputSegmentSizeBytes": 100000000000000,
"maxRowsPerSegment": null,
"skipOffsetFromLatest": "PT0S",
"tuningConfig": {
"maxRowsInMemory": null,
"appendableIndexSpec": null,
"maxBytesInMemory": null,
"maxTotalRows": null,
"splitHintSpec": null,
"partitionsSpec": {
"type": "dynamic",
"maxRowsPerSegment": 5000000,
"maxTotalRows": null
},
"indexSpec": null,
"indexSpecForIntermediatePersists": null,
"maxPendingPersists": null,
"pushTimeout": null,
"segmentWriteOutMediumFactory": null,
"maxNumConcurrentSubTasks": null,
"maxRetry": null,
"taskStatusCheckPeriodMs": null,
"chatHandlerTimeout": null,
"chatHandlerNumRetries": null,
"maxNumSegmentsToMerge": null,
"totalNumMergeTasks": null,
"maxColumnsToMerge": null,
"type": "index_parallel",
"forceGuaranteedRollup": false
},
"granularitySpec": {
"segmentGranularity": "DAY",
"queryGranularity": null,
"rollup": null
},
"dimensionsSpec": null,
"metricsSpec": null,
"transformSpec": null,
"ioConfig": null,
"taskContext": null
},
{
"dataSource": "wikipedia",
"taskPriority": 25,
"inputSegmentSizeBytes": 100000000000000,
"maxRowsPerSegment": null,
"skipOffsetFromLatest": "PT0S",
"tuningConfig": {
"maxRowsInMemory": null,
"appendableIndexSpec": null,
"maxBytesInMemory": null,
"maxTotalRows": null,
"splitHintSpec": null,
"partitionsSpec": {
"type": "dynamic",
"maxRowsPerSegment": 5000000,
"maxTotalRows": null
},
"indexSpec": null,
"indexSpecForIntermediatePersists": null,
"maxPendingPersists": null,
"pushTimeout": null,
"segmentWriteOutMediumFactory": null,
"maxNumConcurrentSubTasks": null,
"maxRetry": null,
"taskStatusCheckPeriodMs": null,
"chatHandlerTimeout": null,
"chatHandlerNumRetries": null,
"maxNumSegmentsToMerge": null,
"totalNumMergeTasks": null,
"maxColumnsToMerge": null,
"type": "index_parallel",
"forceGuaranteedRollup": false
},
"granularitySpec": {
"segmentGranularity": "DAY",
"queryGranularity": null,
"rollup": null
},
"dimensionsSpec": null,
"metricsSpec": null,
"transformSpec": null,
"ioConfig": null,
"taskContext": null
}
],
"compactionTaskSlotRatio": 0.1,
"maxCompactionTaskSlots": 2147483647,

}

获取自动压缩配置

检索特定数据源的自动压缩配置。

URL

GET /druid/coordinator/v1/config/compaction/{dataSource}

响应

成功检索数据源配置


请求示例

以下示例检索了数据源 wikipedia_hour 的自动压缩配置。

curl "http://ROUTER_IP:ROUTER_PORT/druid/coordinator/v1/config/compaction/wikipedia_hour"

响应示例

查看响应
{
"dataSource": "wikipedia_hour",
"taskPriority": 25,
"inputSegmentSizeBytes": 100000000000000,
"maxRowsPerSegment": null,
"skipOffsetFromLatest": "PT0S",
"tuningConfig": {
"maxRowsInMemory": null,
"appendableIndexSpec": null,
"maxBytesInMemory": null,
"maxTotalRows": null,
"splitHintSpec": null,
"partitionsSpec": {
"type": "dynamic",
"maxRowsPerSegment": 5000000,
"maxTotalRows": null
},
"indexSpec": null,
"indexSpecForIntermediatePersists": null,
"maxPendingPersists": null,
"pushTimeout": null,
"segmentWriteOutMediumFactory": null,
"maxNumConcurrentSubTasks": null,
"maxRetry": null,
"taskStatusCheckPeriodMs": null,
"chatHandlerTimeout": null,
"chatHandlerNumRetries": null,
"maxNumSegmentsToMerge": null,
"totalNumMergeTasks": null,
"maxColumnsToMerge": null,
"type": "index_parallel",
"forceGuaranteedRollup": false
},
"granularitySpec": {
"segmentGranularity": "DAY",
"queryGranularity": null,
"rollup": null
},
"dimensionsSpec": null,
"metricsSpec": null,
"transformSpec": null,
"ioConfig": null,
"taskContext": null
}

获取自动压缩配置历史记录

检索数据源的自动压缩配置历史记录。如果数据源不存在或没有压缩历史记录,则返回空列表。

响应包含一个对象列表,每个对象具有以下键:

  • globalConfig:包含适用于整个集群的自动压缩配置的 JSON 对象。
  • compactionConfig:包含数据源自动压缩配置的 JSON 对象。
  • auditInfo:包含有关所做更改信息的 JSON 对象,例如 authorcommentip
  • auditTime:更改进行的日期和时间。

URL

GET /druid/coordinator/v1/config/compaction/{dataSource}/history

查询参数

  • interval (可选)
    • 类型:ISO-8601
    • 将结果限制在指定的时间间隔内。使用 / 作为间隔字符串的分隔符。
  • count (可选)
    • 类型: Int
    • 限制结果的数量。

响应

成功检索配置历史记录


请求示例

curl "http://ROUTER_IP:ROUTER_PORT/druid/coordinator/v1/config/compaction/wikipedia_hour/history"

响应示例

查看响应
[
{
"globalConfig": {
"compactionTaskSlotRatio": 0.1,
"maxCompactionTaskSlots": 2147483647,
"compactionPolicy": {
"type": "newestSegmentFirst",
"priorityDatasource": "wikipedia"
},
"useSupervisors": true,
"engine": "native"
},
"compactionConfig": {
"dataSource": "wikipedia_hour",
"taskPriority": 25,
"inputSegmentSizeBytes": 100000000000000,
"maxRowsPerSegment": null,
"skipOffsetFromLatest": "P1D",
"tuningConfig": null,
"granularitySpec": {
"segmentGranularity": "DAY",
"queryGranularity": null,
"rollup": null
},
"dimensionsSpec": null,
"metricsSpec": null,
"transformSpec": null,
"ioConfig": null,
"taskContext": null
},
"auditInfo": {
"author": "",
"comment": "",
"ip": "127.0.0.1"
},
"auditTime": "2023-07-31T18:15:19.302Z"
},
{
"globalConfig": {
"compactionTaskSlotRatio": 0.1,
"maxCompactionTaskSlots": 2147483647,
"compactionPolicy": {
"type": "newestSegmentFirst"
},
"useSupervisors": false,
"engine": "native"
},
"compactionConfig": {
"dataSource": "wikipedia_hour",
"taskPriority": 25,
"inputSegmentSizeBytes": 100000000000000,
"maxRowsPerSegment": null,
"skipOffsetFromLatest": "PT0S",
"tuningConfig": {
"maxRowsInMemory": null,
"appendableIndexSpec": null,
"maxBytesInMemory": null,
"maxTotalRows": null,
"splitHintSpec": null,
"partitionsSpec": {
"type": "dynamic",
"maxRowsPerSegment": 5000000,
"maxTotalRows": null
},
"indexSpec": null,
"indexSpecForIntermediatePersists": null,
"maxPendingPersists": null,
"pushTimeout": null,
"segmentWriteOutMediumFactory": null,
"maxNumConcurrentSubTasks": null,
"maxRetry": null,
"taskStatusCheckPeriodMs": null,
"chatHandlerTimeout": null,
"chatHandlerNumRetries": null,
"maxNumSegmentsToMerge": null,
"totalNumMergeTasks": null,
"maxColumnsToMerge": null,
"type": "index_parallel",
"forceGuaranteedRollup": false
},
"granularitySpec": {
"segmentGranularity": "DAY",
"queryGranularity": null,
"rollup": null
},
"dimensionsSpec": null,
"metricsSpec": null,
"transformSpec": null,
"ioConfig": null,
"taskContext": null
},
"auditInfo": {
"author": "",
"comment": "",
"ip": "127.0.0.1"
},
"auditTime": "2023-07-31T18:16:16.362Z"
}
]

查看自动压缩状态

获取等待压缩的段

返回给定数据源等待压缩的段的总大小。如果数据源未启用自动压缩,则返回 404 响应。

URL

GET /druid/coordinator/v1/compaction/progress?dataSource={dataSource}

查询参数

  • dataSource (必需)
    • 类型:String
    • 此状态信息对应的数据源名称。

响应

成功检索等待压缩的段大小


请求示例

以下示例检索了数据源 wikipedia_hour 等待压缩的剩余段信息。

curl "http://ROUTER_IP:ROUTER_PORT/druid/coordinator/v1/compaction/progress?dataSource=wikipedia_hour"

响应示例

查看响应
{
"remainingSegmentSize": 7615837
}

获取压缩状态和统计信息

检索一个 latestStatus 对象数组,表示所有已启用自动压缩的数据源的最近一次自动压缩运行的状态和统计信息。

压缩状态响应

latestStatus 对象具有以下属性:

  • dataSource:此状态信息对应的数据源名称。
  • scheduleStatus:自动压缩调度状态。可能的值为 NOT_ENABLEDRUNNING。如果数据源有已提交的活动自动压缩配置,则返回 RUNNING。否则,返回 NOT_ENABLED
  • bytesAwaitingCompaction:此数据源等待自动压缩的字节总数(仅考虑符合自动压缩条件的间隔/段)。
  • bytesCompacted:此数据源已使用自动压缩配置中设置的规范进行压缩的字节总数。
  • bytesSkipped:此数据源被自动压缩跳过的(不符合自动压缩条件)字节总数。
  • segmentCountAwaitingCompaction:此数据源等待自动压缩的段总数(仅考虑符合自动压缩条件的间隔/段)。
  • segmentCountCompacted:此数据源已使用自动压缩配置中设置的规范进行压缩的段总数。
  • segmentCountSkipped:此数据源被自动压缩跳过的(不符合自动压缩条件)段总数。
  • intervalCountAwaitingCompaction:此数据源等待自动压缩的间隔总数(仅考虑符合自动压缩条件的间隔/段)。
  • intervalCountCompacted:此数据源已使用自动压缩配置中设置的规范进行压缩的间隔总数。
  • intervalCountSkipped:此数据源被自动压缩跳过的(不符合自动压缩条件)间隔总数。

URL

GET /druid/coordinator/v1/compaction/status

查询参数

  • dataSource (可选)
    • 类型:String
    • 按特定数据源名称过滤结果。

响应

成功检索 latestStatus 对象


请求示例

curl "http://ROUTER_IP:ROUTER_PORT/druid/coordinator/v1/compaction/status"

响应示例

查看响应
{
"latestStatus": [
{
"dataSource": "wikipedia_api",
"scheduleStatus": "RUNNING",
"bytesAwaitingCompaction": 0,
"bytesCompacted": 0,
"bytesSkipped": 64133616,
"segmentCountAwaitingCompaction": 0,
"segmentCountCompacted": 0,
"segmentCountSkipped": 8,
"intervalCountAwaitingCompaction": 0,
"intervalCountCompacted": 0,
"intervalCountSkipped": 1
},
{
"dataSource": "wikipedia_hour",
"scheduleStatus": "RUNNING",
"bytesAwaitingCompaction": 0,
"bytesCompacted": 5998634,
"bytesSkipped": 0,
"segmentCountAwaitingCompaction": 0,
"segmentCountCompacted": 1,
"segmentCountSkipped": 0,
"intervalCountAwaitingCompaction": 0,
"intervalCountCompacted": 1,
"intervalCountSkipped": 0
}
]
}

[实验性] 统一压缩 API

本节介绍了新的统一压缩 API,无论压缩动态配置中是否启用了压缩主管(即 useSupervisors 是否为 true),均可使用这些 API。

  • 如果禁用了压缩主管,这些 API 将读取或写入压缩动态配置,与上述基于 Coordinator 的压缩 API 相同。
  • 如果启用了压缩主管,这些 API 将读取或写入相应的压缩主管。结合下述 API,还可以使用主管 API 来读取或写入压缩主管,因为它们提供了更大的灵活性,并提供有关主管和任务状态的信息。

更新集群级压缩配置

更新适用于所有数据源的集群级压缩任务配置,除非在数据源压缩配置中明确覆盖。这包括以下字段:

配置项描述默认值
compactionTaskSlotRatio压缩任务占用的槽位与所有工作节点上总任务槽位的比例。0.1
maxCompactionTaskSlots压缩任务和子任务可占用的最大任务槽位数量。可用于压缩的最少任务槽位为 1。当使用 MSQ 引擎或带有范围分区的 Native 引擎时,单个压缩作业会占用多个任务槽位。在这种情况下,最小值应为 2,以确保集群中至少可以运行一个压缩作业。2147483647 (即总任务槽位)
compactionPolicy选择压缩间隔的策略。支持的策略包括 Newest segment first(最新段优先)、Most fragmented first(碎片化程度最高优先)和 Fixed interval order(固定间隔顺序)。Newest segment first
useSupervisors是否应在 Overlord 上使用主管而不是 Coordinator 职责来运行压缩。false
engine用于运行压缩任务的引擎,除非在数据源级压缩配置中进行了覆盖。可能的值为 nativemsq。仅当 useSupervisorstrue 时,才能使用 msq 引擎进行压缩。native
storeCompactionStatePerSegment此配置仅在 useSupervisorstrue 时生效。 是否在段元数据中持久化完整的压缩状态。当为 true(默认值)时,压缩状态会同时存储在段元数据和索引状态表中。这是 Druid 历史上的工作方式。当为 false 时,段元数据中仅存储指纹引用,从而减少了段表中的存储开销。实际的压缩状态存储在索引状态表中,可以使用上述指纹进行引用。最终此配置将被移除,所有压缩都将仅使用指纹方法。此配置的存在是为了让操作员能够提前选择这种未来的模式。警告:如果您将其设置为 false 然后压缩数据,回滚到早于索引状态指纹识别功能的 Druid 版本(< Druid 37)将导致压缩状态丢失,并触发已压缩段的重新压缩。true

压缩策略 newestSegmentFirst

字段描述默认值
type此值必须始终为 newestSegmentFirst
priorityDatasource优先压缩的数据源。该数据源的间隔会在任何其他数据源的间隔之前被选中进行压缩。在该数据源内,将根据选定的压缩策略对间隔进行优先级排序。

压缩策略 mostFragmentedFirst

此实验性策略优先压缩具有大量未压缩小段的间隔。它通过减少段数量来促进集群稳定性,而不是优化较新间隔上的查询性能。

字段描述默认值
type此值必须始终为 mostFragmentedFirst
priorityDatasource优先压缩的数据源。该数据源的间隔会在任何其他数据源的间隔之前被选中进行压缩。在该数据源内,将根据选定的压缩策略对间隔进行优先级排序。
minUncompactedCount间隔中必须存在的最少未压缩段数量,以使其符合压缩条件。必须大于 0。100
minUncompactedBytes间隔中未压缩段必须达到的最少总字节数,以使其符合压缩条件。支持人类可读的字节格式(例如,“10MiB”)。10 MiB
maxAverageUncompactedBytesPerSegment符合压缩条件的间隔内,未压缩段的最大平均大小。支持人类可读的字节格式(例如,“2GiB”)。2 GiB
minUncompactedBytesPercentForFullCompaction未压缩字节占总字节的百分比阈值(0-100),低于此值时,可以使用小型压缩(minor compaction)代替完全压缩(full compaction)。0
minUncompactedRowsPercentForFullCompaction未压缩行数占总行数的百分比阈值(0-100),低于此值时,可以使用小型压缩代替完全压缩。0

压缩策略 fixedIntervalOrder

此策略指定符合压缩条件的数据源和间隔及其顺序。它主要用于集成测试。

字段描述默认值
type此值必须始终为 fixedIntervalOrder
eligibleCandidates符合压缩条件的数据源-间隔对列表。每个条目包含 datasource(字符串)和 interval(ISO-8601 间隔)字段。压缩流程按指定的顺序处理候选项。

URL

POST /druid/indexer/v1/compaction/config/cluster

响应

成功更新压缩配置


请求示例

curl --request POST "http://ROUTER_IP:ROUTER_PORT/druid/coordinator/v1/config/compaction/cluster" \
--header 'Content-Type: application/json' \
--data '{
"compactionTaskSlotRatio": 0.5,
"maxCompactionTaskSlots": 1500,
"compactionPolicy": {
"type": "newestSegmentFirst",
"priorityDatasource": "wikipedia"
},
"useSupervisors": true,
"engine": "msq"
}'

响应示例

请求成功时返回 HTTP 200 OK 状态码和空响应体。

获取集群级压缩配置

检索适用于所有数据源的集群级压缩任务配置,除非在数据源压缩配置中明确覆盖。这包括 更新集群级压缩配置 中列出的所有字段。

URL

GET /druid/indexer/v1/compaction/config/cluster

响应

成功检索集群压缩配置


请求示例

curl "http://ROUTER_IP:ROUTER_PORT/druid/indexer/v1/compaction/config/cluster"

响应示例

查看响应
{
"compactionTaskSlotRatio": 0.5,
"maxCompactionTaskSlots": 1500,
"compactionPolicy": {
"type": "newestSegmentFirst",
"priorityDatasource": "wikipedia"
},
"useSupervisors": true,
"engine": "msq"
}

获取所有数据源的自动压缩配置

检索所有数据源的压缩配置。

URL

GET /druid/indexer/v1/compaction/config/datasources

响应

成功检索自动压缩配置


请求示例

curl "http://ROUTER_IP:ROUTER_PORT/druid/indexer/v1/compaction/config/datasources"

响应示例

查看响应
{
"compactionConfigs": [
{
"dataSource": "wikipedia_hour",
"taskPriority": 25,
"inputSegmentSizeBytes": 100000000000000,
"maxRowsPerSegment": null,
"skipOffsetFromLatest": "PT0S",
"tuningConfig": {
"maxRowsInMemory": null,
"appendableIndexSpec": null,
"maxBytesInMemory": null,
"maxTotalRows": null,
"splitHintSpec": null,
"partitionsSpec": {
"type": "dynamic",
"maxRowsPerSegment": 5000000,
"maxTotalRows": null
},
"indexSpec": null,
"indexSpecForIntermediatePersists": null,
"maxPendingPersists": null,
"pushTimeout": null,
"segmentWriteOutMediumFactory": null,
"maxNumConcurrentSubTasks": null,
"maxRetry": null,
"taskStatusCheckPeriodMs": null,
"chatHandlerTimeout": null,
"chatHandlerNumRetries": null,
"maxNumSegmentsToMerge": null,
"totalNumMergeTasks": null,
"maxColumnsToMerge": null,
"type": "index_parallel",
"forceGuaranteedRollup": false
},
"granularitySpec": {
"segmentGranularity": "DAY",
"queryGranularity": null,
"rollup": null
},
"dimensionsSpec": null,
"metricsSpec": null,
"transformSpec": null,
"ioConfig": null,
"taskContext": null
},
{
"dataSource": "wikipedia",
"taskPriority": 25,
"inputSegmentSizeBytes": 100000000000000,
"maxRowsPerSegment": null,
"skipOffsetFromLatest": "PT0S",
"tuningConfig": {
"maxRowsInMemory": null,
"appendableIndexSpec": null,
"maxBytesInMemory": null,
"maxTotalRows": null,
"splitHintSpec": null,
"partitionsSpec": {
"type": "dynamic",
"maxRowsPerSegment": 5000000,
"maxTotalRows": null
},
"indexSpec": null,
"indexSpecForIntermediatePersists": null,
"maxPendingPersists": null,
"pushTimeout": null,
"segmentWriteOutMediumFactory": null,
"maxNumConcurrentSubTasks": null,
"maxRetry": null,
"taskStatusCheckPeriodMs": null,
"chatHandlerTimeout": null,
"chatHandlerNumRetries": null,
"maxNumSegmentsToMerge": null,
"totalNumMergeTasks": null,
"maxColumnsToMerge": null,
"type": "index_parallel",
"forceGuaranteedRollup": false
},
"granularitySpec": {
"segmentGranularity": "DAY",
"queryGranularity": null,
"rollup": null
},
"dimensionsSpec": null,
"metricsSpec": null,
"transformSpec": null,
"ioConfig": null,
"taskContext": null
}
]
}

获取特定数据源的自动压缩配置

检索特定数据源的自动压缩配置。

URL

GET /druid/indexer/v1/compaction/config/datasources/{dataSource}

响应

成功检索数据源配置


请求示例

以下示例检索了数据源 wikipedia_hour 的自动压缩配置。

curl "http://ROUTER_IP:ROUTER_PORT/druid/indexer/v1/compaction/config/datasources/wikipedia_hour"

响应示例

查看响应
{
"dataSource": "wikipedia_hour",
"taskPriority": 25,
"inputSegmentSizeBytes": 100000000000000,
"maxRowsPerSegment": null,
"skipOffsetFromLatest": "PT0S",
"tuningConfig": {
"maxRowsInMemory": null,
"appendableIndexSpec": null,
"maxBytesInMemory": null,
"maxTotalRows": null,
"splitHintSpec": null,
"partitionsSpec": {
"type": "dynamic",
"maxRowsPerSegment": 5000000,
"maxTotalRows": null
},
"indexSpec": null,
"indexSpecForIntermediatePersists": null,
"maxPendingPersists": null,
"pushTimeout": null,
"segmentWriteOutMediumFactory": null,
"maxNumConcurrentSubTasks": null,
"maxRetry": null,
"taskStatusCheckPeriodMs": null,
"chatHandlerTimeout": null,
"chatHandlerNumRetries": null,
"maxNumSegmentsToMerge": null,
"totalNumMergeTasks": null,
"maxColumnsToMerge": null,
"type": "index_parallel",
"forceGuaranteedRollup": false
},
"granularitySpec": {
"segmentGranularity": "DAY",
"queryGranularity": null,
"rollup": null
},
"dimensionsSpec": null,
"metricsSpec": null,
"transformSpec": null,
"ioConfig": null,
"taskContext": null
}

创建或更新特定数据源的自动压缩配置

为数据源创建或更新自动压缩配置。在请求体中以 JSON 对象形式传入自动压缩配置。

自动压缩配置仅需要 dataSource 属性。如果未指定其他属性,Druid 将使用默认值进行填充。有关配置的详细信息,请参阅 自动压缩动态配置

请注意,即使数据源名称不存在,此端点也会返回 HTTP 200 OK 状态码。

URL

POST /druid/indexer/v1/compaction/config/datasources/wikipedia_hour

响应

成功提交自动压缩配置


请求示例

以下示例为数据源 wikipedia_hour 创建了自动压缩配置,该数据源是以 HOUR(小时)作为段粒度摄入的。此自动压缩配置会对 wikipedia_hour 执行压缩,产生的压缩段代表一天的数据间隔。

在此示例中

  • wikipedia_hour 是一个段粒度为 HOUR 的数据源。
  • skipOffsetFromLatest 设置为 PT0S,表示不跳过任何数据。
  • partitionsSpec 设置为默认的 dynamic,允许 Druid 动态确定最佳分区策略。
  • type 设置为 index_parallel,表示使用并行索引。
  • segmentGranularity 设置为 DAY,表示每个压缩后的段包含一天的数据。
curl "http://ROUTER_IP:ROUTER_PORT/druid/indexer/v1/compaction/config/datasources/wikipedia_hour"\
--header 'Content-Type: application/json' \
--data '{
"dataSource": "wikipedia_hour",
"skipOffsetFromLatest": "PT0S",
"tuningConfig": {
"partitionsSpec": {
"type": "dynamic"
},
"type": "index_parallel"
},
"granularitySpec": {
"segmentGranularity": "DAY"
}
}'

响应示例

请求成功时返回 HTTP 200 OK 状态码和空响应体。

删除特定数据源的自动压缩配置

移除数据源的自动压缩配置。这会将数据源的压缩状态更新为“未启用”(Not enabled)。

URL

DELETE /druid/indexer/v1/compaction/config/datasources/{dataSource}

响应

成功删除自动压缩配置


请求示例

curl --request DELETE "http://ROUTER_IP:ROUTER_PORT/druid/indexer/v1/compaction/config/datasources/wikipedia_hour"

响应示例

请求成功时返回 HTTP 200 OK 状态码和空响应体。

获取所有数据源的压缩状态

检索一个 latestStatus 对象数组,表示用户拥有读取权限的所有数据源的最近一次自动压缩运行的状态和统计信息。响应格式与 压缩状态响应 相同。

URL

GET /druid/indexer/v1/compaction/status/datasources

响应

成功检索 latestStatus 对象


请求示例

curl "http://ROUTER_IP:ROUTER_PORT/druid/indexer/v1/compaction/status/datasources"

响应示例

查看响应
{
"latestStatus": [
{
"dataSource": "wikipedia_api",
"scheduleStatus": "RUNNING",
"bytesAwaitingCompaction": 0,
"bytesCompacted": 0,
"bytesSkipped": 64133616,
"segmentCountAwaitingCompaction": 0,
"segmentCountCompacted": 0,
"segmentCountSkipped": 8,
"intervalCountAwaitingCompaction": 0,
"intervalCountCompacted": 0,
"intervalCountSkipped": 1
},
{
"dataSource": "wikipedia_hour",
"scheduleStatus": "RUNNING",
"bytesAwaitingCompaction": 0,
"bytesCompacted": 5998634,
"bytesSkipped": 0,
"segmentCountAwaitingCompaction": 0,
"segmentCountCompacted": 1,
"segmentCountSkipped": 0,
"intervalCountAwaitingCompaction": 0,
"intervalCountCompacted": 1,
"intervalCountSkipped": 0
}
]
}

获取单个数据源的压缩状态

检索数据源最近一次自动压缩运行的状态。响应格式与 压缩状态响应 相同,包含零个或一个条目。

URL

GET /druid/indexer/v1/compaction/status/datasources/{dataSource}

响应

成功检索 latestStatus 对象


示例请求

curl "http://ROUTER_IP:ROUTER_PORT/druid/indexer/v1/compaction/status/datasources/wikipedia_hour"

示例响应

查看响应
{
"latestStatus": [
{
"dataSource": "wikipedia_hour",
"scheduleStatus": "RUNNING",
"bytesAwaitingCompaction": 0,
"bytesCompacted": 5998634,
"bytesSkipped": 0,
"segmentCountAwaitingCompaction": 0,
"segmentCountCompacted": 1,
"segmentCountSkipped": 0,
"intervalCountAwaitingCompaction": 0,
"intervalCountCompacted": 1,
"intervalCountSkipped": 0
}
]
}