Ignite @AffinityKeyMapped for cache keys that are integers

拈花ヽ惹草 提交于 2019-12-11 17:23:33

问题


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.

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;
...
}

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.

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. Does ignite support @AffinityKeyMapped on integer keys similar to my usage above;

  2. 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.

Thanks!


回答1:


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.

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



来源:https://stackoverflow.com/questions/47839555/ignite-affinitykeymapped-for-cache-keys-that-are-integers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!