Mapping metadata not restored from gateway on server restart, closes #57
This commit is contained in:
parent
65ed582a90
commit
4e1a1f3437
|
@ -89,6 +89,10 @@ public class IndexMetaData {
|
|||
return mappings;
|
||||
}
|
||||
|
||||
public String mapping(String mappingType) {
|
||||
return mappings.get(mappingType);
|
||||
}
|
||||
|
||||
public static Builder newIndexMetaDataBuilder(String index) {
|
||||
return new Builder(index);
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.elasticsearch.util.component.LifecycleComponent;
|
|||
import org.elasticsearch.util.concurrent.DynamicExecutors;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -162,10 +163,17 @@ public class GatewayService extends AbstractComponent implements ClusterStateLis
|
|||
threadPool.execute(new Runnable() {
|
||||
@Override public void run() {
|
||||
try {
|
||||
metaDataService.createIndex(indexMetaData.index(), indexMetaData.settings(), timeValueMillis(10));
|
||||
metaDataService.createIndex(indexMetaData.index(), indexMetaData.settings(), timeValueMillis(500));
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to create index [" + indexMetaData.index() + "]", e);
|
||||
}
|
||||
for (Map.Entry<String, String> entry : indexMetaData.mappings().entrySet()) {
|
||||
try {
|
||||
metaDataService.putMapping(new String[]{indexMetaData.index()}, entry.getKey(), entry.getValue(), true, timeValueMillis(10));
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to put mapping [" + entry.getKey() + "] for index [" + indexMetaData.index() + "]", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
package org.elasticsearch.test.integration.gateway;
|
||||
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
||||
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.client.Requests;
|
||||
import org.elasticsearch.gateway.Gateway;
|
||||
|
@ -57,6 +59,16 @@ public abstract class AbstractSimpleIndexGatewayTests extends AbstractServersTes
|
|||
|
||||
logger.info("Creating index [{}]", "test");
|
||||
client("server1").admin().indices().create(createIndexRequest("test")).actionGet();
|
||||
|
||||
// create a mapping
|
||||
PutMappingResponse putMappingResponse = client("server1").admin().indices().putMapping(putMappingRequest("test").type("type1")
|
||||
.mappingSource(mappingSource())).actionGet();
|
||||
assertThat(putMappingResponse.acknowledged(), equalTo(true));
|
||||
|
||||
// verify that mapping is there
|
||||
ClusterStateResponse clusterState = client("server1").admin().cluster().state(clusterState()).actionGet();
|
||||
assertThat(clusterState.state().metaData().index("test").mapping("type1"), notNullValue());
|
||||
|
||||
// create two and delete the first
|
||||
logger.info("Indexing #1");
|
||||
client("server1").index(Requests.indexRequest("test").type("type1").id("1").source(source("1", "test"))).actionGet();
|
||||
|
@ -79,6 +91,10 @@ public abstract class AbstractSimpleIndexGatewayTests extends AbstractServersTes
|
|||
startServer("server1");
|
||||
Thread.sleep(1000);
|
||||
|
||||
// verify that mapping is there
|
||||
clusterState = client("server1").admin().cluster().state(clusterState()).actionGet();
|
||||
assertThat(clusterState.state().metaData().index("test").mapping("type1"), notNullValue());
|
||||
|
||||
logger.info("Getting #1, should not exists");
|
||||
GetResponse getResponse = client("server1").get(getRequest("test").type("type1").id("1")).actionGet();
|
||||
assertThat(getResponse.exists(), equalTo(false));
|
||||
|
@ -140,6 +156,10 @@ public abstract class AbstractSimpleIndexGatewayTests extends AbstractServersTes
|
|||
assertThat(getResponse.sourceAsString(), equalTo(source("3", "test")));
|
||||
}
|
||||
|
||||
private String mappingSource() {
|
||||
return "{ type1 : { properties : { name : { type : \"string\" } } } }";
|
||||
}
|
||||
|
||||
private String source(String id, String nameValue) {
|
||||
return "{ type1 : { \"id\" : \"" + id + "\", \"name\" : \"" + nameValue + "\" } }";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue