首页 > 解决方案 > apache点燃加载缓存ClassCastException

问题描述

我正在尝试使用 apache ignite,我正在使用 ignite Web 控制台生成我的节点。

我需要从数据库配置 2 个缓存并启用持久存储,因为这两个表有很多数据。

这是我所做的(控制台)


    /**
     * Configure grid.
     * 
     * @return Ignite configuration.
     * @throws Exception If failed to construct Ignite configuration instance.
     **/
    public static IgniteConfiguration createConfiguration() throws Exception {
        IgniteConfiguration cfg = new IgniteConfiguration();

        cfg.setClientMode(true);
        cfg.setIgniteInstanceName("attiryak");

        TcpDiscoverySpi discovery = new TcpDiscoverySpi();

        TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();

        ipFinder.setAddresses(Arrays.asList("127.0.0.1:47500..47510"));

        discovery.setIpFinder(ipFinder);

        cfg.setDiscoverySpi(discovery);

        AtomicConfiguration atomicCfg = new AtomicConfiguration();

        atomicCfg.setCacheMode(CacheMode.LOCAL);

        cfg.setAtomicConfiguration(atomicCfg);

        DataStorageConfiguration dataStorageCfg = new DataStorageConfiguration();

        dataStorageCfg.setPageSize(16384);
        dataStorageCfg.setConcurrencyLevel(2);
        dataStorageCfg.setSystemRegionInitialSize(52428800L);
        dataStorageCfg.setSystemRegionMaxSize(209715200L);

        DataRegionConfiguration dataRegionCfg = new DataRegionConfiguration();

        dataRegionCfg.setInitialSize(536870912L);
        dataRegionCfg.setMaxSize(1073741824L);
        dataRegionCfg.setMetricsEnabled(true);
        dataRegionCfg.setPersistenceEnabled(true);

        dataStorageCfg.setDefaultDataRegionConfiguration(dataRegionCfg);

        cfg.setDataStorageConfiguration(dataStorageCfg);

        cfg.setCacheConfiguration(
            cacheMInoutlineCache(),
            cacheMInoutlineconfirmCache()
        );

        return cfg;
    }
    public static CacheConfiguration cacheMInoutlineCache() throws Exception {
        CacheConfiguration ccfg = new CacheConfiguration();

        ccfg.setName("MInoutlineCache");
        ccfg.setCacheMode(CacheMode.LOCAL);
        ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
        ccfg.setCopyOnRead(true);

        CacheJdbcPojoStoreFactory cacheStoreFactory = new CacheJdbcPojoStoreFactory();

        cacheStoreFactory.setDataSourceFactory(new Factory<DataSource>() {
            /** {@inheritDoc} **/
            @Override public DataSource create() {
                return DataSources.INSTANCE_dsOracle_Compiere;
            };
        });

        cacheStoreFactory.setDialect(new OracleDialect());

        cacheStoreFactory.setTypes(jdbcTypeMInoutline(ccfg.getName()));

        ccfg.setCacheStoreFactory(cacheStoreFactory);

        ccfg.setReadThrough(true);
        ccfg.setWriteThrough(true);

        ArrayList<QueryEntity> qryEntities = new ArrayList<>();

        QueryEntity qryEntity = new QueryEntity();

        qryEntity.setKeyType("java.lang.Long");
        qryEntity.setValueType("com.gmail.talcorpdz.model.MInoutline");
        qryEntity.setTableName("M_INOUTLINE");
        qryEntity.setKeyFieldName("mInoutlineId");

        HashSet<String> keyFields = new HashSet<>();

        keyFields.add("mInoutlineId");

        qryEntity.setKeyFields(keyFields);

        LinkedHashMap<String, String> fields = new LinkedHashMap<>();

        fields.put("adClientId", "java.lang.Long");

        qryEntity.setFields(fields);

        HashMap<String, String> aliases = new HashMap<>();

        aliases.put("mInoutlineId", "M_INOUTLINE_ID");
        qryEntity.setAliases(aliases);

        ArrayList<QueryIndex> indexes = new ArrayList<>();

        QueryIndex index = new QueryIndex();

        index.setName("IDX$$_00010002");
        index.setIndexType(QueryIndexType.SORTED);

        LinkedHashMap<String, Boolean> indFlds = new LinkedHashMap<>();

        indFlds.put("mAttributesetinstanceId", false);
        indFlds.put("mInoutId", false);
        qryEntity.setIndexes(indexes);
        qryEntities.add(qryEntity);

        ccfg.setQueryEntities(qryEntities);

        /**
         * @author taleb 
         * 
         * spec 1.0 : no schema needed solution
         * https://stackoverflow.com/a/58930331/4388228
         * */
        ccfg.setSqlSchema("PUBLIC");

        return ccfg;
    }

我相信我错过了配置我的存储,因为必须帮助内存使用我的磁盘空间。

这是异常的堆栈跟踪

[11:49:58]    __________  ________________ 
[11:49:58]   /  _/ ___/ |/ /  _/_  __/ __/ 
[11:49:58]  _/ // (7 7    // /  / / / _/   
[11:49:58] /___/\___/_/|_/___/ /_/ /___/  
[11:49:58] 
[11:49:58] ver. 2.7.6#20190911-sha1:21f7ca41
[11:49:58] 2019 Copyright(C) Apache Software Foundation
[11:49:58] 
[11:49:58] Ignite documentation: http://ignite.apache.org
[11:49:58] 
[11:49:58] Quiet mode.
[11:49:58]   ^-- Logging by 'JavaLogger [quiet=true, config=null]'
[11:49:58]   ^-- To see **FULL** console log here add -DIGNITE_QUIET=false or "-v" to ignite.{sh|bat}
[11:49:58] 
[11:49:58] OS: Linux 4.19.0-kali5-amd64 amd64
[11:49:58] VM information: Java(TM) SE Runtime Environment 1.8.0_201-b09 Oracle Corporation Java HotSpot(TM) 64-Bit Server VM 25.201-b09
[11:49:58] Please set system property '-Djava.net.preferIPv4Stack=true' to avoid possible problems in mixed environments.
[11:49:58] Initial heap size is 124MB (should be no less than 512MB, use -Xms512m -Xmx512m).
[11:49:58] Configured plugins:
[11:49:58]   ^-- None
[11:49:58] 
[11:49:58] Configured failure handler: [hnd=StopNodeOrHaltFailureHandler [tryStop=false, timeout=0, super=AbstractFailureHandler [ignoredFailureTypes=[SYSTEM_WORKER_BLOCKED, SYSTEM_CRITICAL_OPERATION_TIMEOUT]]]]
[11:49:59] Message queue limit is set to 0 which may lead to potential OOMEs when running cache operations in FULL_ASYNC or PRIMARY_SYNC modes due to message queues growth on sender and receiver sides.
[11:49:59] Security status [authentication=off, tls/ssl=off]
[11:49:59] REST protocols do not start on client node. To start the protocols on client node set '-DIGNITE_REST_START_ON_CLIENT=true' system property.
[11:50:00] Nodes started on local machine require more than 80% of physical RAM what can lead to significant slowdown due to swapping (please decrease JVM heap size, data region size or checkpoint buffer size) [required=4979MB, available=7867MB]
[11:50:00] Performance suggestions for grid 'attiryak' (fix if possible)
[11:50:00] To disable, set -DIGNITE_PERFORMANCE_SUGGESTIONS_DISABLED=true
[11:50:00]   ^-- Enable G1 Garbage Collector (add '-XX:+UseG1GC' to JVM options)
[11:50:00]   ^-- Specify JVM heap max size (add '-Xmx<size>[g|G|m|M|k|K]' to JVM options)
[11:50:00]   ^-- Set max direct memory size if getting 'OOME: Direct buffer memory' (add '-XX:MaxDirectMemorySize=<size>[g|G|m|M|k|K]' to JVM options)
[11:50:00]   ^-- Disable processing of calls to System.gc() (add '-XX:+DisableExplicitGC' to JVM options)
[11:50:00] Refer to this page for more performance suggestions: https://apacheignite.readme.io/docs/jvm-and-system-tuning
[11:50:00] 
[11:50:00] To start Console Management & Monitoring run ignitevisorcmd.{sh|bat}
[11:50:00] Data Regions Configured:
[11:50:00]   ^-- default [initSize=512.0 MiB, maxSize=1.0 GiB, persistence=true]
[11:50:00] 
[11:50:00] Ignite node started OK (id=7ad24962, instance name=attiryak)
[11:50:00] >>> Ignite cluster is not active (limited functionality available). Use control.(sh|bat) script or IgniteCluster interface to activate.
[11:50:00] Topology snapshot [ver=2, locNode=7ad24962, servers=1, clients=1, state=INACTIVE, CPUs=8, offheap=2.0GB, heap=3.4GB]
>> Loading caches...
Nov 19, 2019 11:50:01 AM org.apache.ignite.logger.java.JavaLogger error
SEVERE: Failed to activate node components [nodeId=7ad24962-e5c8-4f0b-8b99-1c42a3c91c01, client=true, topVer=AffinityTopologyVersion [topVer=2, minorTopVer=1]]
java.lang.ClassCastException: org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl cannot be cast to org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx
    at org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager.getOrAllocateCacheMetas(GridCacheOffheapManager.java:728)
    at org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager.initDataStructures(GridCacheOffheapManager.java:123)
    at org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl.start(IgniteCacheOffheapManagerImpl.java:196)
    at org.apache.ignite.internal.processors.cache.CacheGroupContext.start(CacheGroupContext.java:937)
    at org.apache.ignite.internal.processors.cache.GridCacheProcessor.startCacheGroup(GridCacheProcessor.java:2251)
    at org.apache.ignite.internal.processors.cache.GridCacheProcessor.prepareCacheStart(GridCacheProcessor.java:2146)
    at org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager.processCacheStartRequests(CacheAffinitySharedManager.java:898)
    at org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager.onCacheChangeRequest(CacheAffinitySharedManager.java:798)
    at org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.onClusterStateChangeRequest(GridDhtPartitionsExchangeFuture.java:1114)
    at org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.init(GridDhtPartitionsExchangeFuture.java:736)
    at org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$ExchangeWorker.body0(GridCachePartitionExchangeManager.java:2681)
    at org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$ExchangeWorker.body(GridCachePartitionExchangeManager.java:2553)
    at org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:120)
    at java.lang.Thread.run(Thread.java:748)

>> Loading cache: MInoutlineCache
Nov 19, 2019 11:50:02 AM org.apache.ignite.logger.java.JavaLogger error
SEVERE: Failed to process custom exchange task: ClientCacheChangeDummyDiscoveryMessage [reqId=587e6edb-95ee-4208-a525-a35ca441bf7c, cachesToClose=null, startCaches=[MInoutlineCache]]
java.lang.ClassCastException: org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl cannot be cast to org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx
    at org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager.getOrAllocateCacheMetas(GridCacheOffheapManager.java:728)
    at org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager.initDataStructures(GridCacheOffheapManager.java:123)
    at org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl.start(IgniteCacheOffheapManagerImpl.java:196)
    at org.apache.ignite.internal.processors.cache.CacheGroupContext.start(CacheGroupContext.java:937)
    at org.apache.ignite.internal.processors.cache.GridCacheProcessor.startCacheGroup(GridCacheProcessor.java:2251)
    at org.apache.ignite.internal.processors.cache.GridCacheProcessor.prepareCacheStart(GridCacheProcessor.java:2146)
    at org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager.processClientCacheStartRequests(CacheAffinitySharedManager.java:438)
    at org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager.processClientCachesChanges(CacheAffinitySharedManager.java:637)
    at org.apache.ignite.internal.processors.cache.GridCacheProcessor.processCustomExchangeTask(GridCacheProcessor.java:391)
    at org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$ExchangeWorker.processCustomTask(GridCachePartitionExchangeManager.java:2489)
    at org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$ExchangeWorker.body0(GridCachePartitionExchangeManager.java:2634)
    at org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$ExchangeWorker.body(GridCachePartitionExchangeManager.java:2553)
    at org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:120)
    at java.lang.Thread.run(Thread.java:748)

我该怎么做才能解决这个问题?

标签: javaignite

解决方案


这是一个已知问题,它源于您之前启动了同一个集群但没有持久性的事实。

请删除您的 Ignite 工作目录(%TMP%\ignite\work 或 /tmp/ignite/work 或 ./ignite/work)并重新启动您的节点。

UPD:还有关于持久性客户端节点上的本地缓存的问题:IGNITE-11677。我的建议是完全避免使用本地缓存。


推荐阅读