You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sk...@apache.org on 2021/10/08 17:06:40 UTC

[ignite-3] branch main updated: IGNITE-15490 Created an example(s) that can allow to demonstrate rebalancing. Fixes #390

This is an automated email from the ASF dual-hosted git repository.

sk0x50 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new 2a6c557  IGNITE-15490 Created an example(s) that can allow to demonstrate rebalancing. Fixes #390
2a6c557 is described below

commit 2a6c557293035a138a2d4030d4c4cbe7f057b506
Author: Kirill Gusakov <kg...@gmail.com>
AuthorDate: Fri Oct 8 20:06:22 2021 +0300

    IGNITE-15490 Created an example(s) that can allow to demonstrate rebalancing. Fixes #390
    
    Signed-off-by: Slava Koptilin <sl...@gmail.com>
---
 examples/config/rebalance/ignite-config-0.json     |  13 +++
 examples/config/rebalance/ignite-config-1.json     |  13 +++
 examples/config/rebalance/ignite-config-2.json     |  13 +++
 examples/config/rebalance/ignite-config-3.json     |  13 +++
 examples/config/rebalance/ignite-config-4.json     |  13 +++
 .../ignite/example/rebalance/RebalanceExample.java | 107 +++++++++++++++++++++
 6 files changed, 172 insertions(+)

diff --git a/examples/config/rebalance/ignite-config-0.json b/examples/config/rebalance/ignite-config-0.json
new file mode 100644
index 0000000..b492441
--- /dev/null
+++ b/examples/config/rebalance/ignite-config-0.json
@@ -0,0 +1,13 @@
+{
+    "node": {
+        "metastorageNodes": [
+            "node-0"
+        ]
+    },
+    "network": {
+        "port": 3344,
+        "netClusterNodes": [
+            "localhost:3344", "localhost:3345", "localhost:3346"
+        ]
+    }
+}
diff --git a/examples/config/rebalance/ignite-config-1.json b/examples/config/rebalance/ignite-config-1.json
new file mode 100644
index 0000000..c814e97
--- /dev/null
+++ b/examples/config/rebalance/ignite-config-1.json
@@ -0,0 +1,13 @@
+{
+    "node": {
+        "metastorageNodes": [
+            "node-0"
+        ]
+    },
+    "network": {
+        "port": 3345,
+        "netClusterNodes": [
+            "localhost:3344", "localhost:3345", "localhost:3346"
+        ]
+    }
+}
diff --git a/examples/config/rebalance/ignite-config-2.json b/examples/config/rebalance/ignite-config-2.json
new file mode 100644
index 0000000..39cfc33
--- /dev/null
+++ b/examples/config/rebalance/ignite-config-2.json
@@ -0,0 +1,13 @@
+{
+    "node": {
+        "metastorageNodes": [
+            "node-0"
+        ]
+    },
+    "network": {
+        "port": 3346,
+        "netClusterNodes": [
+            "localhost:3344", "localhost:3345", "localhost:3346"
+        ]
+    }
+}
diff --git a/examples/config/rebalance/ignite-config-3.json b/examples/config/rebalance/ignite-config-3.json
new file mode 100644
index 0000000..357c33e
--- /dev/null
+++ b/examples/config/rebalance/ignite-config-3.json
@@ -0,0 +1,13 @@
+{
+    "node": {
+        "metastorageNodes": [
+            "node-0"
+        ]
+    },
+    "network": {
+        "port": 3347,
+        "netClusterNodes": [
+            "localhost:3344", "localhost:3345", "localhost:3346"
+        ]
+    }
+}
diff --git a/examples/config/rebalance/ignite-config-4.json b/examples/config/rebalance/ignite-config-4.json
new file mode 100644
index 0000000..e418070
--- /dev/null
+++ b/examples/config/rebalance/ignite-config-4.json
@@ -0,0 +1,13 @@
+{
+    "node": {
+        "metastorageNodes": [
+            "node-0"
+        ]
+    },
+    "network": {
+        "port": 3348,
+        "netClusterNodes": [
+            "localhost:3344", "localhost:3345", "localhost:3346"
+        ]
+    }
+}
diff --git a/examples/src/main/java/org/apache/ignite/example/rebalance/RebalanceExample.java b/examples/src/main/java/org/apache/ignite/example/rebalance/RebalanceExample.java
new file mode 100644
index 0000000..62ea4e6
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/example/rebalance/RebalanceExample.java
@@ -0,0 +1,107 @@
+/*
+ * 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.example.rebalance;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Set;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter;
+import org.apache.ignite.schema.SchemaBuilders;
+import org.apache.ignite.schema.definition.ColumnType;
+import org.apache.ignite.table.KeyValueView;
+import org.apache.ignite.table.Table;
+import org.apache.ignite.table.Tuple;
+
+/**
+ * This example demonstrates data rebalance on new nodes.
+ *
+ * - Start 3 nodes (A, B, C)
+ * - Put some data
+ * - Add 2 new nodes (D, E)
+ * - Set new baseline to (A, D, E)
+ * - Stop (B, C)
+ * - Check that data is still available on the new configuration
+ *
+ * <p>
+ * To run the example, do the following:
+ * <ol>
+ *     <li>Import the examples project into you IDE.</li>
+ *     <li>Run the example in the IDE.</li>
+ * </ol>
+ */
+public class RebalanceExample {
+
+    public static void main(String[] args) throws Exception {
+        var nodes = new ArrayList<Ignite>();
+
+        for (int i = 0; i < 3; i++) {
+            nodes.add(IgnitionManager.start("node-" + i,
+                Files.readString(Path.of("config", "rebalance", "ignite-config-" + i + ".json")),
+                Path.of("work" + i)));
+        }
+
+        var node0 = nodes.get(0);
+
+        Table testTable = node0.tables().createTable("PUBLIC.rebalance", tbl ->
+            SchemaConfigurationConverter.convert(
+                SchemaBuilders.tableBuilder("PUBLIC", "rebalance")
+                    .columns(
+                        SchemaBuilders.column("key", ColumnType.INT32).asNonNull().build(),
+                        SchemaBuilders.column("value", ColumnType.string()).asNullable().build()
+                    )
+                    .withPrimaryKey("key")
+                    .build(), tbl)
+                .changeReplicas(5)
+                .changePartitions(1)
+        );
+
+        KeyValueView<Tuple, Tuple> kvView = testTable.keyValueView();
+        Tuple key = Tuple.create()
+            .set("key", 1);
+
+        Tuple value = Tuple.create()
+            .set("value", "test");
+
+        kvView.put(key, value);
+
+        String oldValue = testTable.recordView().get(key).value("value");
+        System.out.println("Value in the start cluster configuration " + oldValue);
+
+        for (int i = 3; i < 5; i++) {
+            nodes.add(IgnitionManager.start("node-" + i,
+                Files.readString(Path.of("config", "rebalance", "ignite-config-" + i + ".json")),
+                Path.of("work" + i)));
+        }
+
+        node0.setBaseline(Set.of("node-0", "node-3", "node-4"));
+
+        IgnitionManager.stop(nodes.get(1).name());
+        IgnitionManager.stop(nodes.get(2).name());
+
+        var valueOnNewNode = nodes.get(4).tables().table("PUBLIC.rebalance").recordView().get(key).value("value");
+
+        System.out.println("Value in the new cluster configuration " + valueOnNewNode);
+
+        IgnitionManager.stop(nodes.get(0).name());
+        IgnitionManager.stop(nodes.get(3).name());
+        IgnitionManager.stop(nodes.get(4).name());
+    }
+}