[TEST] Use NoMergePolicy in EngineTest#testSegments
These tests rely on that there are no merges but since MP is now random this can break the test.
This commit is contained in:
parent
58ccb39dee
commit
0ac09fde95
|
@ -262,121 +262,125 @@ public class InternalEngineTests extends ElasticsearchTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSegments() throws Exception {
|
public void testSegments() throws Exception {
|
||||||
List<Segment> segments = engine.segments(false);
|
IndexSettingsService indexSettingsService = new IndexSettingsService(shardId.index(), Settings.builder().put(defaultSettings).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build());
|
||||||
assertThat(segments.isEmpty(), equalTo(true));
|
try (Store store = createStore();
|
||||||
assertThat(engine.segmentsStats().getCount(), equalTo(0l));
|
Engine engine = createEngine(indexSettingsService, store, createTempDir(), new MergeSchedulerConfig(defaultSettings), NoMergePolicy.INSTANCE)) {
|
||||||
assertThat(engine.segmentsStats().getMemoryInBytes(), equalTo(0l));
|
List<Segment> segments = engine.segments(false);
|
||||||
final boolean defaultCompound = defaultSettings.getAsBoolean(EngineConfig.INDEX_COMPOUND_ON_FLUSH, true);
|
assertThat(segments.isEmpty(), equalTo(true));
|
||||||
|
assertThat(engine.segmentsStats().getCount(), equalTo(0l));
|
||||||
|
assertThat(engine.segmentsStats().getMemoryInBytes(), equalTo(0l));
|
||||||
|
final boolean defaultCompound = defaultSettings.getAsBoolean(EngineConfig.INDEX_COMPOUND_ON_FLUSH, true);
|
||||||
|
|
||||||
// create a doc and refresh
|
// create a doc and refresh
|
||||||
ParsedDocument doc = testParsedDocument("1", "1", "test", null, -1, -1, testDocumentWithTextField(), B_1, null);
|
ParsedDocument doc = testParsedDocument("1", "1", "test", null, -1, -1, testDocumentWithTextField(), B_1, null);
|
||||||
engine.create(new Engine.Create(null, newUid("1"), doc));
|
engine.create(new Engine.Create(null, newUid("1"), doc));
|
||||||
|
|
||||||
ParsedDocument doc2 = testParsedDocument("2", "2", "test", null, -1, -1, testDocumentWithTextField(), B_2, null);
|
ParsedDocument doc2 = testParsedDocument("2", "2", "test", null, -1, -1, testDocumentWithTextField(), B_2, null);
|
||||||
engine.create(new Engine.Create(null, newUid("2"), doc2));
|
engine.create(new Engine.Create(null, newUid("2"), doc2));
|
||||||
engine.refresh("test");
|
engine.refresh("test");
|
||||||
|
|
||||||
segments = engine.segments(false);
|
segments = engine.segments(false);
|
||||||
assertThat(segments.size(), equalTo(1));
|
assertThat(segments.size(), equalTo(1));
|
||||||
SegmentsStats stats = engine.segmentsStats();
|
SegmentsStats stats = engine.segmentsStats();
|
||||||
assertThat(stats.getCount(), equalTo(1l));
|
assertThat(stats.getCount(), equalTo(1l));
|
||||||
assertThat(stats.getTermsMemoryInBytes(), greaterThan(0l));
|
assertThat(stats.getTermsMemoryInBytes(), greaterThan(0l));
|
||||||
assertThat(stats.getStoredFieldsMemoryInBytes(), greaterThan(0l));
|
assertThat(stats.getStoredFieldsMemoryInBytes(), greaterThan(0l));
|
||||||
assertThat(stats.getTermVectorsMemoryInBytes(), equalTo(0l));
|
assertThat(stats.getTermVectorsMemoryInBytes(), equalTo(0l));
|
||||||
assertThat(stats.getNormsMemoryInBytes(), greaterThan(0l));
|
assertThat(stats.getNormsMemoryInBytes(), greaterThan(0l));
|
||||||
assertThat(stats.getDocValuesMemoryInBytes(), greaterThan(0l));
|
assertThat(stats.getDocValuesMemoryInBytes(), greaterThan(0l));
|
||||||
assertThat(segments.get(0).isCommitted(), equalTo(false));
|
assertThat(segments.get(0).isCommitted(), equalTo(false));
|
||||||
assertThat(segments.get(0).isSearch(), equalTo(true));
|
assertThat(segments.get(0).isSearch(), equalTo(true));
|
||||||
assertThat(segments.get(0).getNumDocs(), equalTo(2));
|
assertThat(segments.get(0).getNumDocs(), equalTo(2));
|
||||||
assertThat(segments.get(0).getDeletedDocs(), equalTo(0));
|
assertThat(segments.get(0).getDeletedDocs(), equalTo(0));
|
||||||
assertThat(segments.get(0).isCompound(), equalTo(defaultCompound));
|
assertThat(segments.get(0).isCompound(), equalTo(defaultCompound));
|
||||||
assertThat(segments.get(0).ramTree, nullValue());
|
assertThat(segments.get(0).ramTree, nullValue());
|
||||||
|
|
||||||
engine.flush();
|
engine.flush();
|
||||||
|
|
||||||
segments = engine.segments(false);
|
segments = engine.segments(false);
|
||||||
assertThat(segments.size(), equalTo(1));
|
assertThat(segments.size(), equalTo(1));
|
||||||
assertThat(engine.segmentsStats().getCount(), equalTo(1l));
|
assertThat(engine.segmentsStats().getCount(), equalTo(1l));
|
||||||
assertThat(segments.get(0).isCommitted(), equalTo(true));
|
assertThat(segments.get(0).isCommitted(), equalTo(true));
|
||||||
assertThat(segments.get(0).isSearch(), equalTo(true));
|
assertThat(segments.get(0).isSearch(), equalTo(true));
|
||||||
assertThat(segments.get(0).getNumDocs(), equalTo(2));
|
assertThat(segments.get(0).getNumDocs(), equalTo(2));
|
||||||
assertThat(segments.get(0).getDeletedDocs(), equalTo(0));
|
assertThat(segments.get(0).getDeletedDocs(), equalTo(0));
|
||||||
assertThat(segments.get(0).isCompound(), equalTo(defaultCompound));
|
assertThat(segments.get(0).isCompound(), equalTo(defaultCompound));
|
||||||
|
|
||||||
engine.config().setCompoundOnFlush(false);
|
engine.config().setCompoundOnFlush(false);
|
||||||
|
|
||||||
ParsedDocument doc3 = testParsedDocument("3", "3", "test", null, -1, -1, testDocumentWithTextField(), B_3, null);
|
ParsedDocument doc3 = testParsedDocument("3", "3", "test", null, -1, -1, testDocumentWithTextField(), B_3, null);
|
||||||
engine.create(new Engine.Create(null, newUid("3"), doc3));
|
engine.create(new Engine.Create(null, newUid("3"), doc3));
|
||||||
engine.refresh("test");
|
engine.refresh("test");
|
||||||
|
|
||||||
segments = engine.segments(false);
|
segments = engine.segments(false);
|
||||||
assertThat(segments.size(), equalTo(2));
|
assertThat(segments.size(), equalTo(2));
|
||||||
assertThat(engine.segmentsStats().getCount(), equalTo(2l));
|
assertThat(engine.segmentsStats().getCount(), equalTo(2l));
|
||||||
assertThat(engine.segmentsStats().getTermsMemoryInBytes(), greaterThan(stats.getTermsMemoryInBytes()));
|
assertThat(engine.segmentsStats().getTermsMemoryInBytes(), greaterThan(stats.getTermsMemoryInBytes()));
|
||||||
assertThat(engine.segmentsStats().getStoredFieldsMemoryInBytes(), greaterThan(stats.getStoredFieldsMemoryInBytes()));
|
assertThat(engine.segmentsStats().getStoredFieldsMemoryInBytes(), greaterThan(stats.getStoredFieldsMemoryInBytes()));
|
||||||
assertThat(engine.segmentsStats().getTermVectorsMemoryInBytes(), equalTo(0l));
|
assertThat(engine.segmentsStats().getTermVectorsMemoryInBytes(), equalTo(0l));
|
||||||
assertThat(engine.segmentsStats().getNormsMemoryInBytes(), greaterThan(stats.getNormsMemoryInBytes()));
|
assertThat(engine.segmentsStats().getNormsMemoryInBytes(), greaterThan(stats.getNormsMemoryInBytes()));
|
||||||
assertThat(engine.segmentsStats().getDocValuesMemoryInBytes(), greaterThan(stats.getDocValuesMemoryInBytes()));
|
assertThat(engine.segmentsStats().getDocValuesMemoryInBytes(), greaterThan(stats.getDocValuesMemoryInBytes()));
|
||||||
assertThat(segments.get(0).getGeneration() < segments.get(1).getGeneration(), equalTo(true));
|
assertThat(segments.get(0).getGeneration() < segments.get(1).getGeneration(), equalTo(true));
|
||||||
assertThat(segments.get(0).isCommitted(), equalTo(true));
|
assertThat(segments.get(0).isCommitted(), equalTo(true));
|
||||||
assertThat(segments.get(0).isSearch(), equalTo(true));
|
assertThat(segments.get(0).isSearch(), equalTo(true));
|
||||||
assertThat(segments.get(0).getNumDocs(), equalTo(2));
|
assertThat(segments.get(0).getNumDocs(), equalTo(2));
|
||||||
assertThat(segments.get(0).getDeletedDocs(), equalTo(0));
|
assertThat(segments.get(0).getDeletedDocs(), equalTo(0));
|
||||||
assertThat(segments.get(0).isCompound(), equalTo(defaultCompound));
|
assertThat(segments.get(0).isCompound(), equalTo(defaultCompound));
|
||||||
|
|
||||||
|
|
||||||
assertThat(segments.get(1).isCommitted(), equalTo(false));
|
assertThat(segments.get(1).isCommitted(), equalTo(false));
|
||||||
assertThat(segments.get(1).isSearch(), equalTo(true));
|
assertThat(segments.get(1).isSearch(), equalTo(true));
|
||||||
assertThat(segments.get(1).getNumDocs(), equalTo(1));
|
assertThat(segments.get(1).getNumDocs(), equalTo(1));
|
||||||
assertThat(segments.get(1).getDeletedDocs(), equalTo(0));
|
assertThat(segments.get(1).getDeletedDocs(), equalTo(0));
|
||||||
assertThat(segments.get(1).isCompound(), equalTo(false));
|
assertThat(segments.get(1).isCompound(), equalTo(false));
|
||||||
|
|
||||||
|
|
||||||
engine.delete(new Engine.Delete("test", "1", newUid("1")));
|
engine.delete(new Engine.Delete("test", "1", newUid("1")));
|
||||||
engine.refresh("test");
|
engine.refresh("test");
|
||||||
|
|
||||||
segments = engine.segments(false);
|
segments = engine.segments(false);
|
||||||
assertThat(segments.size(), equalTo(2));
|
assertThat(segments.size(), equalTo(2));
|
||||||
assertThat(engine.segmentsStats().getCount(), equalTo(2l));
|
assertThat(engine.segmentsStats().getCount(), equalTo(2l));
|
||||||
assertThat(segments.get(0).getGeneration() < segments.get(1).getGeneration(), equalTo(true));
|
assertThat(segments.get(0).getGeneration() < segments.get(1).getGeneration(), equalTo(true));
|
||||||
assertThat(segments.get(0).isCommitted(), equalTo(true));
|
assertThat(segments.get(0).isCommitted(), equalTo(true));
|
||||||
assertThat(segments.get(0).isSearch(), equalTo(true));
|
assertThat(segments.get(0).isSearch(), equalTo(true));
|
||||||
assertThat(segments.get(0).getNumDocs(), equalTo(1));
|
assertThat(segments.get(0).getNumDocs(), equalTo(1));
|
||||||
assertThat(segments.get(0).getDeletedDocs(), equalTo(1));
|
assertThat(segments.get(0).getDeletedDocs(), equalTo(1));
|
||||||
assertThat(segments.get(0).isCompound(), equalTo(defaultCompound));
|
assertThat(segments.get(0).isCompound(), equalTo(defaultCompound));
|
||||||
|
|
||||||
assertThat(segments.get(1).isCommitted(), equalTo(false));
|
assertThat(segments.get(1).isCommitted(), equalTo(false));
|
||||||
assertThat(segments.get(1).isSearch(), equalTo(true));
|
assertThat(segments.get(1).isSearch(), equalTo(true));
|
||||||
assertThat(segments.get(1).getNumDocs(), equalTo(1));
|
assertThat(segments.get(1).getNumDocs(), equalTo(1));
|
||||||
assertThat(segments.get(1).getDeletedDocs(), equalTo(0));
|
assertThat(segments.get(1).getDeletedDocs(), equalTo(0));
|
||||||
assertThat(segments.get(1).isCompound(), equalTo(false));
|
assertThat(segments.get(1).isCompound(), equalTo(false));
|
||||||
|
|
||||||
engine.config().setCompoundOnFlush(true);
|
engine.config().setCompoundOnFlush(true);
|
||||||
ParsedDocument doc4 = testParsedDocument("4", "4", "test", null, -1, -1, testDocumentWithTextField(), B_3, null);
|
ParsedDocument doc4 = testParsedDocument("4", "4", "test", null, -1, -1, testDocumentWithTextField(), B_3, null);
|
||||||
engine.create(new Engine.Create(null, newUid("4"), doc4));
|
engine.create(new Engine.Create(null, newUid("4"), doc4));
|
||||||
engine.refresh("test");
|
engine.refresh("test");
|
||||||
|
|
||||||
segments = engine.segments(false);
|
segments = engine.segments(false);
|
||||||
assertThat(segments.size(), equalTo(3));
|
assertThat(segments.size(), equalTo(3));
|
||||||
assertThat(engine.segmentsStats().getCount(), equalTo(3l));
|
assertThat(engine.segmentsStats().getCount(), equalTo(3l));
|
||||||
assertThat(segments.get(0).getGeneration() < segments.get(1).getGeneration(), equalTo(true));
|
assertThat(segments.get(0).getGeneration() < segments.get(1).getGeneration(), equalTo(true));
|
||||||
assertThat(segments.get(0).isCommitted(), equalTo(true));
|
assertThat(segments.get(0).isCommitted(), equalTo(true));
|
||||||
assertThat(segments.get(0).isSearch(), equalTo(true));
|
assertThat(segments.get(0).isSearch(), equalTo(true));
|
||||||
assertThat(segments.get(0).getNumDocs(), equalTo(1));
|
assertThat(segments.get(0).getNumDocs(), equalTo(1));
|
||||||
assertThat(segments.get(0).getDeletedDocs(), equalTo(1));
|
assertThat(segments.get(0).getDeletedDocs(), equalTo(1));
|
||||||
assertThat(segments.get(0).isCompound(), equalTo(defaultCompound));
|
assertThat(segments.get(0).isCompound(), equalTo(defaultCompound));
|
||||||
|
|
||||||
assertThat(segments.get(1).isCommitted(), equalTo(false));
|
assertThat(segments.get(1).isCommitted(), equalTo(false));
|
||||||
assertThat(segments.get(1).isSearch(), equalTo(true));
|
assertThat(segments.get(1).isSearch(), equalTo(true));
|
||||||
assertThat(segments.get(1).getNumDocs(), equalTo(1));
|
assertThat(segments.get(1).getNumDocs(), equalTo(1));
|
||||||
assertThat(segments.get(1).getDeletedDocs(), equalTo(0));
|
assertThat(segments.get(1).getDeletedDocs(), equalTo(0));
|
||||||
assertThat(segments.get(1).isCompound(), equalTo(false));
|
assertThat(segments.get(1).isCompound(), equalTo(false));
|
||||||
|
|
||||||
assertThat(segments.get(2).isCommitted(), equalTo(false));
|
assertThat(segments.get(2).isCommitted(), equalTo(false));
|
||||||
assertThat(segments.get(2).isSearch(), equalTo(true));
|
assertThat(segments.get(2).isSearch(), equalTo(true));
|
||||||
assertThat(segments.get(2).getNumDocs(), equalTo(1));
|
assertThat(segments.get(2).getNumDocs(), equalTo(1));
|
||||||
assertThat(segments.get(2).getDeletedDocs(), equalTo(0));
|
assertThat(segments.get(2).getDeletedDocs(), equalTo(0));
|
||||||
assertThat(segments.get(2).isCompound(), equalTo(true));
|
assertThat(segments.get(2).isCompound(), equalTo(true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testVerboseSegments() throws Exception {
|
public void testVerboseSegments() throws Exception {
|
||||||
|
|
|
@ -208,18 +208,22 @@ public class ShadowEngineTests extends ElasticsearchTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ShadowEngine createShadowEngine(IndexSettingsService indexSettingsService, Store store) {
|
protected ShadowEngine createShadowEngine(IndexSettingsService indexSettingsService, Store store) {
|
||||||
return new ShadowEngine(config(indexSettingsService, store, null, new MergeSchedulerConfig(indexSettingsService.indexSettings())));
|
return new ShadowEngine(config(indexSettingsService, store, null, new MergeSchedulerConfig(indexSettingsService.indexSettings()), null));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected InternalEngine createInternalEngine(IndexSettingsService indexSettingsService, Store store, Path translogPath) {
|
protected InternalEngine createInternalEngine(IndexSettingsService indexSettingsService, Store store, Path translogPath) {
|
||||||
return new InternalEngine(config(indexSettingsService, store, translogPath, new MergeSchedulerConfig(indexSettingsService.indexSettings())), true);
|
return createInternalEngine(indexSettingsService, store, translogPath, newMergePolicy());
|
||||||
}
|
}
|
||||||
|
|
||||||
public EngineConfig config(IndexSettingsService indexSettingsService, Store store, Path translogPath, MergeSchedulerConfig mergeSchedulerConfig) {
|
protected InternalEngine createInternalEngine(IndexSettingsService indexSettingsService, Store store, Path translogPath, MergePolicy mergePolicy) {
|
||||||
|
return new InternalEngine(config(indexSettingsService, store, translogPath, new MergeSchedulerConfig(indexSettingsService.indexSettings()), mergePolicy), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EngineConfig config(IndexSettingsService indexSettingsService, Store store, Path translogPath, MergeSchedulerConfig mergeSchedulerConfig, MergePolicy mergePolicy) {
|
||||||
IndexWriterConfig iwc = newIndexWriterConfig();
|
IndexWriterConfig iwc = newIndexWriterConfig();
|
||||||
TranslogConfig translogConfig = new TranslogConfig(shardId, translogPath, indexSettingsService.getSettings(), Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, threadPool);
|
TranslogConfig translogConfig = new TranslogConfig(shardId, translogPath, indexSettingsService.getSettings(), Translog.Durabilty.REQUEST, BigArrays.NON_RECYCLING_INSTANCE, threadPool);
|
||||||
EngineConfig config = new EngineConfig(shardId, threadPool, new ShardIndexingService(shardId, EMPTY_SETTINGS, new ShardSlowLogIndexingService(shardId, EMPTY_SETTINGS, indexSettingsService)), indexSettingsService
|
EngineConfig config = new EngineConfig(shardId, threadPool, new ShardIndexingService(shardId, EMPTY_SETTINGS, new ShardSlowLogIndexingService(shardId, EMPTY_SETTINGS, indexSettingsService)), indexSettingsService
|
||||||
, null, store, createSnapshotDeletionPolicy(),newMergePolicy(), mergeSchedulerConfig,
|
, null, store, createSnapshotDeletionPolicy(), mergePolicy, mergeSchedulerConfig,
|
||||||
iwc.getAnalyzer(), iwc.getSimilarity() , new CodecService(shardId.index()), new Engine.FailedEngineListener() {
|
iwc.getAnalyzer(), iwc.getSimilarity() , new CodecService(shardId.index()), new Engine.FailedEngineListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFailedEngine(ShardId shardId, String reason, @Nullable Throwable t) {
|
public void onFailedEngine(ShardId shardId, String reason, @Nullable Throwable t) {
|
||||||
|
@ -264,6 +268,9 @@ public class ShadowEngineTests extends ElasticsearchTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSegments() throws Exception {
|
public void testSegments() throws Exception {
|
||||||
|
IndexSettingsService indexSettingsService = new IndexSettingsService(shardId.index(), Settings.builder().put(defaultSettings).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build());
|
||||||
|
primaryEngine.close(); // recreate without merging
|
||||||
|
primaryEngine = createInternalEngine(indexSettingsService, store, createTempDir(), NoMergePolicy.INSTANCE);
|
||||||
List<Segment> segments = primaryEngine.segments(false);
|
List<Segment> segments = primaryEngine.segments(false);
|
||||||
assertThat(segments.isEmpty(), equalTo(true));
|
assertThat(segments.isEmpty(), equalTo(true));
|
||||||
assertThat(primaryEngine.segmentsStats().getCount(), equalTo(0l));
|
assertThat(primaryEngine.segmentsStats().getCount(), equalTo(0l));
|
||||||
|
|
Loading…
Reference in New Issue