Merge pull request #17569 from mikemccand/imc_version_conflict_recovery

NullPointerException from IndexingMemoryController when a version conflict happens during recovery
This commit is contained in:
Michael McCandless 2016-04-06 13:47:00 -04:00
commit 8a9b5ccbc4
2 changed files with 23 additions and 3 deletions

View File

@ -32,6 +32,7 @@ import org.elasticsearch.index.engine.FlushNotAllowedEngineException;
import org.elasticsearch.index.shard.IndexShard;
import org.elasticsearch.index.shard.IndexShardState;
import org.elasticsearch.index.shard.IndexingOperationListener;
import org.elasticsearch.index.translog.Translog;
import org.elasticsearch.monitor.jvm.JvmInfo;
import org.elasticsearch.threadpool.ThreadPool;
@ -89,7 +90,6 @@ public class IndexingMemoryController extends AbstractComponent implements Index
this(settings, threadPool, indexServices, JvmInfo.jvmInfo().getMem().getHeapMax().bytes());
}
// for testing
IndexingMemoryController(Settings settings, ThreadPool threadPool, Iterable<IndexShard> indexServices, long jvmMemoryInBytes) {
super(settings);
this.indexShards = indexServices;
@ -205,12 +205,20 @@ public class IndexingMemoryController extends AbstractComponent implements Index
@Override
public void postIndex(Engine.Index index, boolean created) {
bytesWritten(index.getTranslogLocation().size);
recordOperationBytes(index);
}
@Override
public void postDelete(Engine.Delete delete) {
bytesWritten(delete.getTranslogLocation().size);
recordOperationBytes(delete);
}
private void recordOperationBytes(Engine.Operation op) {
Translog.Location loc = op.getTranslogLocation();
// This can be null on (harmless) version conflict during recovery:
if (loc != null) {
bytesWritten(loc.size);
}
}
private static final class ShardAndBytesUsed implements Comparable<ShardAndBytesUsed> {

View File

@ -347,4 +347,16 @@ public class SimpleQueryStringIT extends ESIntegTestCase {
assertHitCount(searchResponse, 1L);
assertSearchHits(searchResponse, "1");
}
public void testSimpleQueryStringUsesFieldAnalyzer() throws Exception {
client().prepareIndex("test", "type1", "1").setSource("foo", 123, "bar", "abc").get();
client().prepareIndex("test", "type1", "2").setSource("foo", 234, "bar", "bcd").get();
refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(
simpleQueryStringQuery("123").field("foo").field("bar")).get();
assertHitCount(searchResponse, 1L);
assertSearchHits(searchResponse, "1");
}
}