Apache Ignite exception: les caches ont des ensembles distincts de nœuds de données

Je commence avec Apache Ignite et je suivais le tutoriel Ignite sur le site Web Apache. Je cours en exception ci-dessous. Il semble que j’ai créé deux jeux de données différents et que je ne parviens pas à les synchroniser ou à en choisir un par rapport à un autre.

Cela se produit lorsque je lance Ignite à partir de la ligne de commande, puis le code avant que la méthode de classe ne la mette à jour. Ensuite, le code de test démarre un nouveau nœud. Je suppose qu’ils seraient synchronisés.

Code:

import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; import java.util.Iterator; import java.util.List; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteException; import org.apache.ignite.Ignition; import org.apache.ignite.cache.query.FieldsQueryCursor; import org.apache.ignite.cache.query.SqlFieldsQuery; import org.junit.BeforeClass; import org.junit.Test; public class IgniteTest { @BeforeClass public static void beforeClass() throws Exception { // Register JDBC driver. Class.forName("org.apache.ignite.IgniteJdbcThinDriver"); // Open JDBC connection. Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1/"); // Create database tables. try (Statement stmt = conn.createStatement()) { // Drop existing tables stmt.execute("DROP TABLE IF EXISTS Person"); stmt.execute("DROP TABLE IF EXISTS City"); // Create table based on REPLICATED template. stmt.executeUpdate("CREATE TABLE City (" + " id LONG PRIMARY KEY, name VARCHAR) " + " WITH \"template=replicated\""); // Create table based on PARTITIONED template with one backup. stmt.executeUpdate("CREATE TABLE Person (" + " id LONG, name VARCHAR, city_id LONG, " + " PRIMARY KEY (id, city_id)) " + " WITH \"backups=1, affinityKey=city_id\""); // Create an index on the City table. stmt.executeUpdate("CREATE INDEX idx_city_name ON City (name)"); // Create an index on the Person table. stmt.executeUpdate("CREATE INDEX idx_person_name ON Person (name)"); } } @Test public void test_01_HelloWorld() throws Exception { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { // Put values in cache. IgniteCache cache = ignite.getOrCreateCache("myCache"); cache.put(1, "Hello"); cache.put(2, "World!"); // Get values from cache // Broadcast 'Hello World' on all the nodes in the cluster. ignite.compute().broadcast(() -> System.out.println(cache.get(1) + " " + cache.get(2))); } } @Test public void test_ignite() throws Exception { // Connecting to the cluster. try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { // Getting a reference to an underlying cache created for City table above. IgniteCache cityCache = ignite.cache("SQL_PUBLIC_CITY"); // Getting a reference to an underlying cache created for Person table above. IgniteCache personCache = ignite.cache("SQL_PUBLIC_PERSON"); // Inserting ensortinges into City. SqlFieldsQuery query = new SqlFieldsQuery( "INSERT INTO City (id, name) VALUES (?, ?)"); cityCache.query(query.setArgs(1, "Forest Hill")).getAll(); cityCache.query(query.setArgs(2, "Denver")).getAll(); cityCache.query(query.setArgs(3, "St. Petersburg")).getAll(); // Inserting ensortinges into Person. query = new SqlFieldsQuery( "INSERT INTO Person (id, name, city_id) VALUES (?, ?, ?)"); personCache.query(query.setArgs(1, "John Doe", 3)).getAll(); personCache.query(query.setArgs(2, "Jane Roe", 2)).getAll(); personCache.query(query.setArgs(3, "Mary Major", 1)).getAll(); personCache.query(query.setArgs(4, "Richard Miles", 2)).getAll(); // next example // Querying data from the cluster using a dissortingbuted JOIN. SqlFieldsQuery query2 = new SqlFieldsQuery("SELECT p.name, c.name " + " FROM Person p, City c WHERE p.city_id = c.id"); FieldsQueryCursor<List> cursor = cityCache.query(query2); Iterator<List> iterator = cursor.iterator(); while (iterator.hasNext()) { List row = iterator.next(); System.out.println(row.get(0) + ", " + row.get(1)); } } } public static void main(Ssortingng[] args) throws IgniteException { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { // Put values in cache. IgniteCache cache = ignite.getOrCreateCache("myCache"); cache.put(1, "Hello"); cache.put(2, "World!"); // Get values from cache // Broadcast 'Hello World' on all the nodes in the cluster. ignite.compute().broadcast(() -> System.out.println(cache.get(1) + " " + cache.get(2))); } } } class City { private long id; private Ssortingng name; } class Person { private long id; private Ssortingng name; private long city_id; } class PersonKey { } 

Exception:

 javax.cache.CacheException: Caches have distinct sets of data nodes [cache1=SQL_PUBLIC_CITY, cache2=SQL_PUBLIC_PERSON] at org.apache.ignite.internal.processors.query.h2.twostep.GridReduceQueryExecutor.stableDataNodes(GridReduceQueryExecutor.java:499) at org.apache.ignite.internal.processors.query.h2.twostep.GridReduceQueryExecutor.nodesForPartitions(GridReduceQueryExecutor.java:1486) at org.apache.ignite.internal.processors.query.h2.twostep.GridReduceQueryExecutor.query(GridReduceQueryExecutor.java:591) at org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing$8.iterator(IgniteH2Indexing.java:1339) at org.apache.ignite.internal.processors.cache.QueryCursorImpl.iterator(QueryCursorImpl.java:95) at org.lhasalimited.ecosystem.business.statestore.ignite.impl.IgniteTest.test_ignite(IgniteTest.java:111) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) *emphasized text* at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206) 

J’ai eu exactement cette erreur et corrigé en ajoutant

 Ignition.setClientMode(true); 

avant l’appel à Ignition.start();