Search in sources :

Example 96 with IndexMetadata

use of org.opensearch.cluster.metadata.IndexMetadata in project OpenSearch by opensearch-project.

the class InternalEngineTests method testStressShouldPeriodicallyFlush.

public void testStressShouldPeriodicallyFlush() throws Exception {
    final long flushThreshold = randomLongBetween(120, 5000);
    final long generationThreshold = randomLongBetween(1000, 5000);
    final IndexSettings indexSettings = engine.config().getIndexSettings();
    final IndexMetadata indexMetadata = IndexMetadata.builder(indexSettings.getIndexMetadata()).settings(Settings.builder().put(indexSettings.getSettings()).put(IndexSettings.INDEX_TRANSLOG_GENERATION_THRESHOLD_SIZE_SETTING.getKey(), generationThreshold + "b").put(IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey(), flushThreshold + "b")).build();
    indexSettings.updateIndexMetadata(indexMetadata);
    engine.onSettingsChanged(indexSettings.getTranslogRetentionAge(), indexSettings.getTranslogRetentionSize(), indexSettings.getSoftDeleteRetentionOperations());
    final int numOps = scaledRandomIntBetween(100, 10_000);
    for (int i = 0; i < numOps; i++) {
        final long localCheckPoint = engine.getProcessedLocalCheckpoint();
        final long seqno = randomLongBetween(Math.max(0, localCheckPoint), localCheckPoint + 5);
        final ParsedDocument doc = testParsedDocument(Long.toString(seqno), null, testDocumentWithTextField(), SOURCE, null);
        engine.index(replicaIndexForDoc(doc, 1L, seqno, false));
        if (rarely() && engine.getTranslog().shouldRollGeneration()) {
            engine.rollTranslogGeneration();
        }
        if (rarely() || engine.shouldPeriodicallyFlush()) {
            engine.flush();
            assertThat(engine.shouldPeriodicallyFlush(), equalTo(false));
        }
    }
}
Also used : ParsedDocument(org.opensearch.index.mapper.ParsedDocument) IndexSettings(org.opensearch.index.IndexSettings) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) LongPoint(org.apache.lucene.document.LongPoint)

Example 97 with IndexMetadata

use of org.opensearch.cluster.metadata.IndexMetadata in project OpenSearch by opensearch-project.

the class EngineConfigFactoryTests method testCreateCodecServiceFromFactory.

public void testCreateCodecServiceFromFactory() {
    IndexMetadata meta = IndexMetadata.builder("test").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1).build();
    List<EnginePlugin> plugins = Arrays.asList(new BakEnginePlugin());
    IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("test", meta.getSettings());
    EngineConfigFactory factory = new EngineConfigFactory(plugins, indexSettings);
    EngineConfig config = factory.newEngineConfig(null, null, indexSettings, null, null, null, null, null, null, null, null, null, null, TimeValue.timeValueMinutes(5), null, null, null, null, null, () -> new RetentionLeases(0, 0, Collections.emptyList()), null, null, false);
    assertNotNull(config.getCodec());
}
Also used : EnginePlugin(org.opensearch.plugins.EnginePlugin) IndexSettings(org.opensearch.index.IndexSettings) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) RetentionLeases(org.opensearch.index.seqno.RetentionLeases)

Example 98 with IndexMetadata

use of org.opensearch.cluster.metadata.IndexMetadata in project OpenSearch by opensearch-project.

the class EngineConfigFactoryTests method testCreateEngineConfigFromFactoryMultipleCustomTranslogDeletionPolicyFactoryIllegalStateException.

public void testCreateEngineConfigFromFactoryMultipleCustomTranslogDeletionPolicyFactoryIllegalStateException() {
    IndexMetadata meta = IndexMetadata.builder("test").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1).build();
    List<EnginePlugin> plugins = Arrays.asList(new FooEnginePlugin(), new BazEnginePlugin());
    IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("test", meta.getSettings());
    expectThrows(IllegalStateException.class, () -> new EngineConfigFactory(plugins, indexSettings));
}
Also used : EnginePlugin(org.opensearch.plugins.EnginePlugin) IndexSettings(org.opensearch.index.IndexSettings) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata)

Example 99 with IndexMetadata

use of org.opensearch.cluster.metadata.IndexMetadata in project OpenSearch by opensearch-project.

the class EngineConfigTests method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    final IndexMetadata defaultIndexMetadata = IndexMetadata.builder("test").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1).build();
    defaultIndexSettings = IndexSettingsModule.newIndexSettings("test", defaultIndexMetadata.getSettings());
}
Also used : IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata)

Example 100 with IndexMetadata

use of org.opensearch.cluster.metadata.IndexMetadata in project OpenSearch by opensearch-project.

the class IndicesLifecycleListenerSingleNodeTests method testStartDeleteIndexEventCallback.

public void testStartDeleteIndexEventCallback() throws Throwable {
    IndicesService indicesService = getInstanceFromNode(IndicesService.class);
    assertAcked(client().admin().indices().prepareCreate("test").setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0)));
    ensureGreen();
    Index idx = resolveIndex("test");
    IndexMetadata metadata = indicesService.indexService(idx).getMetadata();
    ShardRouting shardRouting = indicesService.indexService(idx).getShard(0).routingEntry();
    final AtomicInteger counter = new AtomicInteger(1);
    IndexEventListener countingListener = new IndexEventListener() {

        @Override
        public void beforeIndexCreated(Index index, Settings indexSettings) {
            assertEquals("test", index.getName());
            assertEquals(1, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void afterIndexCreated(IndexService indexService) {
            assertEquals("test", indexService.index().getName());
            assertEquals(2, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void beforeIndexShardCreated(ShardId shardId, Settings indexSettings) {
            assertEquals(3, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void afterIndexShardCreated(IndexShard indexShard) {
            assertEquals(4, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void afterIndexShardStarted(IndexShard indexShard) {
            assertEquals(5, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void beforeIndexRemoved(IndexService indexService, IndexRemovalReason reason) {
            assertEquals(DELETED, reason);
            assertEquals(6, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void beforeIndexShardDeleted(ShardId shardId, Settings indexSettings) {
            assertEquals(7, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void afterIndexShardDeleted(ShardId shardId, Settings indexSettings) {
            assertEquals(8, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void afterIndexRemoved(Index index, IndexSettings indexSettings, IndexRemovalReason reason) {
            assertEquals(DELETED, reason);
            assertEquals(9, counter.get());
            counter.incrementAndGet();
        }
    };
    indicesService.removeIndex(idx, DELETED, "simon says");
    try {
        IndexService index = indicesService.createIndex(metadata, Arrays.asList(countingListener), false);
        assertEquals(3, counter.get());
        idx = index.index();
        ShardRouting newRouting = shardRouting;
        String nodeId = newRouting.currentNodeId();
        UnassignedInfo unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "boom");
        newRouting = newRouting.moveToUnassigned(unassignedInfo).updateUnassigned(unassignedInfo, RecoverySource.EmptyStoreRecoverySource.INSTANCE);
        newRouting = ShardRoutingHelper.initialize(newRouting, nodeId);
        IndexShard shard = index.createShard(newRouting, s -> {
        }, RetentionLeaseSyncer.EMPTY, SegmentReplicationCheckpointPublisher.EMPTY);
        IndexShardTestCase.updateRoutingEntry(shard, newRouting);
        assertEquals(5, counter.get());
        final DiscoveryNode localNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
        shard.markAsRecovering("store", new RecoveryState(newRouting, localNode, null));
        IndexShardTestCase.recoverFromStore(shard);
        newRouting = ShardRoutingHelper.moveToStarted(newRouting);
        IndexShardTestCase.updateRoutingEntry(shard, newRouting);
        assertEquals(6, counter.get());
    } finally {
        indicesService.removeIndex(idx, DELETED, "simon says");
    }
    assertEquals(10, counter.get());
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) IndexService(org.opensearch.index.IndexService) UnassignedInfo(org.opensearch.cluster.routing.UnassignedInfo) IndexShard(org.opensearch.index.shard.IndexShard) IndexSettings(org.opensearch.index.IndexSettings) Index(org.opensearch.index.Index) ShardId(org.opensearch.index.shard.ShardId) IndexEventListener(org.opensearch.index.shard.IndexEventListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IndexRemovalReason(org.opensearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) ShardRouting(org.opensearch.cluster.routing.ShardRouting) RecoveryState(org.opensearch.indices.recovery.RecoveryState) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings)

Aggregations

IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)419 ClusterState (org.opensearch.cluster.ClusterState)149 Settings (org.opensearch.common.settings.Settings)132 Metadata (org.opensearch.cluster.metadata.Metadata)130 IndexSettings (org.opensearch.index.IndexSettings)93 Index (org.opensearch.index.Index)84 ShardRouting (org.opensearch.cluster.routing.ShardRouting)67 ShardId (org.opensearch.index.shard.ShardId)61 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)56 HashSet (java.util.HashSet)53 ArrayList (java.util.ArrayList)52 HashMap (java.util.HashMap)52 IOException (java.io.IOException)51 Matchers.containsString (org.hamcrest.Matchers.containsString)51 IndexShardRoutingTable (org.opensearch.cluster.routing.IndexShardRoutingTable)47 RoutingTable (org.opensearch.cluster.routing.RoutingTable)46 Map (java.util.Map)44 ClusterService (org.opensearch.cluster.service.ClusterService)40 List (java.util.List)39 ActionListener (org.opensearch.action.ActionListener)36