Search in sources :

Example 1 with Node

use of org.opensearch.node.Node in project OpenSearch by opensearch-project.

the class Bootstrap method setup.

private void setup(boolean addShutdownHook, Environment environment) throws BootstrapException {
    Settings settings = environment.settings();
    try {
        spawner.spawnNativeControllers(environment, true);
    } catch (IOException e) {
        throw new BootstrapException(e);
    }
    initializeNatives(environment.tmpFile(), BootstrapSettings.MEMORY_LOCK_SETTING.get(settings), BootstrapSettings.SYSTEM_CALL_FILTER_SETTING.get(settings), BootstrapSettings.CTRLHANDLER_SETTING.get(settings));
    // initialize probes before the security manager is installed
    initializeProbes();
    if (addShutdownHook) {
        Runtime.getRuntime().addShutdownHook(new Thread() {

            @Override
            public void run() {
                try {
                    IOUtils.close(node, spawner);
                    LoggerContext context = (LoggerContext) LogManager.getContext(false);
                    Configurator.shutdown(context);
                    if (node != null && node.awaitClose(10, TimeUnit.SECONDS) == false) {
                        throw new IllegalStateException("Node didn't stop within 10 seconds. " + "Any outstanding requests or tasks might get killed.");
                    }
                } catch (IOException ex) {
                    throw new OpenSearchException("failed to stop node", ex);
                } catch (InterruptedException e) {
                    LogManager.getLogger(Bootstrap.class).warn("Thread got interrupted while waiting for the node to shutdown.");
                    Thread.currentThread().interrupt();
                }
            }
        });
    }
    try {
        // look for jar hell
        final Logger logger = LogManager.getLogger(JarHell.class);
        JarHell.checkJarHell(logger::debug);
    } catch (IOException | URISyntaxException e) {
        throw new BootstrapException(e);
    }
    // Log ifconfig output before SecurityManager is installed
    IfConfig.logIfNecessary();
    // install SM after natives, shutdown hooks, etc.
    try {
        Security.configure(environment, BootstrapSettings.SECURITY_FILTER_BAD_DEFAULTS_SETTING.get(settings));
    } catch (IOException | NoSuchAlgorithmException e) {
        throw new BootstrapException(e);
    }
    node = new Node(environment) {

        @Override
        protected void validateNodeBeforeAcceptingRequests(final BootstrapContext context, final BoundTransportAddress boundTransportAddress, List<BootstrapCheck> checks) throws NodeValidationException {
            BootstrapChecks.check(context, boundTransportAddress, checks);
        }
    };
}
Also used : Node(org.opensearch.node.Node) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) DeprecationLogger(org.opensearch.common.logging.DeprecationLogger) Logger(org.apache.logging.log4j.Logger) LoggerContext(org.apache.logging.log4j.core.LoggerContext) NodeValidationException(org.opensearch.node.NodeValidationException) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) OpenSearchException(org.opensearch.OpenSearchException) Settings(org.opensearch.common.settings.Settings) SecureSettings(org.opensearch.common.settings.SecureSettings)

Example 2 with Node

use of org.opensearch.node.Node in project OpenSearch by opensearch-project.

the class DedicatedClusterSnapshotRestoreIT method testAbortWaitsOnDataNode.

public void testAbortWaitsOnDataNode() throws Exception {
    internalCluster().startMasterOnlyNode();
    final String dataNodeName = internalCluster().startDataOnlyNode();
    final String indexName = "test-index";
    createIndex(indexName);
    index(indexName, "_doc", "some_id", "foo", "bar");
    final String otherDataNode = internalCluster().startDataOnlyNode();
    final String repoName = "test-repo";
    createRepository(repoName, "mock");
    blockAllDataNodes(repoName);
    final String snapshotName = "test-snap";
    final ActionFuture<CreateSnapshotResponse> snapshotResponse = startFullSnapshot(repoName, snapshotName);
    waitForBlock(dataNodeName, repoName, TimeValue.timeValueSeconds(30L));
    final AtomicBoolean blocked = new AtomicBoolean(true);
    final TransportService transportService = internalCluster().getInstance(TransportService.class, otherDataNode);
    transportService.addMessageListener(new TransportMessageListener() {

        @Override
        public void onRequestSent(DiscoveryNode node, long requestId, String action, TransportRequest request, TransportRequestOptions finalOptions) {
            if (blocked.get() && action.equals(SnapshotsService.UPDATE_SNAPSHOT_STATUS_ACTION_NAME)) {
                throw new AssertionError("Node had no assigned shard snapshots so it shouldn't send out shard state updates");
            }
        }
    });
    logger.info("--> abort snapshot");
    final ActionFuture<AcknowledgedResponse> deleteResponse = startDeleteSnapshot(repoName, snapshotName);
    awaitClusterState(otherDataNode, state -> state.custom(SnapshotsInProgress.TYPE, SnapshotsInProgress.EMPTY).entries().stream().anyMatch(entry -> entry.state() == SnapshotsInProgress.State.ABORTED));
    assertFalse("delete should not be able to finish until data node is unblocked", deleteResponse.isDone());
    blocked.set(false);
    unblockAllDataNodes(repoName);
    assertAcked(deleteResponse.get());
    assertThat(snapshotResponse.get().getSnapshotInfo().state(), is(SnapshotState.FAILED));
}
Also used : RepositoryMissingException(org.opensearch.repositories.RepositoryMissingException) Arrays(java.util.Arrays) Metadata(org.opensearch.cluster.metadata.Metadata) CheckedFunction(org.opensearch.common.CheckedFunction) Matchers.not(org.hamcrest.Matchers.not) ClusterScope(org.opensearch.test.OpenSearchIntegTestCase.ClusterScope) Version(org.opensearch.Version) SnapshotsStatusResponse(org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse) Strings(org.opensearch.common.Strings) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) RecoveryState(org.opensearch.indices.recovery.RecoveryState) SnapshotStatus(org.opensearch.action.admin.cluster.snapshots.status.SnapshotStatus) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Path(java.nio.file.Path) EnumSet(java.util.EnumSet) OpenSearchAssertions.assertRequestBuilderThrows(org.opensearch.test.hamcrest.OpenSearchAssertions.assertRequestBuilderThrows) Client(org.opensearch.client.Client) TimeValue(org.opensearch.common.unit.TimeValue) NodeClient(org.opensearch.client.node.NodeClient) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Matchers.allOf(org.hamcrest.Matchers.allOf) TransportRequestOptions(org.opensearch.transport.TransportRequestOptions) Settings(org.opensearch.common.settings.Settings) TestCustomMetadata(org.opensearch.test.TestCustomMetadata) Scope(org.opensearch.test.OpenSearchIntegTestCase.Scope) TransportService(org.opensearch.transport.TransportService) RetentionLeaseActions(org.opensearch.index.seqno.RetentionLeaseActions) UncheckedIOException(java.io.UncheckedIOException) FileVisitResult(java.nio.file.FileVisitResult) CountDownLatch(java.util.concurrent.CountDownLatch) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) Matchers.containsString(org.hamcrest.Matchers.containsString) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Priority(org.opensearch.common.Priority) Node(org.opensearch.node.Node) ParseField(org.opensearch.common.ParseField) Writeable(org.opensearch.common.io.stream.Writeable) MockTransportService(org.opensearch.test.transport.MockTransportService) ArrayList(java.util.ArrayList) RestoreSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse) ClusterState(org.opensearch.cluster.ClusterState) BusyMasterServiceDisruption(org.opensearch.test.disruption.BusyMasterServiceDisruption) Matchers.lessThan(org.hamcrest.Matchers.lessThan) Matchers.hasSize(org.hamcrest.Matchers.hasSize) AbstractRestChannel(org.opensearch.rest.AbstractRestChannel) Environment(org.opensearch.env.Environment) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Files(java.nio.file.Files) RETAIN_ALL(org.opensearch.index.seqno.RetentionLeaseActions.RETAIN_ALL) IOException(java.io.IOException) TransportMessageListener(org.opensearch.transport.TransportMessageListener) Plugin(org.opensearch.plugins.Plugin) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) RetentionLeases(org.opensearch.index.seqno.RetentionLeases) ClusterService(org.opensearch.cluster.service.ClusterService) ShardStats(org.opensearch.action.admin.indices.stats.ShardStats) IndexRequestBuilder(org.opensearch.action.index.IndexRequestBuilder) BlobStoreRepository(org.opensearch.repositories.blobstore.BlobStoreRepository) NodeRoles.nonMasterNode(org.opensearch.test.NodeRoles.nonMasterNode) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) XContentParser(org.opensearch.common.xcontent.XContentParser) FakeRestRequest(org.opensearch.test.rest.FakeRestRequest) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Locale(java.util.Locale) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) Collection(java.util.Collection) RestStatus(org.opensearch.rest.RestStatus) ServiceDisruptionScheme(org.opensearch.test.disruption.ServiceDisruptionScheme) MockRepository(org.opensearch.snapshots.mockstore.MockRepository) List(java.util.List) Matchers.equalTo(org.hamcrest.Matchers.equalTo) SnapshotStats(org.opensearch.action.admin.cluster.snapshots.status.SnapshotStats) RestGetRepositoriesAction(org.opensearch.rest.action.admin.cluster.RestGetRepositoriesAction) SnapshotsInProgress(org.opensearch.cluster.SnapshotsInProgress) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InternalTestCluster(org.opensearch.test.InternalTestCluster) AtomicReference(java.util.concurrent.atomic.AtomicReference) NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) PeerRecoveryTargetService(org.opensearch.indices.recovery.PeerRecoveryTargetService) StreamInput(org.opensearch.common.io.stream.StreamInput) SettingsFilter(org.opensearch.common.settings.SettingsFilter) OpenSearchAssertions.assertAcked(org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked) CreateSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) Setting(org.opensearch.common.settings.Setting) TransportRequest(org.opensearch.transport.TransportRequest) RestRequest(org.opensearch.rest.RestRequest) IntHashSet(com.carrotsearch.hppc.IntHashSet) IntSet(com.carrotsearch.hppc.IntSet) RestClusterStateAction(org.opensearch.rest.action.admin.cluster.RestClusterStateAction) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) OpenSearchAssertions.assertFutureThrows(org.opensearch.test.hamcrest.OpenSearchAssertions.assertFutureThrows) RestResponse(org.opensearch.rest.RestResponse) ActionFuture(org.opensearch.action.ActionFuture) ActiveShardCount(org.opensearch.action.support.ActiveShardCount) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) ShardId(org.opensearch.index.shard.ShardId) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Sets(org.opensearch.common.util.set.Sets) CreateSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest) GetSnapshotsResponse(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) NamedDiff(org.opensearch.cluster.NamedDiff) Collections(java.util.Collections) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) TransportRequest(org.opensearch.transport.TransportRequest) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CreateSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) TransportService(org.opensearch.transport.TransportService) MockTransportService(org.opensearch.test.transport.MockTransportService) TransportRequestOptions(org.opensearch.transport.TransportRequestOptions) TransportMessageListener(org.opensearch.transport.TransportMessageListener)

Example 3 with Node

use of org.opensearch.node.Node in project OpenSearch by opensearch-project.

the class IndicesServiceCloseTests method testCloseNonEmptyIndicesService.

public void testCloseNonEmptyIndicesService() throws Exception {
    Node node = startNode();
    IndicesService indicesService = node.injector().getInstance(IndicesService.class);
    assertEquals(1, indicesService.indicesRefCount.refCount());
    assertAcked(node.client().admin().indices().prepareCreate("test").setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0)));
    assertEquals(2, indicesService.indicesRefCount.refCount());
    assertFalse(indicesService.awaitClose(0, TimeUnit.MILLISECONDS));
    node.close();
    assertEquals(0, indicesService.indicesRefCount.refCount());
    assertTrue(indicesService.awaitClose(0, TimeUnit.MILLISECONDS));
}
Also used : Node(org.opensearch.node.Node) MockNode(org.opensearch.node.MockNode) NodeRoles.dataNode(org.opensearch.test.NodeRoles.dataNode)

Example 4 with Node

use of org.opensearch.node.Node in project OpenSearch by opensearch-project.

the class IndicesServiceCloseTests method testCloseWithIncedRefStore.

public void testCloseWithIncedRefStore() throws Exception {
    Node node = startNode();
    IndicesService indicesService = node.injector().getInstance(IndicesService.class);
    assertEquals(1, indicesService.indicesRefCount.refCount());
    assertAcked(node.client().admin().indices().prepareCreate("test").setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0)));
    assertEquals(2, indicesService.indicesRefCount.refCount());
    IndexService indexService = indicesService.iterator().next();
    IndexShard shard = indexService.getShard(0);
    shard.store().incRef();
    assertFalse(indicesService.awaitClose(0, TimeUnit.MILLISECONDS));
    node.close();
    assertEquals(1, indicesService.indicesRefCount.refCount());
    assertFalse(indicesService.awaitClose(0, TimeUnit.MILLISECONDS));
    shard.store().decRef();
    assertEquals(0, indicesService.indicesRefCount.refCount());
    assertTrue(indicesService.awaitClose(0, TimeUnit.MILLISECONDS));
}
Also used : IndexService(org.opensearch.index.IndexService) Node(org.opensearch.node.Node) MockNode(org.opensearch.node.MockNode) NodeRoles.dataNode(org.opensearch.test.NodeRoles.dataNode) IndexShard(org.opensearch.index.shard.IndexShard)

Example 5 with Node

use of org.opensearch.node.Node in project OpenSearch by opensearch-project.

the class IndicesServiceCloseTests method testCloseWhileOngoingRequestUsesRequestCache.

public void testCloseWhileOngoingRequestUsesRequestCache() throws Exception {
    Node node = startNode();
    IndicesService indicesService = node.injector().getInstance(IndicesService.class);
    assertEquals(1, indicesService.indicesRefCount.refCount());
    assertAcked(node.client().admin().indices().prepareCreate("test").setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0).put(IndexModule.INDEX_QUERY_CACHE_EVERYTHING_SETTING.getKey(), true)));
    node.client().prepareIndex("test").setId("1").setSource(Collections.singletonMap("foo", 3L)).get();
    OpenSearchAssertions.assertAllSuccessful(node.client().admin().indices().prepareRefresh("test").get());
    assertEquals(2, indicesService.indicesRefCount.refCount());
    IndicesRequestCache cache = indicesService.indicesRequestCache;
    IndexService indexService = indicesService.iterator().next();
    IndexShard shard = indexService.getShard(0);
    Engine.Searcher searcher = shard.acquireSearcher("test");
    assertEquals(1, searcher.getIndexReader().maxDoc());
    node.close();
    assertEquals(1, indicesService.indicesRefCount.refCount());
    assertEquals(0L, cache.count());
    IndicesRequestCache.CacheEntity cacheEntity = new IndicesRequestCache.CacheEntity() {

        @Override
        public long ramBytesUsed() {
            return 42;
        }

        @Override
        public void onCached(Key key, BytesReference value) {
        }

        @Override
        public boolean isOpen() {
            return true;
        }

        @Override
        public Object getCacheIdentity() {
            return this;
        }

        @Override
        public void onHit() {
        }

        @Override
        public void onMiss() {
        }

        @Override
        public void onRemoval(RemovalNotification<Key, BytesReference> notification) {
        }
    };
    cache.getOrCompute(cacheEntity, () -> new BytesArray("bar"), searcher.getDirectoryReader(), new BytesArray("foo"));
    assertEquals(1L, cache.count());
    searcher.close();
    assertEquals(0, indicesService.indicesRefCount.refCount());
    assertEquals(0L, cache.count());
}
Also used : BytesReference(org.opensearch.common.bytes.BytesReference) BytesArray(org.opensearch.common.bytes.BytesArray) IndexService(org.opensearch.index.IndexService) Node(org.opensearch.node.Node) MockNode(org.opensearch.node.MockNode) NodeRoles.dataNode(org.opensearch.test.NodeRoles.dataNode) IndexShard(org.opensearch.index.shard.IndexShard) RemovalNotification(org.opensearch.common.cache.RemovalNotification) Engine(org.opensearch.index.engine.Engine) Key(org.opensearch.indices.IndicesRequestCache.Key)

Aggregations

Node (org.opensearch.node.Node)21 MockNode (org.opensearch.node.MockNode)15 Settings (org.opensearch.common.settings.Settings)12 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)10 NodeRoles.dataNode (org.opensearch.test.NodeRoles.dataNode)10 ArrayList (java.util.ArrayList)9 IndexService (org.opensearch.index.IndexService)9 Collections (java.util.Collections)8 List (java.util.List)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 IndexShard (org.opensearch.index.shard.IndexShard)8 IOException (java.io.IOException)7 Set (java.util.Set)7 TimeUnit (java.util.concurrent.TimeUnit)7 Collectors (java.util.stream.Collectors)7 Logger (org.apache.logging.log4j.Logger)7 Matchers.equalTo (org.hamcrest.Matchers.equalTo)7 TimeValue (org.opensearch.common.unit.TimeValue)7 UncheckedIOException (java.io.UncheckedIOException)6 Path (java.nio.file.Path)6