Internally Ignite is key-value storage. It use key to derive partition it belongs to. By default the whole key is used. Alternatively you can use @AffinityKey annotation in cache API or "affinityKey" option in CREATE TABLE to specify *part of the key* to be used for affinity calculation. Affinity column cannot belong to value because in this case single key-value pair could migrate between nodes during updates and IgniteCache.get(K) will not be able to locate the key in cluster.
On Fri, Mar 16, 2018 at 4:56 PM, David Harvey <[email protected]> wrote: > Yes, the affinity key must be part of the primary key. Welcome to my > world.... > > On Fri, Mar 16, 2018 at 3:23 AM, Naveen <[email protected]> wrote: > >> Hi Mike >> >> I have created a table called CITY >> >> : jdbc:ignite:thin://127.0.0.1> CREATE TABLE City ( city_id LONG PRIMARY >> KEY, name VARCHAR) WITH "template=replicated"; >> No rows affected (0.224 seconds) >> >> Creating a table called Person with affinity key as city_id >> >> 0: jdbc:ignite:thin://127.0.0.1> CREATE TABLE IF NOT EXISTS Person ( age >> int, id int, city_id LONG , name varchar, company varchar, PRIMARY KEY >> (name, id)) WITH "template=partitioned,backups=1,affinitykey=city_id, >> key_type=PersonKey, value_type=MyPerson"; >> >> This is the exception I get >> >> Error: Affinity key column must be one of key columns: CITY_ID >> (state=42000,code=0) >> java.sql.SQLException: Affinity key column must be one of key columns: >> CITY_ID >> at >> org.apache.ignite.internal.jdbc.thin.JdbcThinConnection.send >> Request(JdbcThinConnection.java:671) >> at >> org.apache.ignite.internal.jdbc.thin.JdbcThinStatement.execu >> te0(JdbcThinStatement.java:130) >> at >> org.apache.ignite.internal.jdbc.thin.JdbcThinStatement.execu >> te(JdbcThinStatement.java:299) >> at sqlline.Commands.execute(Commands.java:823) >> at sqlline.Commands.sql(Commands.java:733) >> at sqlline.SqlLine.dispatch(SqlLine.java:795) >> at sqlline.SqlLine.begin(SqlLine.java:668) >> at sqlline.SqlLine.start(SqlLine.java:373) >> at sqlline.SqlLine.main(SqlLine.java:265) >> 0: jdbc:ignite:thin://127.0.0.1> >> >> And, when I change the primary key to include affinity id, below DDL is >> working fine. >> 0: jdbc:ignite:thin://127.0.0.1> CREATE TABLE IF NOT EXISTS Person ( age >> int, id int, city_id LONG , name varchar, company varchar, PRIMARY KEY >> (name, id,city_id)) WITH >> "template=partitioned,backups=1,affinitykey=city_id, key_type=PersonKey, >> value_type=MyPerson"; >> >> This is what I was trying to explain, is affinity key to be part of the >> primary key ?? >> >> If this is the case, whole my data model will change drastically. >> >> Thanks >> Naveen >> >> >> >> -- >> Sent from: http://apache-ignite-users.70518.x6.nabble.com/ >> > > > > *Disclaimer* > > The information contained in this communication from the sender is > confidential. It is intended solely for use by the recipient and others > authorized to receive it. If you are not the recipient, you are hereby > notified that any disclosure, copying, distribution or taking action in > relation of the contents of this information is strictly prohibited and may > be unlawful. > > This email has been scanned for viruses and malware, and may have been > automatically archived by *Mimecast Ltd*, an innovator in Software as a > Service (SaaS) for business. Providing a *safer* and *more useful* place > for your human generated data. Specializing in; Security, archiving and > compliance. To find out more Click Here > <http://www.mimecast.com/products/>. >
