Search in sources :

Example 56 with Settings

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.

the class HunspellServiceTests method testLocaleDirectoryWithNodeLevelConfig.

public void testLocaleDirectoryWithNodeLevelConfig() throws Exception {
    Settings settings = Settings.builder().put(Environment.PATH_CONF_SETTING.getKey(), getDataPath("/indices/analyze/conf_dir")).put(HUNSPELL_LAZY_LOAD.getKey(), randomBoolean()).put(HUNSPELL_IGNORE_CASE.getKey(), true).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).build();
    Dictionary dictionary = new HunspellService(settings, new Environment(settings), emptyMap()).getDictionary("en_US");
    assertThat(dictionary, notNullValue());
    assertTrue(dictionary.getIgnoreCase());
}
Also used : Dictionary(org.apache.lucene.analysis.hunspell.Dictionary) HunspellService(org.elasticsearch.indices.analysis.HunspellService) Environment(org.elasticsearch.env.Environment) Settings(org.elasticsearch.common.settings.Settings)

Example 57 with Settings

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.

the class RecoverySourceHandlerTests method testHandleExceptinoOnSendSendFiles.

public void testHandleExceptinoOnSendSendFiles() throws Throwable {
    Settings settings = Settings.builder().put("indices.recovery.concurrent_streams", 1).put("indices.recovery.concurrent_small_file_streams", 1).build();
    final RecoverySettings recoverySettings = new RecoverySettings(settings, service);
    final StartRecoveryRequest request = new StartRecoveryRequest(shardId, new DiscoveryNode("b", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT), new DiscoveryNode("b", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT), null, randomBoolean(), randomNonNegativeLong(), randomBoolean() ? SequenceNumbersService.UNASSIGNED_SEQ_NO : 0L);
    Path tempDir = createTempDir();
    Store store = newStore(tempDir, false);
    AtomicBoolean failedEngine = new AtomicBoolean(false);
    RecoverySourceHandler handler = new RecoverySourceHandler(null, null, request, () -> 0L, e -> () -> {
    }, recoverySettings.getChunkSize().bytesAsInt(), Settings.EMPTY) {

        @Override
        protected void failEngine(IOException cause) {
            assertFalse(failedEngine.get());
            failedEngine.set(true);
        }
    };
    Directory dir = store.directory();
    RandomIndexWriter writer = new RandomIndexWriter(random(), dir, newIndexWriterConfig());
    int numDocs = randomIntBetween(10, 100);
    for (int i = 0; i < numDocs; i++) {
        Document document = new Document();
        document.add(new StringField("id", Integer.toString(i), Field.Store.YES));
        document.add(newField("field", randomUnicodeOfCodepointLengthBetween(1, 10), TextField.TYPE_STORED));
        writer.addDocument(document);
    }
    writer.commit();
    writer.close();
    Store.MetadataSnapshot metadata = store.getMetadata(null);
    List<StoreFileMetaData> metas = new ArrayList<>();
    for (StoreFileMetaData md : metadata) {
        metas.add(md);
    }
    final boolean throwCorruptedIndexException = randomBoolean();
    Store targetStore = newStore(createTempDir(), false);
    try {
        handler.sendFiles(store, metas.toArray(new StoreFileMetaData[0]), (md) -> {
            if (throwCorruptedIndexException) {
                throw new RuntimeException(new CorruptIndexException("foo", "bar"));
            } else {
                throw new RuntimeException("boom");
            }
        });
        fail("exception index");
    } catch (RuntimeException ex) {
        assertNull(ExceptionsHelper.unwrapCorruption(ex));
        if (throwCorruptedIndexException) {
            assertEquals(ex.getMessage(), "[File corruption occurred on recovery but checksums are ok]");
        } else {
            assertEquals(ex.getMessage(), "boom");
        }
    } catch (CorruptIndexException ex) {
        fail("not expected here");
    }
    assertFalse(failedEngine.get());
    IOUtils.close(store, targetStore);
}
Also used : Path(java.nio.file.Path) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ArrayList(java.util.ArrayList) Store(org.elasticsearch.index.store.Store) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) IOException(java.io.IOException) Document(org.apache.lucene.document.Document) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StoreFileMetaData(org.elasticsearch.index.store.StoreFileMetaData) StringField(org.apache.lucene.document.StringField) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) Directory(org.apache.lucene.store.Directory)

Example 58 with Settings

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.

the class CloseIndexDisableCloseAllIT method afterTest.

@After
public void afterTest() {
    Settings settings = Settings.builder().put(TransportCloseIndexAction.CLUSTER_INDICES_CLOSE_ENABLE_SETTING.getKey(), (String) null).build();
    assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(settings));
}
Also used : Settings(org.elasticsearch.common.settings.Settings) After(org.junit.After)

Example 59 with Settings

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.

the class DedicatedMasterGetFieldMappingIT method before1.

@Before
public void before1() throws Exception {
    Settings settings = Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build();
    internalCluster().startNodes(settings, Settings.EMPTY);
}
Also used : Settings(org.elasticsearch.common.settings.Settings) Before(org.junit.Before)

Example 60 with Settings

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.

the class RestRecoveryActionTests method testRestRecoveryAction.

public void testRestRecoveryAction() {
    final Settings settings = Settings.EMPTY;
    final RestController restController = new RestController(settings, Collections.emptySet(), null, null, null);
    final RestRecoveryAction action = new RestRecoveryAction(settings, restController);
    final int totalShards = randomIntBetween(1, 32);
    final int successfulShards = Math.max(0, totalShards - randomIntBetween(1, 2));
    final int failedShards = totalShards - successfulShards;
    final boolean detailed = randomBoolean();
    final Map<String, List<RecoveryState>> shardRecoveryStates = new HashMap<>();
    final List<RecoveryState> recoveryStates = new ArrayList<>();
    for (int i = 0; i < successfulShards; i++) {
        final RecoveryState state = mock(RecoveryState.class);
        when(state.getShardId()).thenReturn(new ShardId(new Index("index", "_na_"), i));
        final RecoveryState.Timer timer = mock(RecoveryState.Timer.class);
        when(timer.time()).thenReturn((long) randomIntBetween(1000000, 10 * 1000000));
        when(state.getTimer()).thenReturn(timer);
        when(state.getRecoverySource()).thenReturn(TestShardRouting.randomRecoverySource());
        when(state.getStage()).thenReturn(randomFrom(RecoveryState.Stage.values()));
        final DiscoveryNode sourceNode = randomBoolean() ? mock(DiscoveryNode.class) : null;
        if (sourceNode != null) {
            when(sourceNode.getHostName()).thenReturn(randomAsciiOfLength(8));
        }
        when(state.getSourceNode()).thenReturn(sourceNode);
        final DiscoveryNode targetNode = mock(DiscoveryNode.class);
        when(targetNode.getHostName()).thenReturn(randomAsciiOfLength(8));
        when(state.getTargetNode()).thenReturn(targetNode);
        RecoveryState.Index index = mock(RecoveryState.Index.class);
        final int totalRecoveredFiles = randomIntBetween(1, 64);
        when(index.totalRecoverFiles()).thenReturn(totalRecoveredFiles);
        final int recoveredFileCount = randomIntBetween(0, totalRecoveredFiles);
        when(index.recoveredFileCount()).thenReturn(recoveredFileCount);
        when(index.recoveredFilesPercent()).thenReturn((100f * recoveredFileCount) / totalRecoveredFiles);
        when(index.totalFileCount()).thenReturn(randomIntBetween(totalRecoveredFiles, 2 * totalRecoveredFiles));
        final int totalRecoveredBytes = randomIntBetween(1, 1 << 24);
        when(index.totalRecoverBytes()).thenReturn((long) totalRecoveredBytes);
        final int recoveredBytes = randomIntBetween(0, totalRecoveredBytes);
        when(index.recoveredBytes()).thenReturn((long) recoveredBytes);
        when(index.recoveredBytesPercent()).thenReturn((100f * recoveredBytes) / totalRecoveredBytes);
        when(index.totalRecoverBytes()).thenReturn((long) randomIntBetween(totalRecoveredBytes, 2 * totalRecoveredBytes));
        when(state.getIndex()).thenReturn(index);
        final RecoveryState.Translog translog = mock(RecoveryState.Translog.class);
        final int translogOps = randomIntBetween(0, 1 << 18);
        when(translog.totalOperations()).thenReturn(translogOps);
        final int translogOpsRecovered = randomIntBetween(0, translogOps);
        when(translog.recoveredOperations()).thenReturn(translogOpsRecovered);
        when(translog.recoveredPercent()).thenReturn(translogOps == 0 ? 100f : (100f * translogOpsRecovered / translogOps));
        when(state.getTranslog()).thenReturn(translog);
        recoveryStates.add(state);
    }
    final List<RecoveryState> shuffle = new ArrayList<>(recoveryStates);
    Randomness.shuffle(shuffle);
    shardRecoveryStates.put("index", shuffle);
    final List<ShardOperationFailedException> shardFailures = new ArrayList<>();
    final RecoveryResponse response = new RecoveryResponse(totalShards, successfulShards, failedShards, detailed, shardRecoveryStates, shardFailures);
    final Table table = action.buildRecoveryTable(null, response);
    assertNotNull(table);
    List<Table.Cell> headers = table.getHeaders();
    assertThat(headers.get(0).value, equalTo("index"));
    assertThat(headers.get(1).value, equalTo("shard"));
    assertThat(headers.get(2).value, equalTo("time"));
    assertThat(headers.get(3).value, equalTo("type"));
    assertThat(headers.get(4).value, equalTo("stage"));
    assertThat(headers.get(5).value, equalTo("source_host"));
    assertThat(headers.get(6).value, equalTo("source_node"));
    assertThat(headers.get(7).value, equalTo("target_host"));
    assertThat(headers.get(8).value, equalTo("target_node"));
    assertThat(headers.get(9).value, equalTo("repository"));
    assertThat(headers.get(10).value, equalTo("snapshot"));
    assertThat(headers.get(11).value, equalTo("files"));
    assertThat(headers.get(12).value, equalTo("files_recovered"));
    assertThat(headers.get(13).value, equalTo("files_percent"));
    assertThat(headers.get(14).value, equalTo("files_total"));
    assertThat(headers.get(15).value, equalTo("bytes"));
    assertThat(headers.get(16).value, equalTo("bytes_recovered"));
    assertThat(headers.get(17).value, equalTo("bytes_percent"));
    assertThat(headers.get(18).value, equalTo("bytes_total"));
    assertThat(headers.get(19).value, equalTo("translog_ops"));
    assertThat(headers.get(20).value, equalTo("translog_ops_recovered"));
    assertThat(headers.get(21).value, equalTo("translog_ops_percent"));
    assertThat(table.getRows().size(), equalTo(successfulShards));
    for (int i = 0; i < successfulShards; i++) {
        final RecoveryState state = recoveryStates.get(i);
        List<Table.Cell> cells = table.getRows().get(i);
        assertThat(cells.get(0).value, equalTo("index"));
        assertThat(cells.get(1).value, equalTo(i));
        assertThat(cells.get(2).value, equalTo(new TimeValue(state.getTimer().time())));
        assertThat(cells.get(3).value, equalTo(state.getRecoverySource().getType().name().toLowerCase(Locale.ROOT)));
        assertThat(cells.get(4).value, equalTo(state.getStage().name().toLowerCase(Locale.ROOT)));
        assertThat(cells.get(5).value, equalTo(state.getSourceNode() == null ? "n/a" : state.getSourceNode().getHostName()));
        assertThat(cells.get(6).value, equalTo(state.getSourceNode() == null ? "n/a" : state.getSourceNode().getName()));
        assertThat(cells.get(7).value, equalTo(state.getTargetNode().getHostName()));
        assertThat(cells.get(8).value, equalTo(state.getTargetNode().getName()));
        assertThat(cells.get(9).value, equalTo(state.getRecoverySource() == null || state.getRecoverySource().getType() != RecoverySource.Type.SNAPSHOT ? "n/a" : ((SnapshotRecoverySource) state.getRecoverySource()).snapshot().getRepository()));
        assertThat(cells.get(10).value, equalTo(state.getRecoverySource() == null || state.getRecoverySource().getType() != RecoverySource.Type.SNAPSHOT ? "n/a" : ((SnapshotRecoverySource) state.getRecoverySource()).snapshot().getSnapshotId().getName()));
        assertThat(cells.get(11).value, equalTo(state.getIndex().totalRecoverFiles()));
        assertThat(cells.get(12).value, equalTo(state.getIndex().recoveredFileCount()));
        assertThat(cells.get(13).value, equalTo(percent(state.getIndex().recoveredFilesPercent())));
        assertThat(cells.get(14).value, equalTo(state.getIndex().totalFileCount()));
        assertThat(cells.get(15).value, equalTo(state.getIndex().totalRecoverBytes()));
        assertThat(cells.get(16).value, equalTo(state.getIndex().recoveredBytes()));
        assertThat(cells.get(17).value, equalTo(percent(state.getIndex().recoveredBytesPercent())));
        assertThat(cells.get(18).value, equalTo(state.getIndex().totalBytes()));
        assertThat(cells.get(19).value, equalTo(state.getTranslog().totalOperations()));
        assertThat(cells.get(20).value, equalTo(state.getTranslog().recoveredOperations()));
        assertThat(cells.get(21).value, equalTo(percent(state.getTranslog().recoveredPercent())));
    }
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RestController(org.elasticsearch.rest.RestController) Index(org.elasticsearch.index.Index) RecoveryResponse(org.elasticsearch.action.admin.indices.recovery.RecoveryResponse) ShardId(org.elasticsearch.index.shard.ShardId) ArrayList(java.util.ArrayList) List(java.util.List) ShardOperationFailedException(org.elasticsearch.action.ShardOperationFailedException) RecoveryState(org.elasticsearch.indices.recovery.RecoveryState) Settings(org.elasticsearch.common.settings.Settings) TimeValue(org.elasticsearch.common.unit.TimeValue) Table(org.elasticsearch.common.Table) SnapshotRecoverySource(org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource)

Aggregations

Settings (org.elasticsearch.common.settings.Settings)1248 Test (org.junit.Test)197 IndexSettings (org.elasticsearch.index.IndexSettings)167 IOException (java.io.IOException)133 Path (java.nio.file.Path)121 ClusterState (org.elasticsearch.cluster.ClusterState)120 ArrayList (java.util.ArrayList)108 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)106 HashMap (java.util.HashMap)105 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)98 Version (org.elasticsearch.Version)91 Matchers.containsString (org.hamcrest.Matchers.containsString)91 Environment (org.elasticsearch.env.Environment)87 Map (java.util.Map)85 List (java.util.List)79 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)72 Index (org.elasticsearch.index.Index)70 HashSet (java.util.HashSet)58 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)54 ThreadPool (org.elasticsearch.threadpool.ThreadPool)54