Search in sources :

Example 1 with LiveIndexWriterConfig

use of org.apache.lucene.index.LiveIndexWriterConfig in project elasticsearch by elastic.

the class InternalEngineTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    CodecService codecService = new CodecService(null, logger);
    String name = Codec.getDefault().getName();
    if (Arrays.asList(codecService.availableCodecs()).contains(name)) {
        // some codecs are read only so we only take the ones that we have in the service and randomly
        // selected by lucene test case.
        codecName = name;
    } else {
        codecName = "default";
    }
    defaultSettings = IndexSettingsModule.newIndexSettings("test", Settings.builder().put(IndexSettings.INDEX_GC_DELETES_SETTING.getKey(), // make sure this doesn't kick in on us
    "1h").put(EngineConfig.INDEX_CODEC_SETTING.getKey(), codecName).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexSettings.MAX_REFRESH_LISTENERS_PER_SHARD.getKey(), between(10, 10 * IndexSettings.MAX_REFRESH_LISTENERS_PER_SHARD.get(Settings.EMPTY))).build());
    threadPool = new TestThreadPool(getClass().getName());
    store = createStore();
    storeReplica = createStore();
    Lucene.cleanLuceneIndex(store.directory());
    Lucene.cleanLuceneIndex(storeReplica.directory());
    primaryTranslogDir = createTempDir("translog-primary");
    engine = createEngine(store, primaryTranslogDir);
    LiveIndexWriterConfig currentIndexWriterConfig = engine.getCurrentIndexWriterConfig();
    assertEquals(engine.config().getCodec().getName(), codecService.codec(codecName).getName());
    assertEquals(currentIndexWriterConfig.getCodec().getName(), codecService.codec(codecName).getName());
    if (randomBoolean()) {
        engine.config().setEnableGcDeletes(false);
    }
    replicaTranslogDir = createTempDir("translog-replica");
    replicaEngine = createEngine(storeReplica, replicaTranslogDir);
    currentIndexWriterConfig = replicaEngine.getCurrentIndexWriterConfig();
    assertEquals(replicaEngine.config().getCodec().getName(), codecService.codec(codecName).getName());
    assertEquals(currentIndexWriterConfig.getCodec().getName(), codecService.codec(codecName).getName());
    if (randomBoolean()) {
        engine.config().setEnableGcDeletes(false);
    }
}
Also used : LiveIndexWriterConfig(org.apache.lucene.index.LiveIndexWriterConfig) CodecService(org.elasticsearch.index.codec.CodecService) Matchers.containsString(org.hamcrest.Matchers.containsString) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Before(org.junit.Before)

Example 2 with LiveIndexWriterConfig

use of org.apache.lucene.index.LiveIndexWriterConfig in project elasticsearch by elastic.

the class InternalEngineSettingsTests method testSettingsUpdate.

public void testSettingsUpdate() {
    final IndexService service = createIndex("foo");
    InternalEngine engine = ((InternalEngine) EngineAccess.engine(service.getShardOrNull(0)));
    assertThat(engine.getCurrentIndexWriterConfig().getUseCompoundFile(), is(true));
    final int iters = between(1, 20);
    for (int i = 0; i < iters; i++) {
        // Tricky: TimeValue.parseTimeValue casts this long to a double, which steals 11 of the 64 bits for exponent, so we can't use
        // the full long range here else the assert below fails:
        long gcDeletes = random().nextLong() & (Long.MAX_VALUE >> 11);
        Settings build = Settings.builder().put(IndexSettings.INDEX_GC_DELETES_SETTING.getKey(), gcDeletes, TimeUnit.MILLISECONDS).build();
        assertEquals(gcDeletes, build.getAsTime(IndexSettings.INDEX_GC_DELETES_SETTING.getKey(), null).millis());
        client().admin().indices().prepareUpdateSettings("foo").setSettings(build).get();
        LiveIndexWriterConfig currentIndexWriterConfig = engine.getCurrentIndexWriterConfig();
        assertEquals(currentIndexWriterConfig.getUseCompoundFile(), true);
        assertEquals(engine.config().getIndexSettings().getGcDeletesInMillis(), gcDeletes);
        assertEquals(engine.getGcDeletesInMillis(), gcDeletes);
    }
    Settings settings = Settings.builder().put(IndexSettings.INDEX_GC_DELETES_SETTING.getKey(), 1000, TimeUnit.MILLISECONDS).build();
    client().admin().indices().prepareUpdateSettings("foo").setSettings(settings).get();
    assertEquals(engine.getGcDeletesInMillis(), 1000);
    assertTrue(engine.config().isEnableGcDeletes());
    settings = Settings.builder().put(IndexSettings.INDEX_GC_DELETES_SETTING.getKey(), "0ms").build();
    client().admin().indices().prepareUpdateSettings("foo").setSettings(settings).get();
    assertEquals(engine.getGcDeletesInMillis(), 0);
    assertTrue(engine.config().isEnableGcDeletes());
    settings = Settings.builder().put(IndexSettings.INDEX_GC_DELETES_SETTING.getKey(), 1000, TimeUnit.MILLISECONDS).build();
    client().admin().indices().prepareUpdateSettings("foo").setSettings(settings).get();
    assertEquals(engine.getGcDeletesInMillis(), 1000);
    assertTrue(engine.config().isEnableGcDeletes());
}
Also used : LiveIndexWriterConfig(org.apache.lucene.index.LiveIndexWriterConfig) IndexService(org.elasticsearch.index.IndexService) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 3 with LiveIndexWriterConfig

use of org.apache.lucene.index.LiveIndexWriterConfig in project elasticsearch by elastic.

the class InternalEngineTests method testSettings.

public void testSettings() {
    CodecService codecService = new CodecService(null, logger);
    LiveIndexWriterConfig currentIndexWriterConfig = engine.getCurrentIndexWriterConfig();
    assertEquals(engine.config().getCodec().getName(), codecService.codec(codecName).getName());
    assertEquals(currentIndexWriterConfig.getCodec().getName(), codecService.codec(codecName).getName());
}
Also used : LiveIndexWriterConfig(org.apache.lucene.index.LiveIndexWriterConfig) CodecService(org.elasticsearch.index.codec.CodecService)

Example 4 with LiveIndexWriterConfig

use of org.apache.lucene.index.LiveIndexWriterConfig in project elasticsearch by elastic.

the class ShadowEngineTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    CodecService codecService = new CodecService(null, logger);
    String name = Codec.getDefault().getName();
    if (Arrays.asList(codecService.availableCodecs()).contains(name)) {
        // some codecs are read only so we only take the ones that we have in the service and randomly
        // selected by lucene test case.
        codecName = name;
    } else {
        codecName = "default";
    }
    defaultSettings = IndexSettingsModule.newIndexSettings("test", Settings.builder().put(IndexSettings.INDEX_GC_DELETES_SETTING, // make sure this doesn't kick in on us
    "1h").put(EngineConfig.INDEX_CODEC_SETTING.getKey(), codecName).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build());
    threadPool = new TestThreadPool(getClass().getName());
    dirPath = createTempDir();
    store = createStore(dirPath);
    storeReplica = createStore(dirPath);
    Lucene.cleanLuceneIndex(store.directory());
    Lucene.cleanLuceneIndex(storeReplica.directory());
    primaryEngine = createInternalEngine(store, createTempDir("translog-primary"));
    LiveIndexWriterConfig currentIndexWriterConfig = ((InternalEngine) primaryEngine).getCurrentIndexWriterConfig();
    assertEquals(primaryEngine.config().getCodec().getName(), codecService.codec(codecName).getName());
    assertEquals(currentIndexWriterConfig.getCodec().getName(), codecService.codec(codecName).getName());
    if (randomBoolean()) {
        primaryEngine.config().setEnableGcDeletes(false);
    }
    replicaEngine = createShadowEngine(storeReplica);
    assertEquals(replicaEngine.config().getCodec().getName(), codecService.codec(codecName).getName());
    if (randomBoolean()) {
        replicaEngine.config().setEnableGcDeletes(false);
    }
}
Also used : LiveIndexWriterConfig(org.apache.lucene.index.LiveIndexWriterConfig) CodecService(org.elasticsearch.index.codec.CodecService) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Before(org.junit.Before)

Example 5 with LiveIndexWriterConfig

use of org.apache.lucene.index.LiveIndexWriterConfig in project crate by crate.

the class EngineTestCase method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    primaryTerm.set(randomLongBetween(1, Long.MAX_VALUE));
    CodecService codecService = new CodecService(null, logger);
    String name = Codec.getDefault().getName();
    if (Arrays.asList(codecService.availableCodecs()).contains(name)) {
        // some codecs are read only so we only take the ones that we have in the service and randomly
        // selected by lucene test case.
        codecName = name;
    } else {
        codecName = "default";
    }
    defaultSettings = IndexSettingsModule.newIndexSettings("test", indexSettings());
    threadPool = new TestThreadPool(getClass().getName());
    store = createStore();
    storeReplica = createStore();
    Lucene.cleanLuceneIndex(store.directory());
    Lucene.cleanLuceneIndex(storeReplica.directory());
    primaryTranslogDir = createTempDir("translog-primary");
    translogHandler = createTranslogHandler(defaultSettings);
    engine = createEngine(store, primaryTranslogDir);
    LiveIndexWriterConfig currentIndexWriterConfig = engine.getCurrentIndexWriterConfig();
    assertEquals(engine.config().getCodec().getName(), codecService.codec(codecName).getName());
    assertEquals(currentIndexWriterConfig.getCodec().getName(), codecService.codec(codecName).getName());
    if (randomBoolean()) {
        engine.config().setEnableGcDeletes(false);
    }
    replicaTranslogDir = createTempDir("translog-replica");
    replicaEngine = createEngine(storeReplica, replicaTranslogDir);
    currentIndexWriterConfig = replicaEngine.getCurrentIndexWriterConfig();
    assertEquals(replicaEngine.config().getCodec().getName(), codecService.codec(codecName).getName());
    assertEquals(currentIndexWriterConfig.getCodec().getName(), codecService.codec(codecName).getName());
    if (randomBoolean()) {
        engine.config().setEnableGcDeletes(false);
    }
}
Also used : LiveIndexWriterConfig(org.apache.lucene.index.LiveIndexWriterConfig) CodecService(org.elasticsearch.index.codec.CodecService) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Before(org.junit.Before)

Aggregations

LiveIndexWriterConfig (org.apache.lucene.index.LiveIndexWriterConfig)7 CodecService (org.elasticsearch.index.codec.CodecService)5 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)3 Before (org.junit.Before)3 Test (org.junit.Test)2 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1 File (java.io.File)1 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)1 IndexWriter (org.apache.lucene.index.IndexWriter)1 RAMDirectory (org.apache.lucene.store.RAMDirectory)1 Settings (org.elasticsearch.common.settings.Settings)1 IndexService (org.elasticsearch.index.IndexService)1 IndexSettings (org.elasticsearch.index.IndexSettings)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1