AffinityKeyMapped is only processed on cache keys, not on cache values.

Try cache.put(keyEntityWithAffinityKeyMappedAnnotation, value)


El 22 jun 2017, a las 13:16, tuco.ramirez [via Apache Ignite Users] 
<[email protected]<mailto:[email protected]>> 
escribió:

Hi,

I have a simple use case, but affinity key does not seem to be working.
AffinityKey is placed on clientId which is same for everyone. So all the data 
should go to one node.
However ignite visor shows that the data is different on each nodes, with each 
node having 3000+ entries.
using 1.9.0 also leads to the same behavior.

Below is the code.

TestItem Class


import java.io.Serializable;

import org.apache.ignite.cache.affinity.AffinityKeyMapped;

public class TestItem implements Serializable {

  private static final long serialVersionUID = 1L;

  @AffinityKeyMapped
    private String clientId;

  private int counter;

    public String getClientId() {
                return clientId;
        }

        public void setClientId(String clientId) {
                this.clientId = clientId;
        }

        public int getCounter() {
                return counter;
        }

        public void setCounter(int counter) {
                this.counter = counter;
        }



        public TestItem(String clientId, int counter) {
                super();
                this.clientId = clientId;
                this.counter = counter;
        }

}


import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
import org.apache.ignite.cache.CacheMode;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;

public class CreateCache {
        public static void main(String[] args) throws Exception {
                Ignition.setClientMode(true);

                IgniteConfiguration conf = new IgniteConfiguration();
                conf.setPeerClassLoadingEnabled(true);
                TcpDiscoverySpi discovery = new TcpDiscoverySpi();

                TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();

                ipFinder.setAddresses(Arrays.asList("ip1", "ip2", "ip3"));

                discovery.setIpFinder(ipFinder);

                conf.setDiscoverySpi(discovery);
                Ignite ignite = Ignition.start(conf);

                ignite.getOrCreateCache("TESTITEMCACHE").destroy();
                pushItems(ignite);

                Ignition.stop(true);
        }

        private static void pushItems(Ignite ignite) {
                CacheConfiguration<Integer, TestItem> itemCfg = new 
CacheConfiguration<>("TESTITEMCACHE");
                itemCfg.setCacheMode(CacheMode.PARTITIONED);
                itemCfg.setIndexedTypes(Integer.class, TestItem.class);

                IgniteCache<Integer, TestItem> skuCache = 
ignite.createCache(itemCfg);

                System.out.println("putting data");
                long t1 = System.currentTimeMillis();
                Map<Integer, TestItem> skuMap = new HashMap<>();

                for(int i = 0 ; i < 10000 ; i++){
                        TestItem item = new TestItem("testId", i);
                        skuMap.put(i, item);
                }
                System.out.println(" sku map size " + skuMap.size());
                skuCache.putAll(skuMap);

                long t2 = System.currentTimeMillis();
                System.out.println("put data in ms " + (t2 - t1));

                Ignition.stop(false);
        }
}



Output of ignite visor


visor> cache -a
Time of the snapshot: 06/22/17, 16:42:16
+==========================================================================================================================+
|      Name(@)       |    Mode     | Nodes |   Entries (Heap / Off-heap)   |   
Hits    |  Misses   |   Reads   |  Writes   |
+==========================================================================================================================+
| TESTITEMCACHE(@c0) | PARTITIONED | 3     | min: 3096 (3096 / 0)          | 
min: 0    | min: 0    | min: 0    | min: 0    |
|                    |             |       | avg: 3333.33 (3333.33 / 0.00) | 
avg: 0.00 | avg: 0.00 | avg: 0.00 | avg: 0.00 |
|                    |             |       | max: 3496 (3496 / 0)          | 
max: 0    | max: 0    | max: 0    | max: 0    |
+--------------------------------------------------------------------------------------------------------------------------+

Cache 'TESTITEMCACHE(@c0)':
+-----------------------------------------------------+
| Name(@)                     | TESTITEMCACHE(@c0)    |
| Nodes                       | 3                     |
| Total size Min/Avg/Max      | 3096 / 3333.33 / 3496 |
|   Heap size Min/Avg/Max     | 3096 / 3333.33 / 3496 |
|   Off-heap size Min/Avg/Max | 0 / 0.00 / 0          |
+-----------------------------------------------------+

Nodes for: TESTITEMCACHE(@c0)
+================================================================================================================+
|       Node ID8(@), IP        | CPUs | Heap Used | CPU Load |   Up Time    |   
      Size         | Hi/Mi/Rd/Wr |
+================================================================================================================+
| 88C3570D(@n0), ip1 | 8    | 1.91 %    | 0.27 %   | 00:07:46:108 | Total: 3496 
         | Hi: 0       |
|                              |      |           |          |              |   
Heap: 3496         | Mi: 0       |
|                              |      |           |          |              |   
Off-Heap: 0        | Rd: 0       |
|                              |      |           |          |              |   
Off-Heap Memory: 0 | Wr: 0       |
+------------------------------+------+-----------+----------+--------------+----------------------+-------------+
| D5DF19FC(@n2), ip3 | 8    | 1.84 %    | 0.23 %   | 00:07:33:386 | Total: 3096 
         | Hi: 0       |
|                              |      |           |          |              |   
Heap: 3096         | Mi: 0       |
|                              |      |           |          |              |   
Off-Heap: 0        | Rd: 0       |
|                              |      |           |          |              |   
Off-Heap Memory: 0 | Wr: 0       |
+------------------------------+------+-----------+----------+--------------+----------------------+-------------+
| E5A391F6(@n1), ip2 | 8    | 0.97 %    | 0.80 %   | 00:07:42:393 | Total: 3408 
         | Hi: 0       |
|                              |      |           |          |              |   
Heap: 3408         | Mi: 0       |
|                              |      |           |          |              |   
Off-Heap: 0        | Rd: 0       |
|                              |      |           |          |              |   
Off-Heap Memory: 0 | Wr: 0       |
+----------------------------------------------------------------------------------------------------------------+
'Hi' - Number of cache hits.
'Mi' - Number of cache misses.
'Rd' - number of cache reads.
'Wr' - Number of cache writes.

Aggregated queries metrics:
  Minimum execution time: 00:00:00:000
  Maximum execution time: 00:00:00:000
  Average execution time: 00:00:00:000
  Total number of executions: 0
  Total number of failures:   0
visor>



What am i doing wrong?
Tuco


________________________________
If you reply to this email, your message will be added to the discussion below:
http://apache-ignite-users.70518.x6.nabble.com/Affinity-key-does-not-seem-to-be-working-tp14043.html
To unsubscribe from Apache Ignite Users, click 
here<http://apache-ignite-users.70518.x6.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=1&code=bWF4bnUwMEBob3RtYWlsLmNvbXwxfDE2MTc2ODgyNTA=>.
NAML<http://apache-ignite-users.70518.x6.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>




--
View this message in context: 
http://apache-ignite-users.70518.x6.nabble.com/Affinity-key-does-not-seem-to-be-working-tp14043p14048.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Reply via email to