Apache Ignite缓存为空,表具有值 [英] Apache Ignite cache empty, table has values

查看:87
本文介绍了Apache Ignite缓存为空,表具有值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的Ignite持久性设置。目前,它是在服务器模式下运行的单个节点,我通过该节点连接两个客户端。当我通过SQL从这些客户端之一(以下称为客户端1)插入数据时,可以再次使用SQL选择它并返回结果。在下面的客户端2中,当我尝试获取应已创建以代表该表的缓存时,该缓存为空。

I have a basic Ignite persistence setup working. For now, it's a single node running in server mode, from which I connect two clients. When I insert data via SQL from one of these clients ("Client 1" below), I can SELECT it again with SQL and get results back. From "Client 2" below, when I try to grab the cache which ought to have been created to represent this table, it is null.

服务器运行apacheignite映像使用以下Dockerfile:

The server runs the apacheignite image using the following Dockerfile:

FROM apacheignite/ignite

# for jdbc connection
EXPOSE 10800

EXPOSE 47100-47109
EXPOSE 47500-47509

# for rest api
EXPOSE 8080

WORKDIR /app

COPY ./config /app/config

RUN mv /opt/ignite/apache-ignite/libs/optional/ignite-aws /opt/ignite/apache-ignite/libs/

RUN mv /opt/ignite/apache-ignite/libs/optional/ignite-rest-http /opt/ignite/apache-ignite/libs/

CMD /opt/ignite/apache-ignite/bin/ignite.sh /app/config/ignite-config.xml -v

此处引用的 ignite-config.xml 的相关部分如下:

The relevant parts of the ignite-config.xml referenced here is as follows:

<bean class="org.apache.ignite.configuration.IgniteConfiguration">
        <property name="dataStorageConfiguration">
            <bean class="org.apache.ignite.configuration.DataStorageConfiguration">
                <property name="defaultDataRegionConfiguration">
                    <bean class="org.apache.ignite.configuration.DataRegionConfiguration">
                        <property name="persistenceEnabled" value="true"/>
                    </bean>
                </property>
            </bean>
        </property>
        <property name="discoverySpi">
            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
                <property name="ipFinder">
                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
                        <property name="addresses">
                            <list>
                                <value>127.0.0.1:47500..47509</value>
                            </list>
                        </property>
                    </bean>
                </property>
            </bean>
        </property>
    </bean>

我还确保使用Persistence将群集设置为激活服务器服务器上的群集

I've also made sure to activate the cluster on the Server container using since Persistence sets the cluster to inactive by default.

/opt/ignite/apache-ignite/bin/control.sh --activate



客户端1



客户端1通过Thin JDBC驱动程序连接,做了一些 CREATE TABLE s和 INSERT s。稍后当我在诸如DBeaver之类的 SELECT 中时,我可以看到此数据。

Client 1

Client 1 connects over the Thin JDBC driver and does some CREATE TABLEs and INSERTs. When I later SELECT in something like DBeaver, I can see this data.

该客户端也在docker中运行,与Compose中的其他项目并排。它真正要做的就是循环调用以下命令,其中 $ file 是一个包含 CREATE TABLE INSERT 等。

This client also runs in docker, alongside the other in Compose. All it really does is call the following in a loop, where $file is a SQL file containing CREATE TABLE, INSERTs, etc.

/opt/ignite/apache-ignite/bin/sqlline.sh -u jdbc:ignite:thin://server:10800 -f $file;

一个这样的SQL文件如下:

One such SQL file looks like:

DROP TABLE IF EXISTS attributes;
DROP INDEX IF EXISTS idx_attributes_token;

CREATE TABLE attributes (
    token VARCHAR,
    attributeId LONG,
    name VARCHAR,
    PRIMARY KEY(token, attributeId)
) WITH "affinityKey=token";

CREATE INDEX idx_attributes_token ON attributes (token);

INSERT INTO attributes (token, attributeId, name) VALUES ('abc123', 123, 'some name');



客户端2



客户端2连接到或多或少地如下点火:

Client 2

Client 2 connects to Ignite more or less as follows:

IgniteConfiguration igniteConfiguration = new IgniteConfiguration();
TcpDiscoverySpi discoverySpi = new TcpDiscoverySpi();
TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();

ipFinder.setAddresses(igniteConfig.getAddresses()); // will be "localhost:10800" -- I map 10800:10800 when the "Server" container runs

discoverySpi.setIpFinder(ipFinder);
igniteConfiguration.setDiscoverySpi(discoverySpi);

Ignite ignite = Ignition.start(igniteConfiguration);

IgniteCache<Object, String> attributesCache = ignite.cache("SQL_PUBLIC_ATTRIBUTES"); // null

//  if i use ignite.getOrCreateCache("SQL_PUBLIC_ATTRIBUTES") instead then of course it's a cache of size 0.

最终,我希望能够抓住此缓存并使用Ignite文档中所述的 StreamVisitor 来对每个执行操作。据称这看起来像:

Ultimately, I want to be able to grab hold of this cache and use the StreamVisitor described in the Ignite docs to perform operations on each. That would allegedly look like:

... 
IgniteDataStreamer<Object, AttributeWithGroup> attributeStreamer = ignite.dataStreamer(attributesCache.getName());

attributeStreamer.receiver(StreamVisitor.from((cache, entity) -> {
    Object key = entity.getKey();
    Attribute attribute = entity.getValue();
    // do some stuff
}));

...但是lambda永远不会运行,因为缓存为空。

...but the lambda never runs, because the cache is null.

为什么在SQL中看到的内容和在缓存中看到的内容之间没有这种联系?

推荐答案

他们以这种方式启动客户端2,它将作为没有缓存的单个服务器节点启动。

They way you are starting your "Client 2" it will start as a single server node with no caches.

您还应该将47500用于发现端口,而不是10800。10800用于瘦客户机。

You should also be using 47500 for discovery port and not 10800. 10800 is for thin clients.

请还请注意,您的IpFinder,Vm与多播不匹配。

Please also note that you have mismatching IpFinder's, Vm versus Multicast.

这篇关于Apache Ignite缓存为空,表具有值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆