본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

CAT Segment Replication API (CAT 세그먼트 복제 API)

원문 보기 위키 갱신

CAT Segment Replication 작업은 각 복제본(replica) 샤드에서 진행 중이거나 마지막으로 완료된 세그먼트 복제 이벤트에 대한 정보와 관련 샤드 레벨 메트릭을 반환하는 API예요. 이 메트릭을 보면 복제본들이 프라이머리 샤드에 비해 얼마나 뒤처져 있는지(래그) 알 수 있습니다.

이 API는 세그먼트 복제를 활성화한 인덱스에서만 호출해야 합니다.

출처: OpenSearch 문서

본문

Endpoints

GET /_cat/segment_replication
GET /_cat/segment_replication/{index}

Path parameters

다음 표는 사용할 수 있는 경로 파라미터 목록이에요. 모든 경로 파라미터는 선택 사항입니다.

| Parameter | Data type | Description | | index | List | A comma-separated list of data streams, indexes, and aliases used to limit the request. Supports wildcards (*). To target all data streams and indexes, omit this parameter or use * or _all. |

Query parameters

다음 표는 사용할 수 있는 쿼리 파라미터 목록이에요. 모든 쿼리 파라미터는 선택 사항입니다.

| Parameter | Data type | Description | Default | | active_only | Boolean | When true, the response only includes ongoing segment replication events. | false | | allow_no_indices | Boolean | Whether to ignore the index if a wildcard index expression resolves to no concrete indexes. This includes the _all string or when no indexes have been specified. | N/A | | bytes | String | The units used to display byte values. Valid values are: b, kb, k, mb, m, gb, g, tb, t, pb, and p. | N/A | | completed_only | Boolean | When true, the response only includes the last-completed segment replication events. | false | | detailed | Boolean | When true, the response includes additional metrics for each stage of a segment replication event. | false | | expand_wildcards | List or String | Specifies the type of index that wildcard expressions can match. Supports comma-separated values. Valid values are: - all: Match any index, including hidden ones. - closed: Match closed, non-hidden indexes. - hidden: Match hidden indexes. Must be combined with open, closed, or both. - none: Wildcard expressions are not accepted. - open: Match open, non-hidden indexes. | N/A | | format | String | A short version of the Accept header, such as json or yaml. | N/A | | h | List | A comma-separated list of column names to display. | N/A | | help | Boolean | Returns help information. | false | | ignore_throttled | Boolean | Whether specified concrete, expanded, or aliased indexes should be ignored when throttled. | N/A | | ignore_unavailable | Boolean | Whether the specified concrete indexes should be ignored when missing or closed. | N/A | | index | List | A comma-separated list of data streams, indexes, and aliases used to limit the request. Supports wildcards (*). To target all data streams and indexes, omit this parameter or use * or _all. | N/A | | s | List | A comma-separated list of column names or column aliases to sort by. | N/A | | shards | List | A comma-separated list of shards to display. | N/A | | time | String | Specifies the time units, for example, 5d or 7h. For more information, see Supported units. Valid values are: nanos, micros, ms, s, m, h, and d. | N/A | | timeout | String | The operation timeout. | N/A | | v | Boolean | Enables verbose mode, which displays column headers. | false |

Path parameters

| Parameter | Type | Description | | index | String | The name of the index, or a comma-separated list or wildcard expression of index names used to filter results. If this parameter is not provided, the response contains information about all indexes in the cluster. |

Query parameters

| Parameter | Data type | Description | | active_only | Boolean | If true, the response only includes active segment replications. Defaults to false. | | detailed | String | If true, the response includes additional metrics for each stage of a segment replication event. Defaults to false. | | shards | String | A comma-separated list of shards to display. | | bytes | Byte units | Units used to display byte size values. | | format | String | A short version of the HTTP accept header. Valid values include JSON and YAML. | | h | String | A comma-separated list of column names to display. | | help | Boolean | If true, the response includes help information. Defaults to false. | | time | Time units | Units used to display time values. | | v | Boolean | If true, the response includes column headings. Defaults to false. | | s | String | Specifies to sort the results. For example, s=shardId:desc sorts by shardId in descending order. |

Example requests

REST Python

GET /_cat/segment_replication?v&s=s:desc

Copy Copy as cURL

response = client.cat.segment_replication(
params = { "v": "true", "s": "s:desc" }
)

Copy 다음 예제들은 다양한 세그먼트 복제 응답을 보여줍니다.

No active segment replication events

다음 쿼리는 모든 인덱스에 대해 열 제목이 포함된 세그먼트 복제 메트릭을 요청합니다.

REST Python

GET /_cat/segment_replication?v=true

Copy Copy as cURL

response = client.cat.segment_replication(
params = { "v": "true" }
)

Copy 위 요청에 대한 응답에는 다음과 같은 메트릭이 들어 있습니다.

shardId target_node target_host checkpoints_behind bytes_behind current_lag last_completed_lag rejected_requests
[index-1][0] runTask-1 127.0.0.1 0 0b 0s 7ms 0

Shard ID specified

다음 쿼리는 index1과 index2 인덱스에서 ID가 0인 샤드에 대해 열 제목이 포함된 세그먼트 복제 메트릭을 요청합니다.

REST Python

GET /_cat/segment_replication/index1,index2?v=true&shards=0

Copy Copy as cURL

response = client.cat.segment_replication(
index = "index1,index2",
params = { "v": "true", "shards": "0" }
)

Copy 위 요청에 대한 응답에는 메트릭이 들어 있습니다. 열 제목은 메트릭 이름과 일치합니다.

shardId target_node target_host checkpoints_behind bytes_behind current_lag last_completed_lag rejected_requests
[index-1][0] runTask-1 127.0.0.1 0 0b 0s 3ms 0
[index-2][0] runTask-1 127.0.0.1 0 0b 0s 5ms 0

Detailed response

다음 쿼리는 모든 인덱스에 대해 열 제목이 포함된 상세 세그먼트 복제 메트릭을 요청합니다.

REST Python

GET /_cat/segment_replication?v=true&detailed=true

Copy Copy as cURL

response = client.cat.segment_replication(
params = { "v": "true", "detailed": "true" }
)

Copy 응답에는 세그먼트 복제 이벤트의 파일과 단계에 대한 추가 메트릭이 포함됩니다.

shardId target_node target_host checkpoints_behind bytes_behind current_lag last_completed_lag rejected_requests stage time files_fetched files_percent bytes_fetched bytes_percent start_time stop_time files files_total bytes bytes_total replicating_stage_time_taken get_checkpoint_info_stage_time_taken file_diff_stage_time_taken get_files_stage_time_taken finalize_replication_stage_time_taken
[index-1][0] runTask-1 127.0.0.1 0 0b 0s 3ms 0 done 10ms 6 100.0% 4753 100.0% 2023-03-16T13:46:16.802Z 2023-03-16T13:46:16.812Z 6 6 4.6kb 4.6kb 0s 2ms 0s 3ms 3ms
[index-2][0] runTask-1 127.0.0.1 0 0b 0s 5ms 0 done 7ms 3 100.0% 3664 100.0% 2023-03-16T13:53:33.466Z 2023-03-16T13:53:33.474Z 3 3 3.5kb 3.5kb 0s 1ms 0s 2ms 2ms

Sorting the results

다음 쿼리는 모든 인덱스에 대해 열 제목이 포함된 세그먼트 복제 메트릭을 샤드 ID 내림차순으로 정렬해 요청합니다.

REST Python

GET /_cat/segment_replication?v&s=shardId:desc

Copy Copy as cURL

response = client.cat.segment_replication(
params = { "v": "true", "s": "shardId:desc" }
)

Copy 응답에는 정렬된 결과가 포함됩니다.

shardId    target_node  target_host checkpoints_behind bytes_behind current_lag last_completed_lag rejected_requests
[test6][1] runTask-2   127.0.0.1   0                  0b           0s          5ms                0
[test6][0] runTask-2   127.0.0.1   0                  0b           0s          4ms                0

Using a metric alias

요청에서는 메트릭의 전체 이름을 쓰거나 별칭 중 하나를 사용할 수 있어요. 다음 쿼리는 앞선 쿼리와 같지만, 정렬에 shardID 대신 별칭 s를 사용한 것입니다.

REST Python

GET /_cat/segment_replication?v&s=s:desc

Copy Copy as cURL

response = client.cat.segment_replication(
params = { "v": "true", "s": "s:desc" }
)

Copy

Example response metrics

다음 표는 모든 요청에서 반환되는 응답 메트릭을 보여줍니다. 쿼리 파라미터에서 메트릭을 참조할 때는 위 예제에서 본 것처럼 메트릭의 전체 이름이나 별칭 중 하나를 사용할 수 있습니다.

| Metric | Alias | Description | | shardId | s | The ID of a specific shard. | | target_host | thost | The target host IP address. | | target_node | tnode | The target node name. | | checkpoints_behind | cpb | The number of checkpoints by which the replica shard is behind the primary shard. | | bytes_behind | bb | The number of bytes by which the replica shard is behind the primary shard. | | current_lag | clag | The time elapsed while waiting for a replica shard to catch up to the primary shard. | | last_completed_lag | lcl | The time taken for a replica shard to catch up to the latest primary shard refresh. | | rejected_requests | rr | The number of rejected requests for the replication group. |

Additional detailed response metrics

다음 표는 detailed가 true로 설정된 경우 반환되는 추가 응답 필드 목록이에요.

| Metric | Alias | Description | | stage | st | The current stage of a segment replication event. | | time | t, ti | The amount of time a segment replication event took to complete, in milliseconds. | | files_fetched | ff | The number of files fetched so far for a segment replication event. | | files_percent | fp | The percentage of files fetched so far for a segment replication event. | | bytes_fetched | bf | The number of bytes fetched so far for a segment replication event. | | bytes_percent | bp | The number of bytes fetched so far for a segment replication event as a percentage. | | start_time | start | The segment replication start time. | | stop_time | stop | The segment replication stop time. | | files | f | The number of files that needs to be fetched for a segment replication event. | | files_total | tf | The total number of files that are part of this recovery, including both reused and recovered files. | | bytes | b | The number of bytes that needs to be fetched for a segment replication event. | | bytes_total | tb | The total number of bytes in the shard. | | replicating_stage_time_taken | rstt | The amount of time the replicating stage of a segment replication event took to complete. | | get_checkpoint_info_stage_time_taken | gcistt | The amount of time the get checkpoint info stage of a segment replication event took to complete. | | file_diff_stage_time_taken | fdstt | The amount of time the file diff stage of a segment replication event took to complete. | | get_files_stage_time_taken | gfstt | The amount of time the get files stage of a segment replication event took to complete. | | finalize_replication_stage_time_taken | frstt | The amount of time the finalize replication stage of a segment replication event took to complete. |

더 알아보기 (Learn more)

세그먼트 복제는 프라이머리 샤드에서 복제본으로 세그먼트 파일 자체를 복사하는 방식이라, 네트워크 부하가 크게 줄어드는 것이 장점이에요. 이 CAT API에서 확인한 랙(lag) 메트릭을 모니터링하면 복제본이 프라이머리를 잘 따라오고 있는지 실시간으로 점검할 수 있습니다. 세그먼트 복제의 개념과 동작 원리는 OpenSearch의 segment-replication 문서를, 클러스터 전체 상태는 CAT Health API를 함께 확인해 보세요.