Search code examples
javapersistencehazelcast

Hazelcast eviction and distributed queries


Here you can read how a query (not a get operation) works in Hazelcast:

  1. The requested predicate is sent to each member in the cluster.
  2. Each member looks at its own local entries and filters them according to the predicate. At this stage, key/value pairs of the entries are deserialized and then passed to the predicate.
  3. The predicate requester merges all the results coming from each member into a single set.

But it is hard to find explicit details on what happens when some entries have been evicted. Assuming a MapStore has been provided for the targeted maps, will queries perform a loadAll? Is it possible to define a behaviour for this situation as for load or store?

I suspect that the answer in both cases is NO (I couldn't find a method to handle queries, in relation to store, in the MapStore interface):

public interface MapStore<K, V> extends MapLoader<K, V> {
    void store(K var1, V var2);

    void storeAll(Map<K, V> var1);

    void delete(K var1);

    void deleteAll(Collection<K> var1);
}

public interface MapLoader<K, V> {
    V load(K var1);

    Map<K, V> loadAll(Collection<K> var1);

    Set<K> loadAllKeys();
}

Thus the same query, executed at different times over the same map not modified by other ways than eviction, could provide different result sets.

I hoped to see something like:

    /* Fetch all query matches and return them */
    Map<K, V> loadQueryMatches(Predicate<K,V> p)

Or:

    /* Fetch all query matches and return them */
    Map<K, V> loadQueryMatches(String hzQuery)

Sadly, it isn't there. But what is the point of providing map queries if, with some configurations, their bahaviour may seem undeterministic because of the lack of some entries after evictions? Do you know if it is planned to include a method like loadQueryMatches?


Solution

  • Queries are meaningful if you use map as a datagrid rather than cache, namely when there is no eviction defined for the map.

    If a method like loadQueryMatches is introduced; then all query operations should do the query from data store because you can not be sure if the map includes all items (there may be some items evicted). It will not make use of IMap, because each query request will be forwarded to database.