Hendy Irawan
Hendy Irawan

Reputation: 21424

Why class-based cache entries gone after GridGain node stopped?

Code:

public static class Oya {
    String name;

    public Oya(String name) {
        super();
        this.name = name;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return "Oya [name=" + name + "]";
    }

}

public static void main(String[] args) throws GridException {
    try (Grid grid = GridGain.start(
            System.getProperty("user.home") + "/gridgain-platform-os-6.1.9-nix/examples/config/example-cache.xml")) {
        GridCache<Integer, Oya> cache = grid.cache("partitioned");
        boolean success2 = cache.putxIfAbsent(3, new Oya("3"));
        log.info("Current 3 value = {}", cache.get(3));
        cache.transform(3, (it) -> new Oya(it.name + "-transformed"));
        log.info("Transformed 3 value = {}", cache.get(3));
    }
}
  1. Start another GridGain node.
  2. Run the code. It should print: 3-transformed
  3. Comment the putxIfAbsent() code.
  4. Run the code. I expected it to print: 3-transformed but got null instead

The code will work if I change the cache value to a String (like in GridGain Basic Operations video) or a Java builtin value, but not for my own custom class.

Upvotes: 0

Views: 129

Answers (1)

Dmitriy
Dmitriy

Reputation: 2292

Peer-deployment for data grid is a development-only feature. The contract of a SHARED mode is that whenever last node which had original class definition leaves, all classes will be undeployed. For Data Grid it means that the cache will be cleared. This is useful for cases when you change class definitions.

In CONTINUOUS mode, cache classes never get undeployed, but in this case you must be careful not to change definitions of classes without restarting the grid nodes.

For more information see Deployment Modes documentation.

Upvotes: 1

Related Questions