I have a very simple requirement to get All values stored in the IMap. I have a server and client on the same box (no cluster just one instance of server and one instance of the client).
Server start:
Config config = new Config();
NetworkConfig network = config.getNetworkConfig();
JoinConfig join = network.getJoin();
join.getMulticastConfig().setEnabled( false );
join.getTcpIpConfig().setEnabled( false );
join.getAwsConfig().setEnabled(false);
HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
Client start:
ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig().addAddress("127.0.0.1");
HazelcastClient hazelIns = HazelcastClient.newHazelcastClient(clientConfig);
IMap<String,DeviceStatus> map = hazelIns.getMap("map");
Query:
class DeviceStatus{
String name;
String status;
DeviceStatus(String name,String status){
this.name=name;
this.status= status;
}
// PUT ALL OBJECTS
for(int i =0;i<1000;i++){
DeviceStatus status = new DeviceStatus("Device"+i,"UP");
map.put(status.getName(),status);
}
for(int i=0; i< 10000; i++){
List<DeviceStatus> list = (List<DeviceStatus>)hazelIns.getMap("map").values();
if(list.size() != 1000){
System.out.println("ALL SIZE "+ list.size());
}
String sql = "name ilike %D%";
List<DeviceStatus> list1 = hazelIns.getMap("map").values( new SqlPredicate( sql ));
if(list1.size() != 1000){
System.out.println("SQL SIZE "+ list1.size());
}
Thread.sleep(1000);
}
Hazelcast version:
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>3.7.3</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-client</artifactId>
<version>3.7.3</version>
</dependency>
I am getting size miss-match size() sometimes from 1 to 1000 but I get 1000 size for majority of time. There is NO near-realtime cache. Why there is an inconsistent result set for both SQL and total size? Just FYI, cache key is updated in the background but never removed.
Any pointer is would be a great help!
Updated: Background update in a separate thread:
run(){
for(int i=0; i < 10; i++){
DeviceStatus status = new DeviceStatus("Device"+i,"DOWN");
map.put(status.getName(),status);
}
Thanks, Bhavesh