点燃@AffinityKeyMapped以获取整数的缓存键 [英] Ignite @AffinityKeyMapped for cache keys that are integers

查看:55
本文介绍了点燃@AffinityKeyMapped以获取整数的缓存键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读> https://apacheignite.readme.io/docs/affinity-collocation中的文档和在ignite-examples中,使用@AffinityKeyMapped的示例假定键是一个对象:PersonKey是具有personId和companyId的类,而CompanyId具有注释.

Reading the documentation in https://apacheignite.readme.io/docs/affinity-collocation and in ignite-examples, the example for using @AffinityKeyMapped assumes that the key is an object: PersonKey is a class with personId and companyId, and companyId has the annotation.

在我的用例中,我的密钥是一个简单的整数.我正在使用从WebConsole生成的域模型.我有2个类:Item和ItemInstance,而ItemInstance具有对Item的外键引用.我的模型定义如下:

In my use case my key is a simple integer. I am using the domain model generated from WebConsole. I have 2 classes: Item and ItemInstance, and ItemInstance has a foreign key reference to Item. My model is defined as follows:

public class ItemInstance implements Serializable {
    private static final long serialVersionUID = 0L;

    @QuerySqlField(index = true)
    @AffinityKeyMapped
    private int itemId;

    private String serialNumber;
...
}

public class Item implements Serializable {
    private String name;
...
}

在节点启动和缓存加载期间没有错误,但是在执行查询时,我得到的结果不完整-它仅检索并置的数据.我知道这是因为,当我在Web控制台中运行相同的查询并勾选了允许非并置的联接"时,我得到了完整的结果.

During node startup and cache loading there are no errors, but when executing a query I get incomplete results- it is retrieving only the data that are collocated. I know this because when I run the same query in Web Console with the "Allow non-collocated joins" ticked, I get the complete result.

请注意,我没有像其他示例中那样使用 AffinityKey ,因为我正在从3rdparty数据库中进行读取,而不进行任何 put .

Note that I am not using AffinityKey as in the other example because I am reading from the 3rdparty database, not doing any put.

您能告诉我以下内容吗?

Can you please tell me the following:

  1. 是否在整数键上点燃@AffinityKeyMapped的支持,类似于我上面的用法;

  1. Does ignite support @AffinityKeyMapped on integer keys similar to my usage above;

我们还需要在spring XML配置中定义@AffinityKeyMapped吗?我以为这可能是问题所在,但是我无法在Web控制台中找到它,也无法在线找到它.

Do we need to define @AffinityKeyMapped as well in the spring XML configuration? I thought this might be the issue, but I cannot find it in Web Console, nor online.

谢谢!

推荐答案

相似性键值必须是键对象的一部分.因此,如果您使用同一位置,则仅使用简单的整数作为缓存键是不够的,因为您的键至少应包含唯一的对象ID和相似性键.因此,您应该使用这两个字段创建一个对象,并用批注标记后者.

Affinity key value must be a part of key object. Therefore if you use co-location, using simple integer as a cache key is not enough, as your key should at least consist of unique object ID and affinity key. Therefore you should create an object with these two fields and mark the latter with the annotation.

如果您不想使用注释或没有类,则可以通过 CacheKeyConfiguration [1]提供相似性关键字字段名称.但是请注意,这仍然需要将复合对象用作键.

If you don't want to use annotation, or don't have classes, you can provide affinity key field name via CacheKeyConfiguration [1]. However note that this still requires a composite object to be used as a key.

[1] https://ignite.apache.org/releases/latest/javadoc/org/apache/ignite/cache/CacheKeyConfiguration.html

这篇关于点燃@AffinityKeyMapped以获取整数的缓存键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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