0

I have apache-ignite running in a cluster with 3 nodes and populated it with some random data using a Long as the key.

IgniteCache<Long, String> cache = ignite.getOrCreateCache("myCache");
Map<Long, String> data = new HashMap<>();
data.put(1L,"Data for 1");
data.put(2L,"Data for 2");
cache.putAll(data);

for retrieval

Set<Long> keys = new HashSet<Long>(Arrays.asList(new Long[]{1L,2L}));
Map<Long,String> data = cache.getAll(keys);
data.forEach( (k,v) -> {
  System.out.println(k+" "+v);
});

This all works great but when changing the key of the map to a POJO I am unable to retrieve the data...

IgniteCache<IdTimeStamp, String> cache = ignite.getOrCreateCache("myCache");
Map<IdTimeStamp, String> data = new HashMap<>();
data.put(new IdTimeStamp(1L, 1514759400000L),"Data for 1514759400000");
data.put(new IdTimeStamp(1L, 1514757600000L),"Data for 1514757600000L");
cache.putAll(data);

for retrieval

    Set<IdTimeStamp> keys = new HashSet<IdTimeStamp>();
    keys.add(new IdTimeStamp(1L, 1514757600000L));
    keys.add(new IdTimeStamp(1L, 1514759400000L));
    Map<IdTimeStamp,String> data = cache.getAll(keys);
    System.out.println(data.size());
    data.forEach( (k,v) -> {
        System.out.println(k+" "+v);
    });

and the IdTimeStamp class:

public class IdTimeStamp  {

    private Long id;
    private Long timestamp;

    public IdTimeStamp(Long id, Long timestamp) {
        this.id = id;
        this.timestamp = timestamp;
    }
}
Steve
  • 24
  • 3

2 Answers2

0

Looks like a known limitation when you are using different clients for data population and retrieving the records. Take a look at this question if configuring compactFooter=true solves that problem.

clientConfig.setBinaryConfiguration(new BinaryConfiguration().setCompactFooter(true)

Otherwise, your code looks fine and should work as expected.

Alexandr Shapkin
  • 2,350
  • 1
  • 6
  • 10
-1

Not working:

ClientConfiguration cfg = new ClientConfiguration().setAddresses("127.0.0.1:10800");
IgniteClient client = Ignition.startClient(cfg);
ClientCache<IdTimeStamp, String> cache =  client.cache("myCache");

Working:

  public static IgniteCache<IdTimeStamp, String> getIgnite() {
        IgniteConfiguration cfg = new IgniteConfiguration();
        cfg.setClientMode(true);
        cfg.setPeerClassLoadingEnabled(false); //true ?? 

        // Setting up an IP Finder to ensure the client can locate the servers.
        TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
        ipFinder.setAddresses(Collections.singletonList("127.0.0.1:47500..47509"));

        TcpDiscoverySpi discoverySpi = new TcpDiscoverySpi();
        discoverySpi.setClientReconnectDisabled(true);
        discoverySpi.setIpFinder(ipFinder);

        cfg.setDiscoverySpi(discoverySpi);

        // Starting the node
        Ignite ignite = Ignition.start(cfg);

        // Create an IgniteCache and put some values in it.
        IgniteCache<IdTimeStamp, String> cache = ignite.getOrCreateCache("myCache");
        return cache;
    }
Steve
  • 24
  • 3