Skip to content

Commit

Permalink
Send the update-mapping events before actually indexing into the shar…
Browse files Browse the repository at this point in the history
…d, because the latter may generate exceptions (like when the shard is not yet ready to accept new docs).

Also improved the SimpleDeleteMappingTest, as it make take a while until the update-mapping event is processed.

Closes #3782
  • Loading branch information
bleskes committed Sep 26, 2013
1 parent 39deaed commit 6372284
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ protected PrimaryResponse<IndexResponse, IndexRequest> shardOperationOnPrimary(C
.version(request.version())
.versionType(request.versionType())
.origin(Engine.Operation.Origin.PRIMARY);
if (index.parsedDoc().mappingsModified()) {
updateMappingOnMaster(request);
}
indexShard.index(index);
version = index.version();
op = index;
Expand All @@ -212,6 +215,9 @@ protected PrimaryResponse<IndexResponse, IndexRequest> shardOperationOnPrimary(C
.version(request.version())
.versionType(request.versionType())
.origin(Engine.Operation.Origin.PRIMARY);
if (create.parsedDoc().mappingsModified()) {
updateMappingOnMaster(request);
}
indexShard.create(create);
version = create.version();
op = create;
Expand All @@ -223,9 +229,7 @@ protected PrimaryResponse<IndexResponse, IndexRequest> shardOperationOnPrimary(C
// ignore
}
}
if (op.parsedDoc().mappingsModified()) {
updateMappingOnMaster(request);
}

// update the version on the request, so it will be used for the replicas
request.version(version);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasKey;


/**
Expand All @@ -52,12 +53,9 @@ public void simpleDeleteMapping() throws Exception {
}

ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState();
if (!clusterState.metaData().index("test").mappings().containsKey("type1")) {
logger.info("mapping of type [{}] is not in the clusterstate version: [{}] localNode: [{}] nodes: [{}]", "type1",
clusterState.version(), clusterState.nodes().localNode(), clusterState.nodes().dataNodes().values());
logger.info("Current mappings in clusterstate: [{}]", clusterState.metaData().index("test").mappings().keySet());
}
assertThat(clusterState.metaData().index("test").mappings().containsKey("type1"), equalTo(true));
for (int i = 0; i < 10 && !clusterState.metaData().index("test").mappings().containsKey("type1"); i++, Thread.sleep(100)) ;

assertThat(clusterState.metaData().index("test").mappings(), hasKey("type1"));

client().admin().indices().prepareDeleteMapping().setType("type1").execute().actionGet();
Thread.sleep(500); // for now, we don't have ack logic, so just wait
Expand Down

0 comments on commit 6372284

Please sign in to comment.