Search in sources :

Example 16 with IndexService

use of org.opensearch.index.IndexService in project OpenSearch by opensearch-project.

the class GlobalCheckpointSyncIT method testPersistGlobalCheckpoint.

public void testPersistGlobalCheckpoint() throws Exception {
    internalCluster().ensureAtLeastNumDataNodes(2);
    Settings.Builder indexSettings = Settings.builder().put(IndexService.GLOBAL_CHECKPOINT_SYNC_INTERVAL_SETTING.getKey(), randomTimeValue(100, 1000, "ms")).put("index.number_of_replicas", randomIntBetween(0, 1));
    if (randomBoolean()) {
        indexSettings.put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.ASYNC).put(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey(), randomTimeValue(100, 1000, "ms"));
    }
    prepareCreate("test", indexSettings).get();
    if (randomBoolean()) {
        ensureGreen("test");
    }
    int numDocs = randomIntBetween(1, 20);
    for (int i = 0; i < numDocs; i++) {
        client().prepareIndex("test").setId(Integer.toString(i)).setSource("{}", XContentType.JSON).get();
    }
    ensureGreen("test");
    assertBusy(() -> {
        for (IndicesService indicesService : internalCluster().getDataNodeInstances(IndicesService.class)) {
            for (IndexService indexService : indicesService) {
                for (IndexShard shard : indexService) {
                    final SeqNoStats seqNoStats = shard.seqNoStats();
                    assertThat(seqNoStats.getLocalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo()));
                    assertThat(shard.getLastKnownGlobalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo()));
                    assertThat(shard.getLastSyncedGlobalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo()));
                }
            }
        }
    });
}
Also used : IndexService(org.opensearch.index.IndexService) IndexShard(org.opensearch.index.shard.IndexShard) IndicesService(org.opensearch.indices.IndicesService) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings)

Example 17 with IndexService

use of org.opensearch.index.IndexService in project OpenSearch by opensearch-project.

the class GlobalCheckpointSyncIT method testPersistLocalCheckpoint.

public void testPersistLocalCheckpoint() {
    internalCluster().ensureAtLeastNumDataNodes(2);
    Settings.Builder indexSettings = Settings.builder().put(IndexService.GLOBAL_CHECKPOINT_SYNC_INTERVAL_SETTING.getKey(), "10m").put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.REQUEST).put("index.number_of_shards", 1).put("index.number_of_replicas", randomIntBetween(0, 1));
    prepareCreate("test", indexSettings).get();
    ensureGreen("test");
    int numDocs = randomIntBetween(1, 20);
    logger.info("numDocs {}", numDocs);
    long maxSeqNo = 0;
    for (int i = 0; i < numDocs; i++) {
        maxSeqNo = client().prepareIndex("test").setId(Integer.toString(i)).setSource("{}", XContentType.JSON).get().getSeqNo();
        logger.info("got {}", maxSeqNo);
    }
    for (IndicesService indicesService : internalCluster().getDataNodeInstances(IndicesService.class)) {
        for (IndexService indexService : indicesService) {
            for (IndexShard shard : indexService) {
                final SeqNoStats seqNoStats = shard.seqNoStats();
                assertThat(maxSeqNo, equalTo(seqNoStats.getMaxSeqNo()));
                assertThat(seqNoStats.getLocalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo()));
                ;
            }
        }
    }
}
Also used : IndexService(org.opensearch.index.IndexService) IndexShard(org.opensearch.index.shard.IndexShard) IndicesService(org.opensearch.indices.IndicesService) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings)

Example 18 with IndexService

use of org.opensearch.index.IndexService in project OpenSearch by opensearch-project.

the class TransportClusterStatsAction method nodeOperation.

@Override
protected ClusterStatsNodeResponse nodeOperation(ClusterStatsNodeRequest nodeRequest) {
    NodeInfo nodeInfo = nodeService.info(true, true, false, true, false, true, false, true, false, false, false);
    NodeStats nodeStats = nodeService.stats(CommonStatsFlags.NONE, true, true, true, false, true, false, false, false, false, false, true, false, false, false, false);
    List<ShardStats> shardsStats = new ArrayList<>();
    for (IndexService indexService : indicesService) {
        for (IndexShard indexShard : indexService) {
            if (indexShard.routingEntry() != null && indexShard.routingEntry().active()) {
                // only report on fully started shards
                CommitStats commitStats;
                SeqNoStats seqNoStats;
                RetentionLeaseStats retentionLeaseStats;
                try {
                    commitStats = indexShard.commitStats();
                    seqNoStats = indexShard.seqNoStats();
                    retentionLeaseStats = indexShard.getRetentionLeaseStats();
                } catch (final AlreadyClosedException e) {
                    // shard is closed - no stats is fine
                    commitStats = null;
                    seqNoStats = null;
                    retentionLeaseStats = null;
                }
                shardsStats.add(new ShardStats(indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indicesService.getIndicesQueryCache(), indexShard, SHARD_STATS_FLAGS), commitStats, seqNoStats, retentionLeaseStats));
            }
        }
    }
    ClusterHealthStatus clusterStatus = null;
    if (clusterService.state().nodes().isLocalNodeElectedMaster()) {
        clusterStatus = new ClusterStateHealth(clusterService.state()).getStatus();
    }
    return new ClusterStatsNodeResponse(nodeInfo.getNode(), clusterStatus, nodeInfo, nodeStats, shardsStats.toArray(new ShardStats[shardsStats.size()]));
}
Also used : ShardStats(org.opensearch.action.admin.indices.stats.ShardStats) ClusterStateHealth(org.opensearch.cluster.health.ClusterStateHealth) IndexService(org.opensearch.index.IndexService) IndexShard(org.opensearch.index.shard.IndexShard) RetentionLeaseStats(org.opensearch.index.seqno.RetentionLeaseStats) ArrayList(java.util.ArrayList) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) ClusterHealthStatus(org.opensearch.cluster.health.ClusterHealthStatus) NodeStats(org.opensearch.action.admin.cluster.node.stats.NodeStats) CommonStats(org.opensearch.action.admin.indices.stats.CommonStats) SeqNoStats(org.opensearch.index.seqno.SeqNoStats) NodeInfo(org.opensearch.action.admin.cluster.node.info.NodeInfo) CommitStats(org.opensearch.index.engine.CommitStats)

Example 19 with IndexService

use of org.opensearch.index.IndexService in project OpenSearch by opensearch-project.

the class TransportExplainAction method asyncShardOperation.

@Override
protected void asyncShardOperation(ExplainRequest request, ShardId shardId, ActionListener<ExplainResponse> listener) throws IOException {
    IndexService indexService = searchService.getIndicesService().indexServiceSafe(shardId.getIndex());
    IndexShard indexShard = indexService.getShard(shardId.id());
    indexShard.awaitShardSearchActive(b -> {
        try {
            super.asyncShardOperation(request, shardId, listener);
        } catch (Exception ex) {
            listener.onFailure(ex);
        }
    });
}
Also used : IndexService(org.opensearch.index.IndexService) IndexShard(org.opensearch.index.shard.IndexShard) RoutingMissingException(org.opensearch.action.RoutingMissingException) OpenSearchException(org.opensearch.OpenSearchException) IOException(java.io.IOException)

Example 20 with IndexService

use of org.opensearch.index.IndexService in project OpenSearch by opensearch-project.

the class TransportUpgradeStatusAction method shardOperation.

@Override
protected ShardUpgradeStatus shardOperation(UpgradeStatusRequest request, ShardRouting shardRouting) {
    IndexService indexService = indicesService.indexServiceSafe(shardRouting.shardId().getIndex());
    IndexShard indexShard = indexService.getShard(shardRouting.shardId().id());
    List<Segment> segments = indexShard.segments(false);
    long total_bytes = 0;
    long to_upgrade_bytes = 0;
    long to_upgrade_bytes_ancient = 0;
    for (Segment seg : segments) {
        total_bytes += seg.sizeInBytes;
        if (seg.version.major != Version.CURRENT.luceneVersion.major) {
            to_upgrade_bytes_ancient += seg.sizeInBytes;
            to_upgrade_bytes += seg.sizeInBytes;
        } else if (seg.version.minor != Version.CURRENT.luceneVersion.minor) {
            // TODO: this comparison is bogus! it would cause us to upgrade even with the same format
            // instead, we should check if the codec has changed
            to_upgrade_bytes += seg.sizeInBytes;
        }
    }
    return new ShardUpgradeStatus(indexShard.routingEntry(), total_bytes, to_upgrade_bytes, to_upgrade_bytes_ancient);
}
Also used : IndexService(org.opensearch.index.IndexService) IndexShard(org.opensearch.index.shard.IndexShard) Segment(org.opensearch.index.engine.Segment)

Aggregations

IndexService (org.opensearch.index.IndexService)201 IndexShard (org.opensearch.index.shard.IndexShard)81 IndicesService (org.opensearch.indices.IndicesService)72 Settings (org.opensearch.common.settings.Settings)42 IndexSettings (org.opensearch.index.IndexSettings)37 ShardId (org.opensearch.index.shard.ShardId)34 Matchers.containsString (org.hamcrest.Matchers.containsString)29 Engine (org.opensearch.index.engine.Engine)29 IOException (java.io.IOException)28 Index (org.opensearch.index.Index)28 CompressedXContent (org.opensearch.common.compress.CompressedXContent)27 QueryShardContext (org.opensearch.index.query.QueryShardContext)21 ClusterService (org.opensearch.cluster.service.ClusterService)20 ActionListener (org.opensearch.action.ActionListener)17 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)17 CountDownLatch (java.util.concurrent.CountDownLatch)14 ShardRouting (org.opensearch.cluster.routing.ShardRouting)14 TimeValue (org.opensearch.common.unit.TimeValue)14 DocumentMapper (org.opensearch.index.mapper.DocumentMapper)14 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)13