2016-08-22 48 views
1

我有兩個客戶端和一個服務器。Apache Ignite複製緩存在客戶端不可用

[14:02:16] Topology snapshot [ver=8, servers=1, clients=2, CPUs=8, heap=7.8GB] 

我創建了一個複製緩存,我想這兩種情況下有機會獲得同樣的緩存,即由一個客戶端加入令牌可以通過其他的,反之亦然讀取。

private IgniteCache<Long, CacheToken> getOrCreateCache() { 
    CacheConfiguration<Long, CacheToken> tokenCacheConfig = new CacheConfiguration<>(REVOCATION_CACHE); 

    tokenCacheConfig.setCacheMode(CacheMode.REPLICATED); 
    tokenCacheConfig.setIndexedTypes(Long.class, CacheToken.class); 
    tokenCacheConfig.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(Duration.THIRTY_MINUTES)); 

    return ignite.getOrCreateCache(tokenCacheConfig); 
} 

我當我看到緩存我實際上看到的是正在創建具有相同名稱的兩個獨立的緩存,而不是複製。

Nodes for: TOKEN_REVOCATION_LIST(@c2) 
+==============================================================================================+ 
|  Node ID8(@), IP  | CPUs | Heap Used | CPU Load | Up Time | Size | Hi/Mi/Rd/Wr | 
+==============================================================================================+ 
| 0794F94D(@n2), xx.xx.xx.xx | 8 | 22.79 % | 0.03 % | 00:54:44:853 | 14 | Hi: 0  | 
|       |  |   |   |    |  | Mi: 0  | 
|       |  |   |   |    |  | Rd: 0  | 
|       |  |   |   |    |  | Wr: 0  | 
+----------------------------+------+-----------+----------+--------------+------+-------------+ 
| 7B9F7E25(@n1), xx.xx.xx.xx | 8 | 23.12 % | 0.13 % | 00:55:00:366 | 0 | Hi: 0  | 
|       |  |   |   |    |  | Mi: 0  | 
|       |  |   |   |    |  | Rd: 0  | 
|       |  |   |   |    |  | Wr: 0  | 
+----------------------------+------+-----------+----------+--------------+------+-------------+ 
| E7321C6D(@n0), xx.xx.xx.xx | 8 | 6.90 % | 0.03 % | 00:55:08:795 | 0 | Hi: 0  | 
|       |  |   |   |    |  | Mi: 0  | 
|       |  |   |   |    |  | Rd: 0  | 
|       |  |   |   |    |  | Wr: 0  | 
+----------------------------------------------------------------------------------------------+ 

我期望看到的行爲是一個共享緩存,或者至少是跨節點複製的令牌。從每個節點中,我可以讀取節點寫入的值,但不能讀取節點中的值。

我應該怎樣改變配置來完成共享的複製緩存?有沒有這樣的例子?

@Configuration 
public class IgniteConfig { 

@Bean 
public Ignite ignite() { 
    return Ignition.start(igniteConfiguration()); 
} 

@Bean 
public JdbcDataSource h2ExampleDb() { 
    JdbcDataSource ds = new JdbcDataSource(); 
    ds.setURL("jdbc:h2:tcp://localhost/mem:ExampleDb"); 
    ds.setUser("sa"); 
    return ds; 
} 

@Bean 
public IgniteConfiguration igniteConfiguration() { 
    IgniteConfiguration ic = new IgniteConfiguration(); 
    ic.setClientMode(true); 
    ic.setPeerClassLoadingEnabled(true); 
    ic.setIncludeEventTypes(getEventTypes()); 
    ic.setDiscoverySpi(discoverySpi()); 
    ic.setCacheConfiguration(cacheConfiguration()); 
    return ic; 
} 

public CacheConfiguration cacheConfiguration() { 
    CacheConfiguration cc = new CacheConfiguration(); 
    cc.setCacheMode(CacheMode.REPLICATED); 
    return cc; 
} 

public int[] getEventTypes() { 
    int[] eventTypes = { 
      EventType.EVT_TASK_STARTED, 
      EventType.EVT_TASK_FINISHED, 
      EventType.EVT_TASK_FAILED, 
      EventType.EVT_TASK_TIMEDOUT, 
      EventType.EVT_TASK_SESSION_ATTR_SET, 
      EventType.EVT_TASK_REDUCED, 
      EventType.EVT_CACHE_OBJECT_PUT, 
      EventType.EVT_CACHE_OBJECT_READ, 
      EventType.EVT_CACHE_OBJECT_REMOVED, 
      EventType.EVT_CLIENT_NODE_RECONNECTED, 
      EventType.EVT_CACHE_OBJECT_EXPIRED 
    }; 

    return eventTypes; 
} 

@Bean 
public TcpDiscoverySpi discoverySpi() { 
    TcpDiscoverySpi spi = new TcpDiscoverySpi(); 
    spi.setIpFinder(tdif()); 
    return spi; 
} 

@Bean 
public TcpDiscoveryMulticastIpFinder tdif() { 
    TcpDiscoveryMulticastIpFinder finder = new TcpDiscoveryMulticastIpFinder(); 
    List<String> addresses = new ArrayList<>(); 
    addresses.add("127.0.0.1:47500..47509"); 
    finder.setAddresses(addresses); 
    return finder; 
} 
} 

回答

4

客戶端節點不存儲分佈式緩存(複製或分區)的數據。由於只有一個服務器節點,因此只會複製一個副本。只需啓動更多服務器節點,您就會看到緩存被複制到所有服務器節點上。

+0

要使複製生效,我添加的每個節點是否都需要一臺服務器?或者兩臺服務器可以跨四個客戶端進行復制? – blur0224

+0

跨客戶端沒有任何複製,只有跨服務器的複製。客戶端只需訪問服務器節點上的緩存即可。你解決了什麼樣的問題?如果你提供額外的細節,可能會有幫助。 –