use of com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl in project hazelcast by hazelcast.
the class FinalizePromotionOperation method shiftUpReplicaVersions.
private void shiftUpReplicaVersions() {
final int partitionId = getPartitionId();
try {
final InternalPartitionServiceImpl partitionService = getService();
// returns the internal array itself, not the copy
final long[] versions = partitionService.getPartitionReplicaVersions(partitionId);
final int lostReplicaIndex = currentReplicaIndex - 1;
if (currentReplicaIndex > 1) {
final long[] versionsCopy = Arrays.copyOf(versions, versions.length);
final long version = versions[lostReplicaIndex];
Arrays.fill(versions, 0, lostReplicaIndex, version);
if (logger.isFinestEnabled()) {
logger.finest("Partition replica is lost! partitionId=" + partitionId + " lost replicaIndex=" + lostReplicaIndex + " replica versions before shift up=" + Arrays.toString(versionsCopy) + " replica versions after shift up=" + Arrays.toString(versions));
}
} else if (logger.isFinestEnabled()) {
logger.finest("PROMOTE partitionId=" + getPartitionId() + " from currentReplicaIndex=" + currentReplicaIndex);
}
PartitionEventManager partitionEventManager = partitionService.getPartitionEventManager();
partitionEventManager.sendPartitionLostEvent(partitionId, lostReplicaIndex);
} catch (Throwable e) {
logger.warning("Promotion failed. partitionId=" + partitionId + " replicaIndex=" + currentReplicaIndex, e);
}
}
use of com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl in project hazelcast by hazelcast.
the class StaleReadDuringMigrationTest method invokeOperation.
private InternalCompletableFuture<Boolean> invokeOperation(final Config config) {
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
final HazelcastInstance instance = factory.newHazelcastInstance(config);
warmUpPartitions(instance);
final int partitionId = 0;
final InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) getPartitionService(instance);
final InternalPartitionImpl partition = (InternalPartitionImpl) partitionService.getPartition(partitionId);
partition.setMigrating(true);
final InternalOperationService operationService = getOperationService(instance);
final InvocationBuilder invocationBuilder = operationService.createInvocationBuilder(InternalPartitionService.SERVICE_NAME, new DummyOperation(), partitionId);
return invocationBuilder.invoke();
}
use of com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl in project hazelcast by hazelcast.
the class PartitionLostListenerTest method test_partitionLostListenerInvoked.
@Test
public void test_partitionLostListenerInvoked() {
HazelcastInstance instance = instances[0];
final EventCollectingPartitionLostListener listener = new EventCollectingPartitionLostListener();
instance.getPartitionService().addPartitionLostListener(listener);
final IPartitionLostEvent internalEvent = new IPartitionLostEvent(1, 0, null);
NodeEngineImpl nodeEngine = getNode(instance).getNodeEngine();
InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) nodeEngine.getPartitionService();
partitionService.onPartitionLost(internalEvent);
assertEventEventually(listener, internalEvent);
}
use of com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl in project hazelcast by hazelcast.
the class ClientPartitionLostListenerTest method test_partitionLostListener_invoked_fromOtherNode.
@Test
public void test_partitionLostListener_invoked_fromOtherNode() {
final HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance();
final HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();
final ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig().setSmartRouting(false);
final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
warmUpPartitions(instance1, instance2, client);
final HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
final Address clientOwnerAddress = clientInstanceImpl.getClientClusterService().getOwnerConnectionAddress();
final HazelcastInstance other = getAddress(instance1).equals(clientOwnerAddress) ? instance2 : instance1;
final EventCollectingPartitionLostListener listener = new EventCollectingPartitionLostListener();
client.getPartitionService().addPartitionLostListener(listener);
assertRegistrationsSizeEventually(instance1, 1);
assertRegistrationsSizeEventually(instance2, 1);
final InternalPartitionServiceImpl partitionService = getNode(other).getNodeEngine().getService(SERVICE_NAME);
final int partitionId = 5;
partitionService.onPartitionLost(new IPartitionLostEvent(partitionId, 0, null));
assertPartitionLostEventEventually(listener, partitionId);
}
use of com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl in project hazelcast by hazelcast.
the class Node method initializeListeners.
@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity" })
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 InternalMigrationListener) {
final InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) nodeEngine.getPartitionService();
partitionService.setInternalMigrationListener((InternalMigrationListener) 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);
}
}
}
Aggregations