Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getDistributedObjects() not reporting persisted objects after HotRestart #15930

Closed
francesco-hz opened this issue Nov 5, 2019 · 1 comment
Closed

Comments

@francesco-hz
Copy link

@francesco-hz francesco-hz commented Nov 5, 2019

Follow up from ZD 5652.
Running the attached piece of code, we can see that getDistributedObjects() is not reporting any persistent objects which were restored after a node restart, unless a proxy for the object is created first. Thank you to @neilstevenson for the contribution !

To reproduce, run this class twice. Code will create two persistent objects, but only one will be reported by getDistributedObjects() after performing a restart.

import com.hazelcast.config.Config;
import com.hazelcast.config.HotRestartConfig;
import com.hazelcast.config.HotRestartPersistenceConfig;
import com.hazelcast.config.MapConfig;
import com.hazelcast.core.DistributedObject;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;

import java.io.File;
import java.util.Collection;
import java.util.concurrent.TimeUnit;

public class GetDistObjectsTest {
    public static void main(String[] args) throws Exception {
        HazelcastInstance server = Hazelcast.newHazelcastInstance(getServerConfig());

        TimeUnit.SECONDS.sleep(5L);
        printDistributedObjects("START", server);

        IMap<String, String> controlMap = server.getMap("control");

        if (controlMap.isEmpty()) {
            System.out.println("Control Map is empty, first run, create data");

            IMap<String, String> anotherMap = server.getMap("another");
            anotherMap.put("hello", "world");
            controlMap.put("hello", "world");
        } else {
            // Do not access "another" map by name
            System.out.println("Control Map is empty, second run, HR loaded");
        }

        TimeUnit.SECONDS.sleep(5L);
        printDistributedObjects("END", server);

        server.shutdown();
    }

    public static Config getServerConfig() {
        Config config = new Config();

        config.setLicenseKey("your enterprise license here");
        config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);

        config.getManagementCenterConfig().setEnabled(true).setUrl("http://localhost:8080/hazelcast-mancenter");

        HotRestartPersistenceConfig hotRestartPersistenceConfig = config.getHotRestartPersistenceConfig();
        hotRestartPersistenceConfig.setEnabled(true);
        hotRestartPersistenceConfig.setBaseDir(new File("hr"));

        HotRestartConfig hotRestartConfig = new HotRestartConfig();
        hotRestartConfig.setEnabled(true);

        MapConfig mapConfig = new MapConfig();
        mapConfig.setName("default");
        mapConfig.setHotRestartConfig(hotRestartConfig);

        config.getMapConfigs().put(mapConfig.getName(), mapConfig);

        return config;
    }

    public static void printDistributedObjects(String prefix, HazelcastInstance hazelcastInstance) {
        Collection<DistributedObject> dObjects = hazelcastInstance.getDistributedObjects();

        System.out.println(prefix + ": getDistributedObjects(), size==" + dObjects.size());
        dObjects.stream()
                .filter(dObject -> dObject instanceof IMap)
                .forEach(dObject ->
                        System.out.println(prefix + ":    IMap, name==" + dObject.getName()
                                + " size==" + ((IMap<?,?>) dObject).size()));
    }

}

The first run will show:

START: getDistributedObjects(), size==0
END: getDistributedObjects(), size==2
END: IMap, name==another size==1
END: IMap, name==control size==1

The second run will show:

START: getDistributedObjects(), size==0
Control Map is empty, second run, HR loaded
END: getDistributedObjects(), size==1
END: IMap, name==control size==1

If this is working as expected, perhaps this test case should be mentioned in IMDG ref guide or this API's javadoc, where we state:

The results are returned on a best-effort basis. The result might miss just-created objects and contain just-deleted objects. An existing object can also be missing from the list occasionally. One cluster member is queried to obtain the list.

Thank you. F.

@vojtechtoman

This comment has been minimized.

Copy link
Contributor

@vojtechtoman vojtechtoman commented Nov 29, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.