Apache Ignite存储二进制值未写入SQL表问题排查
关于Apache Ignite动态构建BinaryObject无法映射SQL表的问题
我搭建了一个简单的Apache Ignite环境,后续计划用于SQL操作,但希望通过Java API动态构建数据,因此无法使用POJO类插入数据。目前出现了警告信息,调试GridQueryProcessor代码也没找到明显修复方案,怀疑type()调用始终返回null(变量b打印为b=null),但不确定具体原因。
日志输出
...snip b=null WARN GridQueryProcessor - Key-value pair is not inserted into any SQL table [cacheName=TestTable, valType=BinaryObject.TestTable_value] WARN GridQueryProcessor - ^-- Value type(s) are specified via CacheConfiguration.indexedTypes or CacheConfiguration.queryEntities WARN GridQueryProcessor - ^-- Make sure that same type(s) used when adding Object or BinaryObject to cache WARN GridQueryProcessor - ^-- Otherwise, entries will be stored in cache, but not appear as SQL Table rows --------Inserted ...snip
完整源代码
package snippet; import java.util.*; import java.util.logging.*; import javax.cache.Cache.Entry; import org.apache.ignite.*; import org.apache.ignite.binary.BinaryObject; import org.apache.ignite.cache.*; import org.apache.ignite.cache.query.*; import org.apache.ignite.configuration.*; import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; import org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder; import org.slf4j.bridge.SLF4JBridgeHandler; public class Snippet { public static void main(String... strings) throws InterruptedException { /* 让SLF4J拦截JUL日志 */ SLF4JBridgeHandler.install(); Logger.getLogger("").setLevel(Level.WARNING); // 启动节点 IgniteConfiguration cfg = new IgniteConfiguration(); cfg.setDeploymentMode(DeploymentMode.CONTINUOUS); TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder(); ipFinder.setAddresses(Collections.singletonList("127.0.0.1:47500..47509")); cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(ipFinder)); var ignite = Ignition.start(cfg); System.err.println("--------Started"); Thread.sleep(1000); // 创建表 var cachec = new CacheConfiguration<>("TestTable"); var qe = new QueryEntity(); qe.addQueryField("simpleId", Long.TYPE.getName(), null); qe.addQueryField("stringField", String.class.getName(), null); qe.setKeyType("TestTable_key"); qe.setIndexes(Collections.singleton(new QueryIndex("simpleId"))); qe.setValueType("TestTable_value"); // cachec.setStoreKeepBinary(true); // 似乎没有效果 cachec.setQueryEntities(Collections.singleton(qe)); cachec.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); cachec.setQueryParallelism(6); ignite.createCache(cachec); System.err.println("--------Created"); Thread.sleep(1000); // 插入一行数据 var bb = ignite.binary().builder("BinaryObject.TestTable_value"); var b = ignite.binary().type("TestTable_value"); // 不知为何始终返回null System.err.println(b == null ? "b=null" : "b=not null"); bb.setField("stringField", "it works!"); bb.setField("simpleId", 3l); ignite.cache("TestTable").withKeepBinary().put(3l, bb.build()); System.err.println("--------Inserted"); Thread.sleep(1000); // 清理资源 ignite.destroyCache("TestTable"); ignite.close(); } }
项目pom文件
可通过命令 mvn clean compile exec:exec 运行:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <name>Stack OverFlow Ignite Question</name> <groupId>com.test</groupId> <artifactId>test-ignite-soq</artifactId> <version>12345</version> <properties> <ignite.version>2.16.0</ignite.version> </properties> <dependencies> <dependency> <groupId>org.apache.ignite</groupId> <artifactId>ignite-core</artifactId> <version>${ignite.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>jul-to-slf4j</artifactId> <version>2.0.13</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.5.6</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <release>17</release> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>3.1.0</version> <configuration> <executable>java</executable> <arguments> <argument>--add-opens=java.base/jdk.internal.access=ALL-UNNAMED</argument> <argument>--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED</argument> <argument>--add-opens=java.base/sun.nio.ch=ALL-UNNAMED</argument> <argument>--add-opens=java.base/sun.util.calendar=ALL-UNNAMED</argument> <argument>--add-opens=java.management/com.sun.jmx.mbeanserver=ALL-UNNAMED</argument> <argument>--add-opens=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED</argument> <argument>--add-opens=java.base/sun.reflect.generics.reflectiveObjects=ALL-UNNAMED</argument> <argument>--add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED</argument> <argument>--add-opens=java.base/java.io=ALL-UNNAMED</argument> <argument>--add-opens=java.base/java.nio=ALL-UNNAMED</argument> <argument>--add-opens=java.base/java.net=ALL-UNNAMED</argument> <argument>--add-opens=java.base/java.util=ALL-UNNAMED</argument> <argument>--add-opens=java.base/java.util.concurrent=ALL-UNNAMED</argument> <argument>--add-opens=java.base/java.util.concurrent.locks=ALL-UNNAMED</argument> <argument>--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED</argument> <argument>--add-opens=java.base/java.lang=ALL-UNNAMED</argument> <argument>--add-opens=java.base/java.lang.invoke=ALL-UNNAMED</argument> <argument>--add-opens=java.base/java.math=ALL-UNNAMED</argument> <argument>--add-opens=java.sql/java.sql=ALL-UNNAMED</argument> <argument>--add-opens=java.base/java.lang.reflect=ALL-UNNAMED</argument> <argument>--add-opens=java.base/java.time=ALL-UNNAMED</argument> <argument>--add-opens=java.base/java.text=ALL-UNNAMED</argument> <argument>--add-opens=java.management/sun.management=ALL-UNNAMED</argument> <argument>--add-opens=java.desktop/java.awt.font=ALL-UNNAMED</argument> <argument>-classpath</argument> <classpath /> <argument>snippet.Snippet</argument> </arguments> </configuration> </plugin> </plugins> </build> </project>
Logback配置文件
<?xml version="1.0" encoding="UTF-8"?> <configuration> <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%d{HH:mm:ss.SSS} %level %logger{0} - %msg%n</pattern> </encoder> </appender> <root level="warn"> <appender-ref ref="console" /> </root> </configuration>
内容的提问来源于stack exchange,提问作者byteit101
相关产品推荐
相关产品推荐

