use of com.hazelcast.internal.partition.InternalPartitionService in project hazelcast by hazelcast.
the class InvalidationMetadataDistortionTest method distortRandomPartitionSequence.
private void distortRandomPartitionSequence(String mapName, HazelcastInstance member) {
NodeEngineImpl nodeEngineImpl = getNodeEngineImpl(member);
CacheService service = nodeEngineImpl.getService(CacheService.SERVICE_NAME);
CacheEventHandler cacheEventHandler = service.getCacheEventHandler();
MetaDataGenerator metaDataGenerator = cacheEventHandler.getMetaDataGenerator();
InternalPartitionService partitionService = nodeEngineImpl.getPartitionService();
int partitionCount = partitionService.getPartitionCount();
int randomPartition = getInt(partitionCount);
int randomSequence = getInt(MAX_VALUE);
metaDataGenerator.setCurrentSequence(mapName, randomPartition, randomSequence);
}
use of com.hazelcast.internal.partition.InternalPartitionService in project hazelcast by hazelcast.
the class InvalidationMemberAddRemoveTest method ensure_nearCachedClient_and_member_data_sync_eventually.
@Test
public void ensure_nearCachedClient_and_member_data_sync_eventually() throws Exception {
final AtomicBoolean stopTest = new AtomicBoolean();
final Config config = createConfig();
hazelcastFactory.newHazelcastInstance(config);
CachingProvider provider = HazelcastServerCachingProvider.createCachingProvider(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();
clientConfig.addNearCacheConfig(createNearCacheConfig(BINARY));
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
CachingProvider clientCachingProvider = HazelcastClientCachingProvider.createCachingProvider(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_POPULATOR_THREAD_COUNT; i++) {
// populates client near-cache
Thread populateClientNearCache = new Thread(new Runnable() {
public void run() {
while (!stopTest.get()) {
for (int i = 0; i < KEY_COUNT; i++) {
clientCache.get(i);
}
}
}
});
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) {
thread.join();
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
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);
}
}
private String createFailureMessage(int i) {
InternalPartitionService partitionService = getPartitionService(serverInstance);
Data keyData = getSerializationService(serverInstance).toData(i);
int partitionId = partitionService.getPartitionId(keyData);
AbstractNearCacheRecordStore nearCacheRecordStore = getAbstractNearCacheRecordStore();
NearCacheRecord record = nearCacheRecordStore.getRecord(keyData);
long recordSequence = record == null ? NO_SEQUENCE : record.getInvalidationSequence();
MetaDataGenerator metaDataGenerator = getMetaDataGenerator();
long memberSequence = metaDataGenerator.currentSequence("/hz/" + DEFAULT_CACHE_NAME, partitionId);
MetaDataContainer metaDataContainer = nearCacheRecordStore.getStaleReadDetector().getMetaDataContainer(keyData);
return String.format("partition=%d, onRecordSequence=%d, latestSequence=%d, staleSequence=%d, memberSequence=%d", partitionService.getPartitionId(keyData), recordSequence, metaDataContainer.getSequence(), metaDataContainer.getStaleSequence(), memberSequence);
}
private MetaDataGenerator getMetaDataGenerator() {
CacheEventHandler cacheEventHandler = ((CacheService) ((CacheProxy) memberCache).getService()).getCacheEventHandler();
return cacheEventHandler.getMetaDataGenerator();
}
private AbstractNearCacheRecordStore getAbstractNearCacheRecordStore() {
DefaultNearCache defaultNearCache = (DefaultNearCache) ((ClientCacheProxy) clientCache).getNearCache().unwrap(DefaultNearCache.class);
return (AbstractNearCacheRecordStore) defaultNearCache.getNearCacheRecordStore();
}
});
}
use of com.hazelcast.internal.partition.InternalPartitionService in project hazelcast by hazelcast.
the class CacheClearTest method testClear.
@Test
public void testClear() {
ICache<String, String> cache = createCache();
String cacheName = cache.getName();
Map<String, String> entries = createAndFillEntries();
for (Map.Entry<String, String> entry : entries.entrySet()) {
cache.put(entry.getKey(), entry.getValue());
}
// Verify that put works
for (Map.Entry<String, String> entry : entries.entrySet()) {
String key = entry.getKey();
String expectedValue = entries.get(key);
String actualValue = cache.get(key);
assertEquals(expectedValue, actualValue);
}
Node node = getNode(hazelcastInstance);
InternalPartitionService partitionService = node.getPartitionService();
SerializationService serializationService = node.getSerializationService();
// Verify that backup of put works
for (Map.Entry<String, String> entry : entries.entrySet()) {
String key = entry.getKey();
String expectedValue = entries.get(key);
Data keyData = serializationService.toData(key);
int keyPartitionId = partitionService.getPartitionId(keyData);
for (int i = 0; i < INSTANCE_COUNT; i++) {
Node n = getNode(hazelcastInstances[i]);
ICacheService cacheService = n.getNodeEngine().getService(ICacheService.SERVICE_NAME);
ICacheRecordStore recordStore = cacheService.getRecordStore("/hz/" + cacheName, keyPartitionId);
assertNotNull(recordStore);
String actualValue = serializationService.toObject(recordStore.get(keyData, null));
assertEquals(expectedValue, actualValue);
}
}
cache.clear();
// Verify that clear works
for (Map.Entry<String, String> entry : entries.entrySet()) {
String key = entry.getKey();
String actualValue = cache.get(key);
assertNull(actualValue);
}
// Verify that backup of clear works
for (Map.Entry<String, String> entry : entries.entrySet()) {
String key = entry.getKey();
Data keyData = serializationService.toData(key);
int keyPartitionId = partitionService.getPartitionId(keyData);
for (int i = 0; i < INSTANCE_COUNT; i++) {
Node n = getNode(hazelcastInstances[i]);
ICacheService cacheService = n.getNodeEngine().getService(ICacheService.SERVICE_NAME);
ICacheRecordStore recordStore = cacheService.getRecordStore("/hz/" + cacheName, keyPartitionId);
assertNotNull(recordStore);
String actualValue = serializationService.toObject(recordStore.get(keyData, null));
assertNull(actualValue);
}
}
}
use of com.hazelcast.internal.partition.InternalPartitionService in project hazelcast by hazelcast.
the class ClusterJoinManager method startJoin.
private void startJoin() {
logger.fine("Starting join...");
clusterServiceLock.lock();
try {
InternalPartitionService partitionService = node.getPartitionService();
try {
joinInProgress = true;
// pause migrations until join, member-update and post-join operations are completed
partitionService.pauseMigration();
Collection<MemberImpl> members = clusterService.getMemberImpls();
Collection<MemberInfo> memberInfos = createMemberInfoList(members);
for (MemberInfo memberJoining : joiningMembers.values()) {
memberInfos.add(memberJoining);
}
long time = clusterClock.getClusterTime();
// post join operations must be lock free, that means no locks at all:
// no partition locks, no key-based locks, no service level locks!
Operation[] postJoinOps = nodeEngine.getPostJoinOperations();
boolean createPostJoinOperation = (postJoinOps != null && postJoinOps.length > 0);
PostJoinOperation postJoinOp = (createPostJoinOperation ? new PostJoinOperation(postJoinOps) : null);
clusterService.updateMembers(memberInfos, node.getThisAddress());
int count = members.size() - 1 + joiningMembers.size();
List<Future> calls = new ArrayList<Future>(count);
PartitionRuntimeState partitionRuntimeState = partitionService.createPartitionState();
for (MemberInfo member : joiningMembers.values()) {
long startTime = clusterClock.getClusterStartTime();
Operation finalizeJoinOperation = new FinalizeJoinOperation(member.getUuid(), memberInfos, postJoinOp, time, clusterService.getClusterId(), startTime, clusterStateManager.getState(), clusterService.getClusterVersion(), partitionRuntimeState);
calls.add(invokeClusterOperation(finalizeJoinOperation, member.getAddress()));
}
for (MemberImpl member : members) {
if (member.localMember() || joiningMembers.containsKey(member.getAddress())) {
continue;
}
Operation memberInfoUpdateOperation = new MemberInfoUpdateOperation(member.getUuid(), memberInfos, time, partitionRuntimeState, true);
calls.add(invokeClusterOperation(memberInfoUpdateOperation, member.getAddress()));
}
int timeout = Math.min(calls.size() * FINALIZE_JOIN_TIMEOUT_FACTOR, FINALIZE_JOIN_MAX_TIMEOUT);
waitWithDeadline(calls, timeout, TimeUnit.SECONDS, whileFinalizeJoinsExceptionHandler);
} finally {
reset();
partitionService.resumeMigration();
}
} finally {
clusterServiceLock.unlock();
}
}
use of com.hazelcast.internal.partition.InternalPartitionService in project hazelcast by hazelcast.
the class HttpGetCommandProcessor method handleHealthcheck.
private void handleHealthcheck(HttpGetCommand command) {
Node node = textCommandService.getNode();
NodeState nodeState = node.getState();
ClusterServiceImpl clusterService = node.getClusterService();
ClusterState clusterState = clusterService.getClusterState();
int clusterSize = clusterService.getMembers().size();
InternalPartitionService partitionService = node.getPartitionService();
boolean memberStateSafe = partitionService.isMemberStateSafe();
boolean clusterSafe = memberStateSafe && !partitionService.hasOnGoingMigration();
long migrationQueueSize = partitionService.getMigrationQueueSize();
StringBuilder res = new StringBuilder();
res.append("Hazelcast::NodeState=").append(nodeState).append("\n");
res.append("Hazelcast::ClusterState=").append(clusterState).append("\n");
res.append("Hazelcast::ClusterSafe=").append(Boolean.toString(clusterSafe).toUpperCase()).append("\n");
res.append("Hazelcast::MigrationQueueSize=").append(migrationQueueSize).append("\n");
res.append("Hazelcast::ClusterSize=").append(clusterSize).append("\n");
command.setResponse(MIME_TEXT_PLAIN, stringToBytes(res.toString()));
}
Aggregations