You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "valepakh (via GitHub)" <gi...@apache.org> on 2024/06/12 08:49:15 UTC

[PR] IGNITE-22224 Rework embedded mode API [ignite-3]

valepakh opened a new pull request, #3908:
URL: https://github.com/apache/ignite-3/pull/3908

   https://issues.apache.org/jira/browse/IGNITE-22224


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-22224 Rework embedded mode API [ignite-3]

Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #3908:
URL: https://github.com/apache/ignite-3/pull/3908#discussion_r1654693133


##########
modules/runner/src/main/java/org/apache/ignite/IgniteServer.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite;
+
+import java.nio.file.Path;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.app.IgniteServerImpl;
+import org.apache.ignite.lang.IgniteException;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Embedded Ignite node. Manages node's lifecycle, provides Ignite API and allows cluster initialization.
+ */
+public interface IgniteServer {
+    /**
+     * Starts an embedded Ignite node with a configuration from a HOCON file.
+     *
+     * <p>When the future returned from this method completes, the node is partially started, and is ready to accept the init command (that
+     * is, its REST endpoint is
+     * functional).
+     *
+     * @param nodeName Name of the node. Must not be {@code null}.
+     * @param configPath Path to the node configuration in the HOCON format. Must not be {@code null}.
+     * @param workDir Work directory for the node. Must not be {@code null}.
+     * @return Future that will be completed when the node is partially started, and is ready to accept the init command (that is, its REST
+     *         endpoint is functional).
+     */
+    static CompletableFuture<IgniteServer> startAsync(String nodeName, Path configPath, Path workDir) {
+        return startAsync(nodeName, configPath, workDir, null);
+    }
+
+    /**
+     * Starts an embedded Ignite node with a configuration from a HOCON file with an optional class loader for further usage by
+     * {@link java.util.ServiceLoader}..
+     *
+     * <p>When the future returned from this method completes, the node is partially started, and is ready to accept the init command (that
+     * is, its REST endpoint is functional).
+     *
+     * @param nodeName Name of the node. Must not be {@code null}.
+     * @param configPath Path to the node configuration in the HOCON format. Must not be {@code null}.
+     * @param workDir Work directory for the node. Must not be {@code null}.
+     * @param serviceLoaderClassLoader The class loader to be used to load provider-configuration files and provider classes, or
+     *         {@code null} if the system class loader (or, failing that, the bootstrap class loader) is to be used
+     * @return Future that will be completed when the node is partially started, and is ready to accept the init command (that is, its REST
+     *         endpoint is functional).
+     */
+    static CompletableFuture<IgniteServer> startAsync(
+            String nodeName,
+            Path configPath,
+            Path workDir,
+            @Nullable ClassLoader serviceLoaderClassLoader
+    ) {
+        IgniteServerImpl embeddedNode = new IgniteServerImpl(nodeName, configPath, workDir, serviceLoaderClassLoader);
+        return embeddedNode.startAsync().thenApply(unused -> embeddedNode);
+    }
+
+    /**
+     * Starts an embedded Ignite node with a configuration from a HOCON file with an optional class loader for further usage by
+     * {@link java.util.ServiceLoader}..
+     *
+     * <p>When this method returns, the node is partially started, and is ready to accept the init command (that is, its REST endpoint is
+     * functional).
+     *
+     * @param nodeName Name of the node. Must not be {@code null}.
+     * @param configPath Path to the node configuration in the HOCON format. Must not be {@code null}.
+     * @param workDir Work directory for the node. Must not be {@code null}.
+     * @return Node instance.
+     */
+    static IgniteServer start(String nodeName, Path configPath, Path workDir) {
+        return start(nodeName, configPath, workDir, null);
+    }
+
+    /**
+     * Creates and starts an embedded Ignite node with a configuration from a HOCON file, with an optional class loader for further usage by
+     * {@link java.util.ServiceLoader}.
+     *
+     * <p>When this method returns, the node is partially started, and is ready to accept the init command (that is, its REST endpoint is
+     * functional).
+     *
+     * @param nodeName Name of the node. Must not be {@code null}.
+     * @param configPath Path to the node configuration in the HOCON format. Must not be {@code null}.
+     * @param workDir Work directory for the started node. Must not be {@code null}.
+     * @param serviceLoaderClassLoader The class loader to be used to load provider-configuration files and provider classes, or
+     *         {@code null} if the system class loader (or, failing that, the bootstrap class loader) is to be used
+     */
+    static IgniteServer start(
+            String nodeName,
+            Path configPath,
+            Path workDir,
+            @Nullable ClassLoader serviceLoaderClassLoader
+    ) {
+        IgniteServerImpl embeddedNode = new IgniteServerImpl(nodeName, configPath, workDir, serviceLoaderClassLoader);
+        embeddedNode.start();
+        return embeddedNode;
+    }
+
+    /**
+     * Returns the Ignite API. The API is available when the node has joined an initialized cluster. This method throws a
+     * {@link org.apache.ignite.lang.ClusterNotInitializedException} if the cluster is not yet initialized.
+     *
+     * @return Ignite API facade.
+     */
+    Ignite api();
+
+    /**
+     * Initializes the cluster that the given node is present in.
+     *
+     * <p>Cluster initialization propagates information about those nodes that will host the Meta Storage and CMG Raft groups
+     * to all nodes in the cluster. After the operation succeeds, nodes can finish the start procedure and begin accepting incoming
+     * requests.
+     *
+     * <p>Meta Storage is responsible for storing cluster-wide meta information required for internal purposes and proper functioning of
+     * the cluster.

Review Comment:
   Ok, let's keep it for now.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-22224 Rework embedded mode API [ignite-3]

Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #3908:
URL: https://github.com/apache/ignite-3/pull/3908#discussion_r1639339189


##########
modules/runner/src/main/java/org/apache/ignite/EmbeddedNode.java:
##########
@@ -52,40 +57,88 @@ public interface Ignition {
      * @param workDir Work directory for the started node. Must not be {@code null}.
      * @param serviceLoaderClassLoader The class loader to be used to load provider-configuration files and provider classes, or {@code
      * null} if the system class loader (or, failing that, the bootstrap class loader) is to be used
-     * @return CompletableFuture that resolves to an Ignite node after all components are started and the cluster initialization is
-     *         complete.
      */
-    CompletableFuture<Ignite> start(
+    static EmbeddedNode create(
             String nodeName,
             Path configPath,
             Path workDir,
             @Nullable ClassLoader serviceLoaderClassLoader
-    );
+    ) {
+        EmbeddedNode embeddedNode = new EmbeddedNodeImpl(nodeName, configPath, workDir, serviceLoaderClassLoader);
+        embeddedNode.start(); // Ignite future is kept inside this instance and will be returned from the igniteAsync.
+        return embeddedNode;
+    }
+
+    /**
+     * Returns the Ignite API. The API is available when the node has joined an initialized cluster.
+     *
+     * @return Ignite API future.
+     */
+    CompletableFuture<Ignite> igniteAsync();

Review Comment:
   I believe this method should be synchronous and return a result immediately in any case. If the node is not in a correct state, then Ignite API methods will throw an exception.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-22224 Rework embedded mode API [ignite-3]

Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #3908:
URL: https://github.com/apache/ignite-3/pull/3908#discussion_r1639336262


##########
modules/runner/src/main/java/org/apache/ignite/EmbeddedNode.java:
##########
@@ -52,40 +57,88 @@ public interface Ignition {
      * @param workDir Work directory for the started node. Must not be {@code null}.
      * @param serviceLoaderClassLoader The class loader to be used to load provider-configuration files and provider classes, or {@code
      * null} if the system class loader (or, failing that, the bootstrap class loader) is to be used
-     * @return CompletableFuture that resolves to an Ignite node after all components are started and the cluster initialization is
-     *         complete.
      */
-    CompletableFuture<Ignite> start(
+    static EmbeddedNode create(
             String nodeName,
             Path configPath,
             Path workDir,
             @Nullable ClassLoader serviceLoaderClassLoader
-    );
+    ) {
+        EmbeddedNode embeddedNode = new EmbeddedNodeImpl(nodeName, configPath, workDir, serviceLoaderClassLoader);
+        embeddedNode.start(); // Ignite future is kept inside this instance and will be returned from the igniteAsync.
+        return embeddedNode;
+    }
+
+    /**
+     * Returns the Ignite API. The API is available when the node has joined an initialized cluster.
+     *
+     * @return Ignite API future.
+     */
+    CompletableFuture<Ignite> igniteAsync();

Review Comment:
   This method returns a future that will never complete if I don't call `initClusterAsync`, right?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-22224 Rework embedded mode API [ignite-3]

Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #3908:
URL: https://github.com/apache/ignite-3/pull/3908#discussion_r1639337516


##########
modules/runner/src/main/java/org/apache/ignite/EmbeddedNode.java:
##########
@@ -52,40 +57,88 @@ public interface Ignition {
      * @param workDir Work directory for the started node. Must not be {@code null}.
      * @param serviceLoaderClassLoader The class loader to be used to load provider-configuration files and provider classes, or {@code
      * null} if the system class loader (or, failing that, the bootstrap class loader) is to be used
-     * @return CompletableFuture that resolves to an Ignite node after all components are started and the cluster initialization is
-     *         complete.
      */
-    CompletableFuture<Ignite> start(
+    static EmbeddedNode create(
             String nodeName,
             Path configPath,
             Path workDir,
             @Nullable ClassLoader serviceLoaderClassLoader
-    );
+    ) {
+        EmbeddedNode embeddedNode = new EmbeddedNodeImpl(nodeName, configPath, workDir, serviceLoaderClassLoader);
+        embeddedNode.start(); // Ignite future is kept inside this instance and will be returned from the igniteAsync.

Review Comment:
   I don't think we should start the node as part of `create` call, the API becomes confusing.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org