use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.
the class EvictionChecker method usedHeapInBytes.
private long usedHeapInBytes(String mapName) {
long usedHeapInBytes = 0L;
for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
usedHeapInBytes += getRecordStoreHeapCost(mapName, containers[partitionId]);
}
NearCache nearCache = mapNearCacheManager.getNearCache(mapName);
if (nearCache != null) {
NearCacheStats nearCacheStats = nearCache.getNearCacheStats();
usedHeapInBytes += nearCacheStats.getOwnedEntryMemoryCost();
}
return usedHeapInBytes;
}
use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.
the class ClientCacheInvalidationMemberAddRemoveTest method ensure_nearCachedClient_and_member_data_sync_eventually.
@Test
public void ensure_nearCachedClient_and_member_data_sync_eventually() {
final AtomicBoolean stopTest = new AtomicBoolean();
final Config config = createConfig();
secondNode = hazelcastFactory.newHazelcastInstance(config);
CachingProvider provider = createServerCachingProvider(serverInstance);
final CacheManager serverCacheManager = provider.getCacheManager();
// populated from member
final Cache<Integer, Integer> memberCache = serverCacheManager.createCache(DEFAULT_CACHE_NAME, createCacheConfig(BINARY));
for (int i = 0; i < KEY_COUNT; i++) {
memberCache.put(i, i);
}
ClientConfig clientConfig = createClientConfig().addNearCacheConfig(createNearCacheConfig(BINARY));
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
CachingProvider clientCachingProvider = createClientCachingProvider(client);
final Cache<Integer, Integer> clientCache = clientCachingProvider.getCacheManager().createCache(DEFAULT_CACHE_NAME, createCacheConfig(BINARY));
ArrayList<Thread> threads = new ArrayList<Thread>();
// continuously adds and removes member
Thread shadowMember = new Thread(new Runnable() {
@Override
public void run() {
while (!stopTest.get()) {
HazelcastInstance member = hazelcastFactory.newHazelcastInstance(config);
sleepSeconds(5);
member.getLifecycleService().terminate();
}
}
});
threads.add(shadowMember);
for (int i = 0; i < NEAR_CACHE_POPULATE_THREAD_COUNT; i++) {
// populates client Near Cache
Thread populateClientNearCache = new Thread(new Runnable() {
public void run() {
int i = 0;
while (!stopTest.get()) {
clientCache.get(i++);
if (i == KEY_COUNT) {
i = 0;
}
}
}
});
threads.add(populateClientNearCache);
}
// updates data from member
Thread putFromMember = new Thread(new Runnable() {
public void run() {
while (!stopTest.get()) {
int key = getInt(KEY_COUNT);
int value = getInt(Integer.MAX_VALUE);
memberCache.put(key, value);
sleepAtLeastMillis(2);
}
}
});
threads.add(putFromMember);
Thread clearFromMember = new Thread(new Runnable() {
public void run() {
while (!stopTest.get()) {
memberCache.clear();
sleepSeconds(3);
}
}
});
threads.add(clearFromMember);
// start threads
for (Thread thread : threads) {
thread.start();
}
// stress system some seconds
sleepSeconds(TEST_RUN_SECONDS);
// stop threads
stopTest.set(true);
for (Thread thread : threads) {
assertJoinable(thread);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() {
for (int i = 0; i < KEY_COUNT; i++) {
Integer valueSeenFromMember = memberCache.get(i);
Integer valueSeenFromClient = clientCache.get(i);
String msg = createFailureMessage(i);
assertEquals(msg, valueSeenFromMember, valueSeenFromClient);
}
}
@SuppressWarnings("unchecked")
private String createFailureMessage(int i) {
int partitionId = getPartitionService(serverInstance).getPartitionId(i);
NearCacheRecordStore nearCacheRecordStore = getNearCacheRecordStore();
NearCacheRecord record = nearCacheRecordStore.getRecord(i);
long recordSequence = record == null ? NO_SEQUENCE : record.getInvalidationSequence();
// member-1
MetaDataGenerator metaDataGenerator1 = getMetaDataGenerator(serverInstance);
long memberSequence1 = metaDataGenerator1.currentSequence("/hz/" + DEFAULT_CACHE_NAME, partitionId);
UUID memberUuid1 = metaDataGenerator1.getUuidOrNull(partitionId);
// member-2
MetaDataGenerator metaDataGenerator2 = getMetaDataGenerator(secondNode);
long memberSequence2 = metaDataGenerator2.currentSequence("/hz/" + DEFAULT_CACHE_NAME, partitionId);
UUID memberUuid2 = metaDataGenerator2.getUuidOrNull(partitionId);
StaleReadDetector staleReadDetector = getStaleReadDetector(nearCacheRecordStore);
MetaDataContainer metaDataContainer = staleReadDetector.getMetaDataContainer(partitionId);
return format("On client: [uuid=%s, partition=%d, onRecordSequence=%d, latestSequence=%d, staleSequence=%d]," + "%nOn members: [memberUuid1=%s, memberSequence1=%d, memberUuid2=%s, memberSequence2=%d]", metaDataContainer.getUuid(), partitionId, recordSequence, metaDataContainer.getSequence(), metaDataContainer.getStaleSequence(), memberUuid1, memberSequence1, memberUuid2, memberSequence2);
}
private MetaDataGenerator getMetaDataGenerator(HazelcastInstance node) {
CacheService service = getNodeEngineImpl(node).getService(CacheService.SERVICE_NAME);
CacheEventHandler cacheEventHandler = service.getCacheEventHandler();
return cacheEventHandler.getMetaDataGenerator();
}
private NearCacheRecordStore getNearCacheRecordStore() {
NearCache nearCache = ((NearCachedClientCacheProxy) clientCache).getNearCache();
DefaultNearCache defaultNearCache = (DefaultNearCache) nearCache.unwrap(DefaultNearCache.class);
return defaultNearCache.getNearCacheRecordStore();
}
});
}
use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.
the class ClientCacheNearCacheCacheOnUpdateTest method with_cacheOnUpdate_policy_concurrently_updated_near_cache_does_not_cause_any_miss.
@Test
public void with_cacheOnUpdate_policy_concurrently_updated_near_cache_does_not_cause_any_miss() {
ICache<Integer, Integer> nearCachedClientCache = newNearCachedCache(CACHE_ON_UPDATE);
checkNearCacheInstance(nearCachedClientCache);
runTest(nearCachedClientCache, CACHE_ON_UPDATE);
NearCache nearCache = ((NearCachedClientCacheProxy) nearCachedClientCache).getNearCache();
int size = nearCache.size();
NearCacheStats nearCacheStatistics = nearCachedClientCache.getLocalCacheStatistics().getNearCacheStatistics();
assertEquals(size + ", " + nearCacheStatistics.toString() + ", " + nearCache.getNearCacheConfig(), 0, nearCacheStatistics.getMisses());
}
use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.
the class MapNearCacheInvalidationTest method testHigherBatchSize_shouldNotCauseAnyInvalidation_onRemoteNode.
@Test
public void testHigherBatchSize_shouldNotCauseAnyInvalidation_onRemoteNode() {
Config config = getConfig(mapName);
configureBatching(config, Integer.MAX_VALUE, Integer.MAX_VALUE);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
HazelcastInstance node1 = factory.newHazelcastInstance(config);
HazelcastInstance node2 = factory.newHazelcastInstance(config);
IMap<String, Integer> map1 = node1.getMap(mapName);
IMap<String, Integer> map2 = node2.getMap(mapName);
int size = 1000;
List<String> keys = new ArrayList<String>();
for (int i = 0; i < size; i++) {
keys.add(generateKeyOwnedBy(node1));
}
// fill map-1
for (int i = 0; i < size; i++) {
map1.put(keys.get(i), i);
}
// fill Near Cache on node-1
for (int i = 0; i < size; i++) {
map1.get(keys.get(i));
}
// fill Near Cache on node-2
for (int i = 0; i < size; i++) {
map2.get(keys.get(i));
}
// generate invalidation data
for (int i = 0; i < size; i++) {
map1.put(keys.get(i), i);
}
NearCache nearCache1 = ((NearCachedMapProxyImpl) map1).getNearCache();
NearCache nearCache2 = ((NearCachedMapProxyImpl) map2).getNearCache();
// Near Cache on one node should be invalidated completely, other node should not receive any event
// (due to the higher invalidation batch-size)
assertEquals(size, nearCache1.size() + nearCache2.size());
}
use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.
the class AbstractNearCachePreloaderTest method assertNearCachePreloadDoneEventually.
private static void assertNearCachePreloadDoneEventually(final NearCacheTestContext clientContext, long timeoutSeconds) {
assertTrueEventually(() -> {
NearCache nearCache = clientContext.nearCache;
NearCacheStats stats = nearCache.getNearCacheStats();
int size = nearCache.size();
assertTrue(format("Preloading has not finished yet. [size: %d, %s]", size, stats), nearCache.isPreloadDone());
});
}
Aggregations