2.X/1. Getting Started

1-04-3. Creating, Indexing, and Deleting a Document

drscg 2017. 10. 1. 09:22

Create, index, and delete requests are write operations, which must be successfully completed on the primary shard before they can be copied to any associated replica shards, as shown in Figure 9, “하나의 document를 생성, 색인 또는 삭제”.

create, index, delete request는 쓰기 연산이다. Figure 9, “하나의 document를 생성, 색인 또는 삭제”에서 볼 수 있듯이, 관련된 replica shard에 복사하기 전에, primary shard에서 성공적으로 완료되어야 한다.

Figure 9. 하나의 document를 생성, 색인 또는 삭제

하나의 document를 생성, 색인 또는 삭제


Here is the sequence of steps necessary to successfully create, index, or delete a document on both the primary and any replica shards:

아래에 primary와 replica shard 양쪽에 document를 성공적으로 생성, 색인 또는 삭제하기 위해 필요한 일련의 과정을 나열하였다.

  1. The client sends a create, index, or delete request to Node 1.

    클라이언트가 create, index 또는 delete request를 Node 1 에 보낸다.

  2. The node uses the document’s _id to determine that the document belongs to shard 0. It forwards the request to Node 3, where the primary copy of shard 0 is currently allocated.

    node는 document를 shard 0 에 저장하기 위해 document의 _id 를 사용한다. shard 0 의 primary 복사본이 현재 할당되어 있는 Node 3 으로 request를 전달한다.

  3. Node 3 executes the request on the primary shard. If it is successful, it forwards the request in parallel to the replica shards on Node 1 and Node 2. Once all of the replica shards report success, Node 3 reports success to the coordinating node, which reports success to the client.

    Node 3 은 primary에서 request를 실행한다. 만약 성공하면, Node 1 과 Node 2 에 있는 replica shard로 request를 병렬로 전달한다. replica shard 모두가 성공했다고 하면, Node 3 은 coordinating node(Node 1)에 성공했다고 알려준다. 그러면 Node 1은 클라이언트에게 성공했다고 보고한다.

By the time the client receives a successful response, the document change has been executed on the primary shard and on all replica shards. Your change is safe.

클라이언트가 성공했다는 response를 받을 때까지, document의 변경은 primary shard와 모든 replica shard에서 실행될 수 있다. 이 때의 변경은 안전하다.

There are a number of optional request parameters that allow you to influence this process, possibly increasing performance at the cost of data security. These options are seldom used because Elasticsearch is already fast, but they are explained here for the sake of completeness:

이 프로세스에 영향을 미칠 수 있는, 데이터 보안을 댓가로 성능을 향상시킬 수 있는, 선택적인 request 매개변수가 많이 있다. Elasticsearch는 이미 빠르기 때문에, 이런 옵션은 거의 사용되지 않으나, 완성도를 위해 여기에서 설명한다.

consistency

By default, the primary shard requires a quorum, or majority, of shard copies (where a shard copy can be a primary or a replica shard) to be available before even attempting a write operation. This is to prevent writing data to the "wrong side" of a network partition. A quorum is defined as follows:

기본적으로, primary shard는 쓰기 연산을 시도하기 전에 이용할 수 있는, shard 복사본(primary나 replica shard가 될 수 있는 shard 복사본이 있는 곳)의 quorum(정족수) 이나 다수를 요구한다. 이는 네트워크 파티션의 "wrong side" 에 데이터를 쓰는 것을 방지한다. quorum은 아래와 같이 정의된다.

int( (primary + number_of_replicas) / 2 ) + 1

The allowed values for consistency are one (just the primary shard), all (the primary and all replicas), or the default quorum, or majority, of shard copies.

consistency 에 허용되는 값은 one (primary shard에게만), all (primary와 모든 replica) 또는 shard 복사본의 기본 quorum 또는 다수이다.

Note that the number_of_replicas is the number of replicas specified in the index settings, not the number of replicas that are currently active. If you have specified that an index should have three replicas, a quorum would be as follows:

number_of_replicas 는 현재 동작 중인 replica의 수가 아니라, index settings에 지정된 replica의 수라는 것을 기억하자. 만약, index는 3개의 replica를 가진다고 지정했다면, quorum은 아래와 같다.

int( (primary + 3 replicas) / 2 ) + 1 = 3

But if you start only two nodes, there will be insufficient active shard copies to satisfy the quorum, and you will be unable to index or delete any documents.

그런데, 만약 2개의 node만 시작했다면, quorum을 만족시킬 동작중인 shard 복사본이 부족하고, 어떤 document도 색인 하거나 지울 수 없게 된다.

timeout

What happens if insufficient shard copies are available? Elasticsearch waits, in the hope that more shards will appear. By default, it will wait up to 1 minute. If you need to, you can use the timeout parameter to make it abort sooner: 100 is 100 milliseconds, and 30s is 30 seconds.

이용할 수 있는 shard 복사본이 부족하면 어떤 일이 발생할까? 더 많은 shard가 나타날 거라고 기대하며, Elasticsearch는 기다린다. 기본적으로 1분을 기다린다. 필요하다면, 더 빨리 중지하도록 timeout(100 은 100ms, 30s 는 30 seconds) 매개변수를 사용할 수 있다.

Note

A new index has 1 replica by default, which means that two active shard copies shouldbe required in order to satisfy the need for a quorum. However, these default settings would prevent us from doing anything useful with a single-node cluster. To avoid this problem, the requirement for a quorum is enforced only when number_of_replicas is greater than 1.

새로운 index는 기본적으로 1 개의 replica를 가진다. 즉, quorum 의 필요성을 만족시키기 위해, 2개의 동작하는 shard 복사본이 요구된다. 그러나, 이런 기본 설정은 단일 node cluster에서 유용한 어떤 것을 하지 못하게 막을 수 있다. 이 문제점을 피하기 위해서, quorum에 대한 요구사항은 number_of_replica 가 1 보다 클 때만 강제된다.