title: Enabling or Disabling MapLoader/MapStore, or promoting/demoting client to server or server to client dynamically in Hazelcast
body: <p>I'm trying to set up a replicated Hazelcast cluster, by which there are between 1-2 servers at any time and N number of clients who all share the same replicated information. I plan to upgrade Hazelcast soon, but the current version I'm locked into is Hazelcast 2.1.2.</p>
  
  <p>All I really want is for both servers to remain a server, but for Hazelcast to not consider it as capable of servicing <a href="http://docs.hazelcast.org/docs/2.1/javadoc/com/hazelcast/core/MapLoader.html" rel="nofollow noreferrer">MapLoader</a>/<a href="http://docs.hazelcast.org/docs/2.1/javadoc/com/hazelcast/core/MapStore.html" rel="nofollow noreferrer">MapStore</a> requests except for when I signal that it is capable. The other alternative is to be able to seamlessly promote a client to a server while simultaneously demoting the opposite server to a client, without a need for re-replicating the entire cache.</p>
  
  <p>The issue is that I want to set up only one of the two servers to do any MapLoader/MapStore work. Basically only one of the two servers is capable of doing this work at any time, for reasons I cannot control, so I need only one of the two of them to be allowed to do it at any time. The issue is, that if both servers are connected to the cluster, then the cluster expects both of them to be able to service the request, by which only one does when another node (the non-active server, or any of the clients) requests information and I end up with no data for roughly half of the requests.</p>
  
  <p>Obviously if I lose all the servers, the cluster goes away entirely and the clients are disconnected and I don't see a version to dynamically change Hazelcast at runtime. Not that I can upgrade just yet, but even in Hazelcast 3.9 I don't really see a way to do this <a href="http://docs.hazelcast.org/docs/latest-development/manual/html/Understanding_Configuration/Dynamically_Adding_Configuration_on_a_Cluster.html" rel="nofollow noreferrer">Dynamic Configuration in 3.9</a> because for starters you can only add to a configuration, but on top of that the server seems to still be meant to service server requests as well.</p>
  
  <p>So, what I have tried, is connecting one of the servers with the default MapStoreConfig, but that doesn't work because it's still a server, and still ends up with half of the MapLoader/MapStore requests, so my clients only get half of the data. Additionally, this also shares a speed problem to doing this same technique but with a client connection, below.</p>
  
  <p>For a client connection, I do much of the same thing. I connect a client while the server is still running, and then I call out to <code>HazelcastInstance#getLifecycleService()#shutdown()</code> on the old server logic (or vice versa, by connecting a server with the client still running).</p>
  
  <pre><code>//config specifies MapLoader/MapStore for FOO_CACHE and the map/queue/etc
  //that I want to use
  Config config = ...;
  HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
  ...
  //something happened where this node isn't capable of loading/storing
  //data any longer
  HazelcastInstance oldInstance = instance;
  ClientConfig clientConfig = new ClientConfig();
  clientConfig.getGroupConfig().setName("FOO_CACHE").setPassword("my_password");
  clientConfig.addAddress("127.0.0.1:5700");
  instance = HazelcastClient.newHazelcastClient(clientConfig);
  oldInstance.getLifecycleService().shutdown();
  </code></pre>
  
  <p>This technically works but this is a little time consuming because when this server swap happens it means something big is going on and it needs to be fast. I have only tested with very small amounts of data in the cache, but I suspect this could be worse when data needs to be replicated across to the new instance with a large cache (i.e. the new instance needs to connect to the cluster, and now the cluster needs to replicate the data out to the new instance, then the old Hazelcast instance's data is dumped when it disconnects from the cluster).</p>
  
  <p>What I'd like, is that the server's replicated data still stays as is, but it is just 'signaled' in some way to the cluster that it isn't capable of loading or storing data that is added or requested by the cluster. In this way, I'd like to avoid the re-replication of the data to a newly created instance, and the reconnection time for the new instance.</p>
  
  <p>Is this possible in any other way than doing the HazelcastClient -> Server technique I mentioned above?</p>
  
  <p>EDIT:
  I also tried this, but it doesn't seem to have any effect at all (still receives requests, and it even still attempts to process them):</p>
  
  <pre><code>instance.getConfig().getMapConfig("map_example_in_cache")
          .getMapStoreConfig().setEnabled(false);
  </code></pre>