|
Question |
If the DistributedMap API is being used with cache
replication enabled, why are the objects placed in the cache not being
replicated? |
|
|
|
Cause |
The replication service for a DistributedMap will only be
initialized when you use it. If the cache is defined using one of the
techniques, but not actually used in the application code, then the
replication service for that cache instance will not be initialized.
A DistributedMap can be initialized when the application code performs the
look-up operation.
Another way to initialize a DistributedMap is to call:
com.ibm.wsspi.cache.DistributedObjectCacheFactory.getMap(String)
com.ibm.wsspi.cache.DistributedObjectCacheFactory.getMap(String,
Properties)
As an example of this problem, say you have defined a cache instance named
services/cache/instance_one and enabled cache replication for the same.
The cache instance will not be initialized until you perform a look-up for
it.
The following code will initialize the cache and replication service:
InitialContext ic = new InitialContext();v
DistributedMap dm
=(DistributedMap)ic.lookup("services/cache/instance_one");
You will see the following lines in SystemOut.log:
[2008-07-10 18:56:01:828 EST] 0000002c CacheServiceI I DYNA1001I:
WebSphere Dynamic Cache instance named /cache/instance_one initialized
successfully.
[2008-07-10 18:56:02:828 EST] 00000042 DRSBootstrapM A CWWDR0001I:
Replication instance launched : /cache/instance_one
Notice that there will be a small delay between the initialization of the
cache instance and the replication service. This delay will normally be
around a second and it may be few seconds more if you have a large cluster
topology.
Here are the things that may happen when you try to deal with the cache
instance before it is completely replicated:
- If you try to put an object in the cache, it will not be
replicated immediately. It should still be replicated during
bootstrap.
- If you try to get an object that was supposed to be
replicated from a different cluster member, then the get operation may
fail to retrieve the object as the replication service is not ready.
This initialization only happens for the first look-up operation after
server start. Subsequent access of cache instance should not have this
issue. |
|
|
Answer |
The replication for a cache instance is complete when it has finished
bootstrapping, that is handshaking with the same cache instance on all the
other members/servers of the replication domain. Until this bootstrap is
done, users should expect to see a delay in their cache replication and
messages like the one pasted above.
Messages like "updatePeerCaches() DRS is not ready!! - CE will be sent
during bootstrap CE=" in the dynamic cache trace log indicate that
replication has not been initialized and setup is not complete for this
cache instance. All the cache data put into this cache instance cannot be
sent immediately to the servers. The cache data will be sent to other
servers during the process of bootstrap. The cache data for bootstrap is
only limited to the memory cache but not the disk cache, if disk offload
is enabled.
Typically the JNDI⢠look-up of the cache instance can be done in the init
method of a Servlet. So that, when service is called, the cache instance
and its replication service has been initialized successfully.
If you can not isolate the JNDI lookup of cache instance and are working
with the cache, it is suggested to add a small delay of about 1 to 5
seconds for the initial look-up. You may have to tune this delay depending
on your environment by reviewing the SystemOut.log file and finding the
actual time taken to launch the replication service.
The following code fragment may help:
InitialContext ic = new InitialContext();
DistributedMap dm
=(DistributedMap)ic.lookup("services/cache/instance_one");
if(firstAccess) {
firstAccess = false;
//Add delay to sleep for 5000ms.
Thread.sleep(5000);
}
// Hopefully by now, the replication instance is launched, you can
continue with the put or get operation on the DistributedMap object
dm.put(...);
MyObject obj = dm.get(...); |
|
|
|
|
|
|