use of com.hazelcast.internal.partition.impl.MigrationInterceptor in project hazelcast by hazelcast.
the class ClientExecutorServiceCancelTest method testCancel_submitToKeyOwner_Should_Not_Block_Migration.
@Test(expected = CancellationException.class)
public void testCancel_submitToKeyOwner_Should_Not_Block_Migration() throws IOException, ExecutionException, InterruptedException {
server2.shutdown();
HazelcastInstance client = createClient(true);
warmUpPartitions(server1);
IExecutorService executorService = client.getExecutorService(randomString());
String key = ExecutorServiceTestSupport.generateKeyOwnedBy(server1);
final Future<Boolean> future = executorService.submitToKeyOwner(new CancellationAwareTask(SLEEP_TIME), key);
awaitTaskStartAtMember(server1, 1);
InternalPartitionServiceImpl internalPartitionService = (InternalPartitionServiceImpl) TestUtil.getNode(server1).getPartitionService();
final int partitionId = internalPartitionService.getPartitionId(key);
// Simulate partition thread blockage as if the partition is migrating
internalPartitionService.setMigrationInterceptor(new MigrationInterceptor() {
@Override
public void onMigrationCommit(MigrationInterceptor.MigrationParticipant participant, MigrationInfo migrationInfo) {
int migratingPartitionId = migrationInfo.getPartitionId();
if (migratingPartitionId == partitionId) {
spawn(() -> {
future.cancel(true);
});
// sleep enough so that the ExecutorServiceCancelOnPartitionMessageTask actually starts
// This test is time sensitive
sleepSeconds(3);
}
}
});
// Start the second member to initiate migration
server2 = hazelcastFactory.newHazelcastInstance();
waitAllForSafeState(server1, server2);
future.get();
}
use of com.hazelcast.internal.partition.impl.MigrationInterceptor in project hazelcast by hazelcast.
the class Node method initializeListeners.
@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity", "checkstyle:methodlength" })
private void initializeListeners(Config config) {
for (final ListenerConfig listenerCfg : config.getListenerConfigs()) {
Object listener = listenerCfg.getImplementation();
if (listener == null) {
try {
listener = ClassLoaderUtil.newInstance(configClassLoader, listenerCfg.getClassName());
} catch (Exception e) {
logger.severe(e);
}
}
if (listener instanceof HazelcastInstanceAware) {
((HazelcastInstanceAware) listener).setHazelcastInstance(hazelcastInstance);
}
boolean known = false;
if (listener instanceof DistributedObjectListener) {
final ProxyServiceImpl proxyService = (ProxyServiceImpl) nodeEngine.getProxyService();
proxyService.addProxyListener((DistributedObjectListener) listener);
known = true;
}
if (listener instanceof MembershipListener) {
clusterService.addMembershipListener((MembershipListener) listener);
known = true;
}
if (listener instanceof MigrationListener) {
partitionService.addMigrationListener((MigrationListener) listener);
known = true;
}
if (listener instanceof PartitionLostListener) {
partitionService.addPartitionLostListener((PartitionLostListener) listener);
known = true;
}
if (listener instanceof LifecycleListener) {
hazelcastInstance.lifecycleService.addLifecycleListener((LifecycleListener) listener);
known = true;
}
if (listener instanceof ClientListener) {
String serviceName = ClientEngineImpl.SERVICE_NAME;
nodeEngine.getEventService().registerLocalListener(serviceName, serviceName, listener);
known = true;
}
if (listener instanceof MigrationInterceptor) {
partitionService.setMigrationInterceptor((MigrationInterceptor) listener);
known = true;
}
if (listener instanceof CPMembershipListener) {
hazelcastInstance.cpSubsystem.addMembershipListener((CPMembershipListener) listener);
known = true;
}
if (listener instanceof CPGroupAvailabilityListener) {
hazelcastInstance.cpSubsystem.addGroupAvailabilityListener((CPGroupAvailabilityListener) listener);
known = true;
}
if (nodeExtension.registerListener(listener)) {
known = true;
}
if (listener != null && !known) {
final String error = "Unknown listener type: " + listener.getClass();
Throwable t = new IllegalArgumentException(error);
logger.warning(error, t);
}
}
}
use of com.hazelcast.internal.partition.impl.MigrationInterceptor in project hazelcast by hazelcast.
the class BaseMigrationOperation method onMigrationStart.
void onMigrationStart() {
InternalPartitionServiceImpl partitionService = getService();
MigrationInterceptor migrationInterceptor = partitionService.getMigrationInterceptor();
migrationInterceptor.onMigrationStart(getMigrationParticipantType(), migrationInfo);
}
use of com.hazelcast.internal.partition.impl.MigrationInterceptor in project hazelcast by hazelcast.
the class BaseMigrationOperation method onMigrationComplete.
void onMigrationComplete() {
InternalPartitionServiceImpl partitionService = getService();
MigrationInterceptor migrationInterceptor = partitionService.getMigrationInterceptor();
migrationInterceptor.onMigrationComplete(getMigrationParticipantType(), migrationInfo, success);
}
use of com.hazelcast.internal.partition.impl.MigrationInterceptor in project hazelcast by hazelcast.
the class GracefulShutdownTest method shutdownMasterCandidate_whileMastershipClaimIsInProgress.
@Test
public void shutdownMasterCandidate_whileMastershipClaimIsInProgress() throws Exception {
Config config = new Config();
// setting a very graceful shutdown high timeout value
// to guarantee instance.shutdown() not to timeout
config.setProperty(ClusterProperty.GRACEFUL_SHUTDOWN_MAX_WAIT.getName(), "99999999999");
final HazelcastInstance[] instances = factory.newInstances(config, 4);
assertClusterSizeEventually(4, instances);
warmUpPartitions(instances);
// Drop mastership claim operation submitted from master candidate
dropOperationsFrom(instances[1], ClusterDataSerializerHook.F_ID, singletonList(ClusterDataSerializerHook.FETCH_MEMBER_LIST_STATE));
final InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) getPartitionService(instances[1]);
final AtomicReference<MigrationInfo> startedMigration = new AtomicReference<MigrationInfo>();
partitionService.setMigrationInterceptor(new MigrationInterceptor() {
@Override
public void onMigrationStart(MigrationParticipant participant, MigrationInfo migrationInfo) {
startedMigration.set(migrationInfo);
}
});
final long partitionStateStamp = partitionService.getPartitionStateStamp();
instances[0].getLifecycleService().terminate();
// instance-1 starts mastership claim
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertTrue(getNode(instances[1]).isMaster());
}
});
Future future = spawn(new Runnable() {
@Override
public void run() {
instances[1].shutdown();
}
});
assertTrueAllTheTime(new AssertTask() {
@Override
public void run() {
// other members have not received/accepted mastership claim yet
assertNotEquals(getAddress(instances[1]), getNode(instances[2]).getMasterAddress());
assertNotEquals(getAddress(instances[1]), getNode(instances[3]).getMasterAddress());
// no partition state version change
assertEquals(partitionStateStamp, partitionService.getPartitionStateStamp());
// no migrations has been submitted yet
assertNull(startedMigration.get());
}
}, 5);
assertFalse(future.isDone());
resetPacketFiltersFrom(instances[1]);
future.get();
}
Aggregations