Search code examples
ignite

Ignite: ClassNotFoundException for a class of another service


I created a spring service (Service A) which uses an Ignite Cache. The Ignite Cache preloads data from a database using the CacheStoreAdapter. The cache configuration is:

final CacheConfiguration<String, StandardItem> cacheConfiguration = new CacheConfiguration<>(Identifiers.IGNITE_ITEM);

cacheConfiguration.setName(Identifiers.IGNITE_ITEM);
cacheConfiguration.setIndexedTypes(String.class, IgniteItem.class);
cacheConfiguration.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
cacheConfiguration.setCacheStoreFactory(FactoryBuilder.factoryOf(StandardItemCacheStore.class.getName()));
cacheConfiguration.setReadThrough(true);
cacheConfiguration.setWriteThrough(true);
cacheConfiguration.setCopyOnRead(false);
cacheConfiguration.setCacheMode(CacheMode.LOCAL);
cacheConfiguration.setOnheapCacheEnabled(true);

return cacheConfiguration;

The service itself is working great. But I have another service (Service B) which uses Ignite on the same network. The Configuration of the other service is the following:

final CacheConfiguration<String, String> cacheConfiguration = new CacheConfiguration<>(Constants.IGNITE_RESULT_CACHE);

cacheConfiguration.setName(Constants.IGNITE_RESULT_CACHE);
cacheConfiguration.setIndexedTypes(String.class, String.class);
cacheConfiguration.setAtomicityMode(CacheAtomicityMode.ATOMIC);
cacheConfiguration.setCopyOnRead(false);
cacheConfiguration.setCacheMode(CacheMode.LOCAL);
cacheConfiguration.setOnheapCacheEnabled(true);
cacheConfiguration.setEvictionPolicy(new LruEvictionPolicy(1_000_000));

final IgniteConfiguration igniteConfiguration = new IgniteConfiguration();
igniteConfiguration.setIgniteInstanceName("ServiceGrid");
igniteConfiguration.setCacheConfiguration(cacheConfiguration);
igniteConfiguration.setIncludeEventTypes();

return igniteConfiguration;

But for this service now I get exceptions:

2017-12-01 10:25:39.512 ERROR 39 --- [34%ServiceGrid%] .c.d.d.p.GridDhtPartitionsExchangeFuture : Failed to reinitialize local partitions (preloading will be stopped): GridDhtPartitionExchangeId [topVer=AffinityTopologyVersion [topVer=6, minorTopVer=1], nodeId=79de964e, evt=DISCOVERY_CUSTOM_EVT]

java.lang.RuntimeException: Failed to create an instance of io.mio.scap.dao.cache.IgniteItemCacheStore
        at javax.cache.configuration.FactoryBuilder$ClassFactory.create(FactoryBuilder.java:134) ~[cache-api-1.0.0.jar!/:na]
        at org.apache.ignite.internal.processors.cache.GridCacheProcessor.createCache(GridCacheProcessor.java:1392) ~[ignite-core-2.2.0.jar!/:2.2.0]
        at org.apache.ignite.internal.processors.cache.GridCacheProcessor.prepareCacheStart(GridCacheProcessor.java:1867) ~[ignite-core-2.2.0.jar!/:2.2.0]
        at org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager.onCacheChangeRequest(CacheAffinitySharedManager.java:748) ~[ignite-core-2.2.0.jar!/:2.2.0]
        at org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.onCacheChangeRequest(GridDhtPartitionsExchangeFuture.java:838) ~[ignite-core-2.2.0.jar!/:2.2.0]
        at org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.init(GridDhtPartitionsExchangeFuture.java:579) ~[ignite-core-2.2.0.jar!/:2.2.0]
        at org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$ExchangeWorker.body(GridCachePartitionExchangeManager.java:1901) [ignite-core-2.2.0.jar!/:2.2.0]
        at org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:110) [ignite-core-2.2.0.jar!/:2.2.0]
        at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]
Caused by: java.lang.ClassNotFoundException: io.mio.scap.dao.cache.IgniteItemCacheStore
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_151]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_151]
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:93) ~[app.jar:na]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_151]
        at javax.cache.configuration.FactoryBuilder$ClassFactory.create(FactoryBuilder.java:130) ~[cache-api-1.0.0.jar!/:na]
        ... 8 common frames omitted

2017-12-01 10:25:39.513  INFO 39 --- [34%ServiceGrid%] .c.d.d.p.GridDhtPartitionsExchangeFuture : Snapshot initialization completed [topVer=AffinityTopologyVersion [topVer=6, minorTopVer=1], time=0ms]
2017-12-01 10:25:39.516 ERROR 39 --- [34%ServiceGrid%] .i.p.c.GridCachePartitionExchangeManager : Failed to wait for completion of partition map exchange (preloading will not start): GridDhtPartitionsExchangeFuture [dummy=false, forcePreload=false, reassign=false, discoEvt=DiscoveryCustomEvent [customMsg=null, affTopVer=AffinityTopologyVersion [topVer=6, minorTopVer=1], super=DiscoveryEvent [evtNode=TcpDiscoveryNode [id=79de964e-08e9-4a09-b915-4a221d10c642, addrs=[127.0.0.1, 172.19.0.10], sockAddrs=[1f3ec767d8a2/172.19.0.10:47500, /127.0.0.1:47500], discPort=47500, order=6, intOrder=6, lastExchangeTime=1512123936779, loc=false, ver=2.2.0#20170915-sha1:5747ce6b, isClient=false], topVer=6, nodeId8=68a843cf, msg=null, type=DISCOVERY_CUSTOM_EVT, tstamp=1512123939493]], crd=TcpDiscoveryNode [id=6e5c36ce-5042-4f9b-b507-3f9ed4eb1384, addrs=[127.0.0.1, 172.19.0.11], sockAddrs=[5b8f17420165/172.19.0.11:47500, /127.0.0.1:47500], discPort=47500, order=1, intOrder=1, lastExchangeTime=1512123917048, loc=false, ver=2.2.0#20170915-sha1:5747ce6b, isClient=false], exchId=GridDhtPartitionExchangeId [topVer=AffinityTopologyVersion [topVer=6, minorTopVer=1], nodeId=79de964e, evt=DISCOVERY_CUSTOM_EVT], added=true, initFut=GridFutureAdapter [ignoreInterrupts=false, state=DONE, res=false, hash=2088336463], init=false, lastVer=null, partReleaseFut=null, exchActions=null, affChangeMsg=null, skipPreload=false, clientOnlyExchange=false, initTs=1512123939493, centralizedAff=false, changeGlobalStateE=null, forcedRebFut=null, done=true, evtLatch=0, remaining=[a9181efd-950b-4d23-9697-a301c81094aa, 2fd78465-8a0f-4318-bded-716348753cef, 79de964e-08e9-4a09-b915-4a221d10c642, 3fa0ac5d-c464-46a7-9dac-c56873b64dd0, 6e5c36ce-5042-4f9b-b507-3f9ed4eb1384], super=GridFutureAdapter [ignoreInterrupts=false, state=DONE, res=java.lang.RuntimeException: Failed to create an instance of io.mio.scap.dao.cache.IgniteItemCacheStore, hash=1326392751]]

org.apache.ignite.IgniteCheckedException: Failed to create an instance of io.mio.scap.dao.cache.IgniteItemCacheStore
        at org.apache.ignite.internal.util.IgniteUtils.cast(IgniteUtils.java:7229) ~[ignite-core-2.2.0.jar!/:2.2.0]
        at org.apache.ignite.internal.util.future.GridFutureAdapter.resolve(GridFutureAdapter.java:258) ~[ignite-core-2.2.0.jar!/:2.2.0]
        at org.apache.ignite.internal.util.future.GridFutureAdapter.get0(GridFutureAdapter.java:206) ~[ignite-core-2.2.0.jar!/:2.2.0]
        at org.apache.ignite.internal.util.future.GridFutureAdapter.get(GridFutureAdapter.java:158) ~[ignite-core-2.2.0.jar!/:2.2.0]
        at org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$ExchangeWorker.body(GridCachePartitionExchangeManager.java:1911) ~[ignite-core-2.2.0.jar!/:2.2.0]
        at org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:110) [ignite-core-2.2.0.jar!/:2.2.0]
        at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]
Caused by: java.lang.RuntimeException: Failed to create an instance of io.mio.scap.dao.cache.IgniteItemCacheStore
        at javax.cache.configuration.FactoryBuilder$ClassFactory.create(FactoryBuilder.java:134) ~[cache-api-1.0.0.jar!/:na]
        at org.apache.ignite.internal.processors.cache.GridCacheProcessor.createCache(GridCacheProcessor.java:1392) ~[ignite-core-2.2.0.jar!/:2.2.0]
        at org.apache.ignite.internal.processors.cache.GridCacheProcessor.prepareCacheStart(GridCacheProcessor.java:1867) ~[ignite-core-2.2.0.jar!/:2.2.0]
        at org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager.onCacheChangeRequest(CacheAffinitySharedManager.java:748) ~[ignite-core-2.2.0.jar!/:2.2.0]
        at org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.onCacheChangeRequest(GridDhtPartitionsExchangeFuture.java:838) ~[ignite-core-2.2.0.jar!/:2.2.0]
        at org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.init(GridDhtPartitionsExchangeFuture.java:579) ~[ignite-core-2.2.0.jar!/:2.2.0]
        at org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$ExchangeWorker.body(GridCachePartitionExchangeManager.java:1901) ~[ignite-core-2.2.0.jar!/:2.2.0]
        ... 2 common frames omitted
Caused by: java.lang.ClassNotFoundException: io.mio.scap.dao.cache.IgniteItemCacheStore
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_151]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_151]
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:93) ~[app.jar:na]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_151]
        at javax.cache.configuration.FactoryBuilder$ClassFactory.create(FactoryBuilder.java:130) ~[cache-api-1.0.0.jar!/:na]
        ... 8 common frames omitted

2017-12-01 10:25:40.890  INFO 39 --- [34%ServiceGrid%] o.apache.ignite.internal.exchange.time   : Started exchange init [topVer=AffinityTopologyVersion [topVer=6, minorTopVer=2], crd=false, evt=18, node=TcpDiscoveryNode [id=68a843cf-2970-4f2a-930b-c9a36b3942ce, addrs=[127.0.0.1, 172.19.0.9], sockAddrs=[/127.0.0.1:47500, 2a1936cdc613/172.19.0.9:47500], discPort=47500, order=4, intOrder=4, lastExchangeTime=1512123940480, loc=true, ver=2.2.0#20170915-sha1:5747ce6b, isClient=false], evtNode=TcpDiscoveryNode [id=68a843cf-2970-4f2a-930b-c9a36b3942ce, addrs=[127.0.0.1, 172.19.0.9], sockAddrs=[/127.0.0.1:47500, 2a1936cdc613/172.19.0.9:47500], discPort=47500, order=4, intOrder=4, lastExchangeTime=1512123940480, loc=true, ver=2.2.0#20170915-sha1:5747ce6b, isClient=false], customEvt=CacheAffinityChangeMessage [id=2b0ab911061-e15fbf79-7ad2-420e-b870-5a61d94b442c, topVer=AffinityTopologyVersion [topVer=6, minorTopVer=0], exchId=null, partsMsg=null, exchangeNeeded=true]]
2017-12-01 10:25:40.896  INFO 39 --- [34%ServiceGrid%] .c.d.d.p.GridDhtPartitionsExchangeFuture : Finished waiting for partition release future [topVer=AffinityTopologyVersion [topVer=6, minorTopVer=2], waitTime=0ms]
2017-12-01 10:25:40.898  INFO 39 --- [34%ServiceGrid%] o.apache.ignite.internal.exchange.time   : Finished exchange init [topVer=AffinityTopologyVersion [topVer=6, minorTopVer=2], crd=false]
2017-12-01 10:25:40.970  INFO 39 --- [39%ServiceGrid%] .c.d.d.p.GridDhtPartitionsExchangeFuture : Snapshot initialization completed [topVer=AffinityTopologyVersion [topVer=6, minorTopVer=2], time=0ms]
2017-12-01 10:25:40.976  INFO 39 --- [34%ServiceGrid%] .i.p.c.GridCachePartitionExchangeManager : Skipping rebalancing (nothing scheduled) [top=AffinityTopologyVersion [topVer=6, minorTopVer=2], evt=DISCOVERY_CUSTOM_EVT, node=6e5c36ce-5042-4f9b-b507-3f9ed4eb1384]

My question now is: Why does Service B need to know/have the IgniteItemCacheStore which is not even used by that service, its only used by Service A.


Solution

  • All Ignite nodes need to have all caches' configurations, and cache store is a part of cache configuration, therefore all Ignite nodes need all classes used by cache store.

    There are ways of sidestep this, such as factory that returns lazily-initialized proxy of CacheStore, your mileage may vary.