New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better logic on sending mapping update new type introduction #6669
Changes from 2 commits
3e5e018
9e413e3
e406dcb
bbbab96
ad63dae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.bytes.BytesReference; | ||
import org.elasticsearch.common.collect.Tuple; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.io.stream.BytesStreamOutput; | ||
import org.elasticsearch.common.lucene.Lucene; | ||
|
@@ -369,9 +370,12 @@ private IndexShardState changeState(IndexShardState newState, String reason) { | |
@Override | ||
public Engine.Create prepareCreate(SourceToParse source, long version, VersionType versionType, Engine.Operation.Origin origin, boolean canHaveDuplicates, boolean autoGeneratedId) throws ElasticsearchException { | ||
long startTime = System.nanoTime(); | ||
DocumentMapper docMapper = mapperService.documentMapperWithAutoCreate(source.type()); | ||
ParsedDocument doc = docMapper.parse(source); | ||
return new Engine.Create(docMapper, docMapper.uidMapper().term(doc.uid().stringValue()), doc, version, versionType, origin, startTime, state != IndexShardState.STARTED || canHaveDuplicates, autoGeneratedId); | ||
Tuple<DocumentMapper, Boolean> docMapper = mapperService.documentMapperWithAutoCreate(source.type()); | ||
ParsedDocument doc = docMapper.v1().parse(source); | ||
if (docMapper.v2()) { | ||
doc.setMappingsModified(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These upper lines are duplicated in 3 methods, would it make sense to extract the logic to a helper method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
return new Engine.Create(docMapper.v1(), docMapper.v1().uidMapper().term(doc.uid().stringValue()), doc, version, versionType, origin, startTime, state != IndexShardState.STARTED || canHaveDuplicates, autoGeneratedId); | ||
} | ||
|
||
@Override | ||
|
@@ -390,9 +394,12 @@ public ParsedDocument create(Engine.Create create) throws ElasticsearchException | |
@Override | ||
public Engine.Index prepareIndex(SourceToParse source, long version, VersionType versionType, Engine.Operation.Origin origin, boolean canHaveDuplicates) throws ElasticsearchException { | ||
long startTime = System.nanoTime(); | ||
DocumentMapper docMapper = mapperService.documentMapperWithAutoCreate(source.type()); | ||
ParsedDocument doc = docMapper.parse(source); | ||
return new Engine.Index(docMapper, docMapper.uidMapper().term(doc.uid().stringValue()), doc, version, versionType, origin, startTime, state != IndexShardState.STARTED || canHaveDuplicates); | ||
Tuple<DocumentMapper, Boolean> docMapper = mapperService.documentMapperWithAutoCreate(source.type()); | ||
ParsedDocument doc = docMapper.v1().parse(source); | ||
if (docMapper.v2()) { | ||
doc.setMappingsModified(); | ||
} | ||
return new Engine.Index(docMapper.v1(), docMapper.v1().uidMapper().term(doc.uid().stringValue()), doc, version, versionType, origin, startTime, state != IndexShardState.STARTED || canHaveDuplicates); | ||
} | ||
|
||
@Override | ||
|
@@ -416,7 +423,7 @@ public ParsedDocument index(Engine.Index index) throws ElasticsearchException { | |
@Override | ||
public Engine.Delete prepareDelete(String type, String id, long version, VersionType versionType, Engine.Operation.Origin origin) throws ElasticsearchException { | ||
long startTime = System.nanoTime(); | ||
DocumentMapper docMapper = mapperService.documentMapperWithAutoCreate(type); | ||
DocumentMapper docMapper = mapperService.documentMapperWithAutoCreate(type).v1(); | ||
return new Engine.Delete(type, id, docMapper.uidMapper().term(type, id), version, versionType, origin, startTime, false); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,31 +19,35 @@ | |
|
||
package org.elasticsearch.index.fielddata; | ||
|
||
import com.google.common.base.Predicate; | ||
import org.elasticsearch.action.search.SearchPhaseExecutionException; | ||
import org.elasticsearch.action.search.SearchResponse; | ||
import org.elasticsearch.common.settings.ImmutableSettings; | ||
import org.elasticsearch.common.xcontent.XContentFactory; | ||
import org.elasticsearch.index.mapper.MapperService.SmartNameFieldMappers; | ||
import org.elasticsearch.index.service.IndexService; | ||
import org.elasticsearch.indices.IndicesService; | ||
import org.elasticsearch.search.aggregations.AggregationBuilders; | ||
import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode; | ||
import org.elasticsearch.test.ElasticsearchIntegrationTest; | ||
import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope; | ||
|
||
import java.util.Set; | ||
|
||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFailures; | ||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; | ||
|
||
@ClusterScope(randomDynamicTemplates = false) | ||
public class DisabledFieldDataFormatTests extends ElasticsearchIntegrationTest { | ||
|
||
@Override | ||
protected int numberOfReplicas() { | ||
return 0; | ||
} | ||
|
||
public void test() throws Exception { | ||
createIndex("test"); | ||
prepareCreate("test").addMapping("type", "s", "type=string").execute().actionGet(); | ||
ensureGreen(); | ||
logger.info("indexing data start"); | ||
for (int i = 0; i < 10; ++i) { | ||
client().prepareIndex("test", "type", Integer.toString(i)).setSource("s", "value" + i).execute().actionGet(); | ||
} | ||
logger.info("indexing data end"); | ||
|
||
refresh(); | ||
|
||
|
@@ -89,19 +93,55 @@ public void test() throws Exception { | |
} | ||
} | ||
|
||
private void updateFormat(String format) throws Exception { | ||
private void updateFormat(final String format) throws Exception { | ||
logger.info(">> put mapping start {}", format); | ||
client().admin().indices().preparePutMapping("test").setType("type").setSource( | ||
XContentFactory.jsonBuilder().startObject().startObject("type") | ||
.startObject("properties") | ||
.startObject("properties") | ||
.startObject("s") | ||
.field("type", "string") | ||
.startObject("fielddata") | ||
.field("format", format) | ||
.endObject() | ||
.endObject() | ||
.endObject() | ||
.field("type", "string") | ||
.startObject("fielddata") | ||
.field("format", format) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you keep the formatting? I tend to find it easier to read when formatted |
||
.endObject() | ||
.endObject() | ||
.endObject()).execute().actionGet(); | ||
.endObject() | ||
.endObject() | ||
.endObject()).execute().actionGet(); | ||
logger.info(">> put mapping end {}", format); | ||
boolean applied = awaitBusy(new Predicate<Object>() { | ||
@Override | ||
public boolean apply(Object input) { | ||
try { | ||
Set<String> nodes = internalCluster().nodesInclude("test"); | ||
if (nodes.isEmpty()) { // we expect at least one node to hold an index, so wait if not allocated yet | ||
return false; | ||
} | ||
for (String node : nodes) { | ||
IndicesService indicesService = internalCluster().getInstance(IndicesService.class, node); | ||
IndexService indexService = indicesService.indexService("test"); | ||
if (indexService == null) { | ||
return false; | ||
} | ||
final SmartNameFieldMappers mappers = indexService.mapperService().smartName("s"); | ||
if (mappers == null || !mappers.hasMapper()) { | ||
return false; | ||
} | ||
final String currentFormat = mappers.mapper().fieldDataType().getFormat(ImmutableSettings.EMPTY); | ||
if (!format.equals(currentFormat)) { | ||
return false; | ||
} | ||
} | ||
} catch (Exception e) { | ||
logger.info("got exception waiting for concrete mappings", e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to fail the test if we get an exception here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think returning false and logging it is good enough |
||
return false; | ||
} | ||
return true; | ||
} | ||
}); | ||
logger.info(">> put mapping verified {}, applies {}", format, applied); | ||
if (!applied) { | ||
fail(); | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add quick documentation of what the boolean in the tuple means?