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

Split Index API (인덱스 분할 API)

원문 보기 위키 갱신

Split Index API는 기존 인덱스의 프라이머리 샤드 수를 늘리는 API예요. 원래 각 프라이머리 샤드를 둘 이상의 프라이머리 샤드로 나누는 새 대상 인덱스를 만들어요. 인덱스가 원래 샤드 수를 초과해 늘어나서 데이터 양이나 쿼리 부하를 처리할 추가 용량이 필요할 때 유용합니다.

대상 인덱스의 프라이머리 샤드 수는 소스 인덱스의 프라이머리 샤드 수의 배수여야 해요. 예를 들어 프라이머리 샤드가 2개인 인덱스는 4, 6, 8 또는 2의 다른 배수로 분할할 수 있습니다. 프라이머리 샤드가 1개인 인덱스는 아무 개수의 샤드로 분할할 수 있어요.

인덱스가 지원하는 최대 분할 수는 index.number_of_routing_shards 설정에 따라 달라집니다. 이 설정은 일관 해싱(consistent hashing)으로 문서가 분산되는 전체 해싱 공간을 정의합니다. 일관 해싱은 각 새 샤드가 원래 해시 공간의 완전하고 연속적인 부분집합에 매핑되어야 하므로 곱셈 인수만 지원돼요. 증분 리샤딩(N → N+1)은 모든 샤드에 걸쳐 문서를 리밸런싱해야 하므로 검색 지향 데이터 구조에는 비용이 너무 높습니다. 예를 들어 샤드 2개와 number_of_routing_shards가 12(2 x 2 x 3)로 설정된 인덱스는 다음 분할 경로를 지원합니다.

  • 2 -> 4 -> 12 (2로 분할, 그다음 3으로 분할)
  • 2 -> 6 -> 12 (3으로 분할, 그다음 2로 분할)
  • 2 -> 12 (6으로 분할)

명시적으로 설정하지 않으면 number_of_routing_shards는 최대 1,024개 샤드까지 반복적으로 두 배로 늘리는 것을 허용하는 값으로 기본 설정됩니다.

출처: OpenSearch 문서

본문

Prerequisites

인덱스를 분할하려면 먼저 다음 조건을 충족해야 합니다.

  • 인덱스가 읽기 전용이어야 합니다. 인덱스를 읽기 전용으로 만들려면 동적 인덱스 레벨 인덱스 설정 중 index.blocks.write를 true로 설정하세요.
  • 클러스터 상태(health)가 green이어야 합니다.

또한 분할 작업은 다음 제약 조건을 적용합니다.

  • 대상 인덱스는 이미 존재하면 안 됩니다.
  • 소스 인덱스는 대상 인덱스보다 프라이머리 샤드가 적어야 합니다.
  • 대상 인덱스의 프라이머리 샤드 수는 소스 인덱스의 프라이머리 샤드 수의 배수여야 합니다.
  • 분할 과정을 처리하는 노드에는 기존 인덱스의 두 번째 사본을 수용할 충분한 여유 디스크 공간이 있어야 합니다.

다음 요청은 catalog-logs 인덱스를 분할 준비를 위해 읽기 전용으로 만듭니다.

PUT /catalog-logs/_settings
{
  "settings": {
    "index.blocks.write": true
  }
}

분할 요청에는 매핑을 지정할 수 없어요. 대상 인덱스는 소스 인덱스의 모든 매핑을 상속합니다.

분할 작업은 다음 단계를 수행합니다.

  1. 동일한 매핑과 구성을 갖지만 프라이머리 샤드 수가 더 많은 새 대상 인덱스를 할당합니다.
  2. 소스 세그먼트에서 대상 인덱스 디렉터리로 하드 링크를 설정합니다. 파일 시스템이 하드 링크를 지원하지 않으면 전체 바이트 레벨 복사가 발생하는데, 이는 훨씬 오래 걸립니다.
  3. 각 문서를 새 라우팅 레이아웃에 따라 올바른 대상 샤드에 재할당하고 더 이상 속하지 않는 문서를 제거하는 리해싱(rehashing) 패스를 실행합니다.
  4. 대상 인덱스에서 샤드 리커버리를 시작합니다. 닫힌 인덱스가 다시 열릴 때 실행되는 과정과 유사합니다.

Monitoring the split process

분할 API는 대상 인덱스가 클러스터 상태에 추가되는 즉시 반환되며, 분할 작업이 완료될 때까지 기다리지 않아요. 분할 과정은 다음 샤드 상태를 거쳐 진행됩니다.

  1. Unassigned – API가 반환된 직후 대상 인덱스의 모든 샤드는 이 상태에서 시작합니다.
  2. Initializing – 프라이머리 샤드가 노드에 할당되면 이 상태로 전환되고 데이터 재분배가 시작됩니다.
  3. Active – 분할이 완료되면 샤드가 활성 상태가 됩니다. 그런 다음 OpenSearch는 구성된 복제본을 할당하려 시도하고 밸런싱을 위해 프라이머리 샤드를 다른 노드로 이동할 수도 있습니다.

샤드 리커버리 진행 상황은 CAT recovery API로 추적하거나, Cluster Health API를 wait_for_status=yellow와 함께 사용해 모든 프라이머리 샤드가 할당될 때까지 기다릴 수 있습니다.

대상 인덱스를 만들 때 OpenSearch 인덱스 이름에는 다음 제한 사항이 있다는 점을 기억하세요.

  • 모든 문자가 소문자여야 합니다.
  • 인덱스 이름은 밑줄(_)이나 하이픈(-)으로 시작할 수 없습니다.
  • 인덱스 이름은 공백, 쉼표 또는 다음 문자를 포함할 수 없습니다.

:, ", *, +, /, \, |, ?, #, >, <

Endpoints

POST /{index}/_split/{target}
PUT  /{index}/_split/{target}

Path parameters

다음 표는 사용할 수 있는 경로 파라미터 목록이에요.

Parameter Required Data type Description
index Required String The name of the source index to split.
target Required String The name of the target index to create.

Query parameters

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

Parameter Data type Description Default
wait_for_active_shards String The number of active shard copies that must be available before OpenSearch returns a response. Because the split operation creates a new index, the wait for active shards setting on index creation applies here as well. Set to all or a positive integer. Values greater than 1 require replicas. For example, if you specify a value of 3, the index must have two replicas distributed across two additional nodes for the request to succeed. 1
cluster_manager_timeout String The amount of time to wait for a connection to the cluster manager node. 30s
timeout String The amount of time to wait for a response. If no response is received before the timeout expires, the request fails and returns an error. 30s
wait_for_completion Boolean When set to false, the request returns immediately instead of after the operation is finished. To monitor the operation status, use the Tasks API with the task ID returned by the request. true
task_execution_timeout String The amount of time to wait for the task to complete. Only applicable when wait_for_completion is set to false. 1h

Request body fields

다음 표는 사용할 수 있는 요청 본문 필드 목록이에요. 모든 필드는 선택 사항입니다.

Field Data type Description
settings Object Index settings to apply to the target index. See Index settings.
aliases Object Aliases to associate with the target index. See Alias APIs.

Index codec considerations

인덱스 코덱 관련 고려 사항은 Index codecs 문서를 참고하세요.

Example: Splitting an index

다음 예제는 catalog-logs 인덱스를 프라이머리 샤드 2개에서 4개로 분할하고, 쓰기 블록을 제거한 뒤 별칭을 연결합니다.

POST /catalog-logs/_split/catalog-logs-split
{
  "settings": {
    "index.number_of_shards": 4,
    "index.number_of_replicas": 0,
    "index.blocks.write": null
  },
  "aliases": {
    "catalog-logs-current": {}
  }
}
response = client.indices.split(
  index = "catalog-logs",
  target = "catalog-logs-split",
  body =   {
    "settings": {
      "index.number_of_shards": 4,
      "index.number_of_replicas": 0,
      "index.blocks.write": null
    },
    "aliases": {
      "catalog-logs-current": {}
    }
  }
)

프라이머리 샤드가 1개인 인덱스는 아무 개수의 샤드로 분할할 수 있어요. 다음 예제는 catalog-events 인덱스를 1개 샤드에서 3개로 분할합니다.

POST /catalog-events/_split/catalog-events-expanded
{
  "settings": {
    "index.number_of_shards": 3,
    "index.number_of_replicas": 0,
    "index.blocks.write": null
  }
}
response = client.indices.split(
  index = "catalog-events",
  target = "catalog-events-expanded",
  body =   {
    "settings": {
      "index.number_of_shards": 3,
      "index.number_of_replicas": 0,
      "index.blocks.write": null
    }
  }
)

Example response

{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "catalog-logs-split"
}

Response body fields

다음 표는 모든 응답 본문 필드 목록이에요.

Field Data type Description
acknowledged Boolean Indicates whether the request was acknowledged by all relevant nodes in the cluster.
shards_acknowledged Boolean Indicates whether the required number of shard copies were started before the request timed out.
index String The name of the target index that was created.

Security 플러그인을 사용한다면 적절한 권한이 있어야 합니다: indices:admin/resize.

더 알아보기 (Learn more)

분할은 인덱스가 커져서 샤드 수를 늘려야 할 때 사용하는 스케일 업 전략이에요. 반대로 샤드 수를 줄이는 shrink 작업도 있으니 둘을 함께 이해해 두면 좋습니다. 분할 전에는 반드시 인덱스를 읽기 전용으로 만들고 클러스터 상태가 green인지 확인해야 하며, 동시 세그먼트 검색(index codecs) 설정이 분할에 어떤 영향을 주는지도 docs의 Index codecs 문서에서 확인해 보세요.