Репликация ehcache RMI: java.rmi.NoSuchObjectException: такого объекта нет в таблице - PullRequest
0 голосов
/ 04 сентября 2018

Я искал решение в сети, но не смог найти решение, которое у меня возникло с репликацией ehcache. Я использую ручную репликацию rmi между 2 серверами (сервер 1 = A.A.A.A и сервер 2 = B.B.B.B) и получаю эту ошибку:

2018-09-04 00:07:40,517 DEBUG [ehcache.distribution.RMICacheManagerPeerProvider] (req:) (Replication Thread:null) Lookup URL //B.B.B.B:40000/AddressDao
2018-09-04 00:07:40,522 WARN  [ehcache.distribution.RMIAsynchronousCacheReplicator] (req:) (Replication Thread:null) Unable to send message to remote peer.  Message was: no such object in table
java.rmi.NoSuchObjectException: no such object in table
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:283)
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:260)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:161)
    at net.sf.ehcache.distribution.RMICachePeer_Stub.send(Unknown Source)
    at net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator.writeReplicationQueue(RMIAsynchronousCacheReplicator.java:314)
    at net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator.replicationThreadMain(RMIAsynchronousCacheReplicator.java:127)
    at net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator.access$000(RMIAsynchronousCacheReplicator.java:58)
    at net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator$ReplicationThread.run(RMIAsynchronousCacheReplicator.java:389)

Версия

  • ehcache: 2.10.5
  • пружина: 4.3.9. РЕЛИЗ
  • JDK: 8

Конфигурация

Ehcache

Файл ehcache.xml выглядит следующим образом:

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="ehcache.xsd">
<cacheManagerEventListenerFactory
    class=""
    properties=""/>
<cacheManagerPeerProviderFactory
 class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
    properties="peerDiscovery=manual"
    propertySeparator="," />
<cacheManagerPeerListenerFactory
   class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
    properties="port=40000,remoteObjectPort=40001,hostName=A.A.A.A" />
<defaultCache
    maxElementsInMemory="10000"
    eternal="false"
    timeToIdleSeconds="120"
    timeToLiveSeconds="120"
    overflowToDisk="false"
    diskSpoolBufferSizeMB="30"
    maxElementsOnDisk="10000000"
    diskPersistent="false"
    diskExpiryThreadIntervalSeconds="120"
    memoryStoreEvictionPolicy="LRU"
    />
</ehcache>

Весенние бобы

Сервер RMI настроен на использование Spring для ehcache 2.5 +:

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation" value="classpath:ehcache.xml"/>
    <property name="shared" value="false"/>
    <property name="acceptExisting" value="true"/>
</bean>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
    <property name="locateExistingServerIfPossible" value="true"/>
</bean>

Java-код

Создание кэша

Для создания кешей приведен фрагмент кода:

    final CacheManager cm = CacheManager.create();
    _cache = cm.getCache(getName()); // If the cache is configured in the ehcache XML

    if (_cache == null) {
        final int maxElements = NumbersUtil.parseInt(value, 0);
        final int live = NumbersUtil.parseInt((String)params.get("cache.time.to.live"), 300);
        int idle = NumbersUtil.parseInt((String)params.get("cache.time.to.idle"), 300);
        if (live > 0 && idle > live) {
            idle = live;
        }
        _cache = new Cache(getName(), maxElements, false, live == 0, live, idle);

        // Check if replication is enabled and add the replication if needed
        final CacheManagerPeerListener cacheManagerPeerListener = cm.getCachePeerListener("RMI");
        final CacheManagerPeerProvider cmPeerProvider = cm.getCacheManagerPeerProvider("RMI");
        if (cacheManagerPeerListener != null && cmPeerProvider != null) {
            _cache.getCacheEventNotificationService().registerListener(new RMIAsynchronousCacheReplicator(false, false, true, false, true, 1000, 1000));
        }
        cm.addCache(_cache);
        s_logger.info("Cache created: " + _cache.toString());
    }

Регистрация репликации кэша

Код, когда сервер присоединяется к кластеру:

public void onServerJoined(List<? extends Server> nodeList, long selfNodeId) {
    final CacheManager cm = CacheManager.create();
    CacheManagerPeerProvider peerProvider = cm.getCacheManagerPeerProvider("RMI");
    if (peerProvider != null) {
        for (Server host : nodeList) {
            if (selfNodeId == host.getId()) {
                continue;
            }
            for (String cacheName : cm.getCacheNames()) {
                final String peerUrl = "//" + host.getServiceIP() + ":40000/" + cacheName;
                peerProvider.registerPeer(peerUrl);
            }
        }
    }
}

Устранение неполадок

Используя этот Java-код , кэш может быть перечислен:

$ java RmiPortNamesDisplay A.A.A.A 40000
Names bound to RMI registry at host A.A.A.A and port 40000:
    AddressDao
$ java RmiPortNamesDisplay B.B.B.B 40000
Names bound to RMI registry at host B.B.B.B and port 40000:
    AddressDao

Порты 40000 и 400001 открываются на брандмауэре каждого сервера.

Играя с менеджером ehcache JMX, если я удаляю все записи из кэша, генерируется исключение (вверху) и кэш не очищается на другом сервере.

Кто-то сталкивался с этой проблемой или есть решение, подсказка?

1 Ответ

0 голосов
/ 05 сентября 2018

Я наконец-то нашел причину этой проблемы. JVM была запущена с -Djava.rmi.server.hostname=127.0.0.1, что не позволяло серверу RMI правильно связываться. Вы можете удалить этот аргумент или установить IP-адрес, используемый ehcache для репликации.

...