Skip to content

Commit

Permalink
Use OpType.CREATE in GeoIpDownloader (#69951) (#69954)
Browse files Browse the repository at this point in the history
When indexing new chunks in GeoIpDwonloader we should never have to overwrite old chunks, if we try to that means that there are 2 simultaneous executions. This change forces one of them to throw error in such case.
  • Loading branch information
probakowski authored Mar 4, 2021
1 parent bc8987b commit 34524c0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ int indexChunks(String name, InputStream is, int chunk, String expectedMd5) thro
for (byte[] buf = getChunk(is); buf.length != 0; buf = getChunk(is)) {
md.update(buf);
client.prepareIndex(DATABASES_INDEX, "_doc").setId(name + "_" + chunk)
.setCreate(true)
.setSource(XContentType.SMILE, "name", name, "chunk", chunk, "data", buf)
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.setWaitForActiveShards(ActiveShardCount.ALL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.DocWriteRequest.OpType;
import org.elasticsearch.action.index.IndexAction;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
Expand Down Expand Up @@ -164,6 +165,7 @@ public void testIndexChunks() throws IOException {

client.addHandler(IndexAction.INSTANCE, (IndexRequest request, ActionListener<IndexResponse> listener) -> {
int chunk = chunkIndex.getAndIncrement();
assertEquals(OpType.CREATE, request.opType());
assertEquals("test_" + (chunk + 15), request.id());
assertEquals(XContentType.SMILE, request.getContentType());
Map<String, Object> source = request.sourceAsMap();
Expand Down

0 comments on commit 34524c0

Please sign in to comment.