gpt4 book ai didi

java - Apache Ignite 异常 : Caches have distinct sets of data nodes

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:23:25 48 4
gpt4 key购买 nike

我从 Apache Ignite 开始,我正在关注 Apache 网站上的 Ignite 教程。我在下面遇到异常。看来我造成了两个不同的数据集,我无法同步它们或选择一个而不是另一个。

当我首先从命令行启动 Ignite 然后在类方法更新它之前编码时会发生这种情况。然后测试代码启动新节点。我假设它们会同步。

代码:

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<Integer, String> 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<Long, City> cityCache = ignite.cache("SQL_PUBLIC_CITY");

// Getting a reference to an underlying cache created for Person table above.
IgniteCache<PersonKey, Person> personCache = ignite.cache("SQL_PUBLIC_PERSON");

// Inserting entries 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 entries 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 distributed 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(String[] args) throws IgniteException
{
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml"))
{
// Put values in cache.
IgniteCache<Integer, String> 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 String name;
}

class Person
{
private long id;
private String 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)

最佳答案

我确实遇到了这个错误并通过添加修复了它

Ignition.setClientMode(true);

在调用 Ignition.start(); 之前

关于java - Apache Ignite 异常 : Caches have distinct sets of data nodes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49300556/

48 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com