Search in sources :

Example 1 with InternalPartitionServiceImpl

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) HazelcastTestSupport.getAddress(com.hazelcast.test.HazelcastTestSupport.getAddress) EventCollectingPartitionLostListener(com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) ClientTestUtil.getHazelcastClientInstanceImpl(com.hazelcast.client.impl.ClientTestUtil.getHazelcastClientInstanceImpl) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientConfig(com.hazelcast.client.config.ClientConfig) IPartitionLostEvent(com.hazelcast.spi.partition.IPartitionLostEvent) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with InternalPartitionServiceImpl

use of com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl in project hazelcast by hazelcast.

the class ClusterServiceImpl method repairPartitionTableIfReturningMember.

private void repairPartitionTableIfReturningMember(MemberImpl member) {
    if (!isMaster()) {
        return;
    }
    if (getClusterState() == ClusterState.ACTIVE) {
        return;
    }
    if (!node.getNodeExtension().isStartCompleted()) {
        return;
    }
    Address address = member.getAddress();
    MemberImpl memberRemovedWhileClusterIsNotActive = getMemberRemovedWhileClusterIsNotActive(member.getUuid());
    if (memberRemovedWhileClusterIsNotActive != null) {
        Address oldAddress = memberRemovedWhileClusterIsNotActive.getAddress();
        if (!oldAddress.equals(address)) {
            assert !isMemberRemovedWhileClusterIsNotActive(address);
            logger.warning(member + " is returning with a new address. Old one was: " + oldAddress + ". Will update partition table with the new address.");
            InternalPartitionServiceImpl partitionService = node.partitionService;
            partitionService.replaceAddress(oldAddress, address);
        }
    }
}
Also used : Address(com.hazelcast.nio.Address) MemberImpl(com.hazelcast.instance.MemberImpl) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)

Example 3 with InternalPartitionServiceImpl

use of com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl in project hazelcast by hazelcast.

the class ReplicaSyncResponse method run.

@Override
public void run() throws Exception {
    NodeEngine nodeEngine = getNodeEngine();
    InternalPartitionServiceImpl partitionService = getService();
    int partitionId = getPartitionId();
    int replicaIndex = getReplicaIndex();
    PartitionStateManager partitionStateManager = partitionService.getPartitionStateManager();
    InternalPartitionImpl partition = partitionStateManager.getPartitionImpl(partitionId);
    Address thisAddress = nodeEngine.getThisAddress();
    int currentReplicaIndex = partition.getReplicaIndex(thisAddress);
    try {
        if (replicaIndex == currentReplicaIndex) {
            executeTasks();
        } else {
            nodeNotOwnsBackup(partition);
        }
        if (tasks != null) {
            tasks.clear();
        }
    } finally {
        postProcessReplicaSync(partitionService, currentReplicaIndex);
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Address(com.hazelcast.nio.Address) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl) PartitionStateManager(com.hazelcast.internal.partition.impl.PartitionStateManager)

Example 4 with InternalPartitionServiceImpl

use of com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl in project hazelcast by hazelcast.

the class ReplicaSyncRetryResponse method run.

@Override
public void run() throws Exception {
    final InternalPartitionServiceImpl partitionService = getService();
    final int partitionId = getPartitionId();
    final int replicaIndex = getReplicaIndex();
    partitionService.getReplicaManager().clearReplicaSyncRequest(partitionId, replicaIndex);
    PartitionStateManager partitionStateManager = partitionService.getPartitionStateManager();
    InternalPartitionImpl partition = partitionStateManager.getPartitionImpl(partitionId);
    Address thisAddress = getNodeEngine().getThisAddress();
    ILogger logger = getLogger();
    int currentReplicaIndex = partition.getReplicaIndex(thisAddress);
    if (currentReplicaIndex > 0) {
        if (logger.isFinestEnabled()) {
            logger.finest("Retrying replica sync request for partitionId=" + partitionId + ", initial-replicaIndex=" + replicaIndex + ", current-replicaIndex=" + currentReplicaIndex);
        }
        partitionService.getReplicaManager().triggerPartitionReplicaSync(partitionId, currentReplicaIndex, InternalPartitionService.REPLICA_SYNC_RETRY_DELAY);
    } else if (logger.isFinestEnabled()) {
        logger.finest("No need to retry replica sync request for partitionId=" + partitionId + ", initial-replicaIndex=" + replicaIndex + ", current-replicaIndex=" + currentReplicaIndex);
    }
}
Also used : Address(com.hazelcast.nio.Address) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl) ILogger(com.hazelcast.logging.ILogger) PartitionStateManager(com.hazelcast.internal.partition.impl.PartitionStateManager)

Example 5 with InternalPartitionServiceImpl

use of com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl in project hazelcast by hazelcast.

the class PromotionCommitOperation method beforePromotion.

private void beforePromotion() {
    NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
    InternalOperationService operationService = nodeEngine.getOperationService();
    InternalPartitionServiceImpl partitionService = getService();
    ILogger logger = getLogger();
    if (logger.isFineEnabled()) {
        logger.fine("Submitting BeforePromotionOperations for " + promotions.size() + " promotions.");
    }
    Runnable beforePromotionsCallback = new BeforePromotionOperationCallback(this, new AtomicInteger(promotions.size()));
    for (MigrationInfo promotion : promotions) {
        if (logger.isFinestEnabled()) {
            logger.finest("Submitting BeforePromotionOperation for promotion: " + promotion);
        }
        int currentReplicaIndex = promotion.getDestinationCurrentReplicaIndex();
        BeforePromotionOperation op = new BeforePromotionOperation(currentReplicaIndex, beforePromotionsCallback);
        op.setPartitionId(promotion.getPartitionId()).setNodeEngine(nodeEngine).setService(partitionService);
        operationService.execute(op);
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) MigrationInfo(com.hazelcast.internal.partition.MigrationInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) ILogger(com.hazelcast.logging.ILogger) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService)

Aggregations

InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)35 Address (com.hazelcast.nio.Address)11 ILogger (com.hazelcast.logging.ILogger)10 PartitionStateManager (com.hazelcast.internal.partition.impl.PartitionStateManager)7 NodeEngine (com.hazelcast.spi.NodeEngine)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)5 IPartitionLostEvent (com.hazelcast.spi.partition.IPartitionLostEvent)5 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 InternalPartitionImpl (com.hazelcast.internal.partition.impl.InternalPartitionImpl)4 PartitionReplicaManager (com.hazelcast.internal.partition.impl.PartitionReplicaManager)4 EventCollectingPartitionLostListener (com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener)4 MigrationInfo (com.hazelcast.internal.partition.MigrationInfo)3 InternalMigrationListener (com.hazelcast.internal.partition.impl.InternalMigrationListener)3 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)3 MigrationEndpoint (com.hazelcast.spi.partition.MigrationEndpoint)3 ClusterService (com.hazelcast.internal.cluster.ClusterService)2 Operation (com.hazelcast.spi.Operation)2