Search in sources :

Example 31 with InternalPartitionService

use of com.hazelcast.internal.partition.InternalPartitionService in project hazelcast by hazelcast.

the class ClusterStateManager method checkMigrationsAndPartitionStateVersion.

private void checkMigrationsAndPartitionStateVersion(ClusterStateChange stateChange, int partitionStateVersion) {
    final InternalPartitionService partitionService = node.getPartitionService();
    final int thisPartitionStateVersion = partitionService.getPartitionStateVersion();
    if (partitionService.hasOnGoingMigrationLocal()) {
        throw new IllegalStateException("Still have pending migration tasks, " + "cannot lock cluster state! New state: " + stateChange + ", current state: " + getState());
    } else if (partitionStateVersion != thisPartitionStateVersion) {
        throw new IllegalStateException("Can not lock cluster state! Partition tables have different versions! " + "Expected version: " + partitionStateVersion + " Current version: " + thisPartitionStateVersion);
    }
}
Also used : InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService)

Example 32 with InternalPartitionService

use of com.hazelcast.internal.partition.InternalPartitionService in project hazelcast by hazelcast.

the class Backup method beforeRun.

@Override
public void beforeRun() throws Exception {
    NodeEngine nodeEngine = getNodeEngine();
    int partitionId = getPartitionId();
    InternalPartitionService partitionService = (InternalPartitionService) nodeEngine.getPartitionService();
    ILogger logger = getLogger();
    IPartition partition = partitionService.getPartition(partitionId);
    Address owner = partition.getReplicaAddress(getReplicaIndex());
    if (!nodeEngine.getThisAddress().equals(owner)) {
        valid = false;
        if (logger.isFinestEnabled()) {
            logger.finest("Wrong target! " + toString() + " cannot be processed! Target should be: " + owner);
        }
    } else if (partitionService.isPartitionReplicaVersionStale(getPartitionId(), replicaVersions, getReplicaIndex())) {
        valid = false;
        if (logger.isFineEnabled()) {
            long[] currentVersions = partitionService.getPartitionReplicaVersions(partitionId);
            logger.fine("Ignoring stale backup! Current-versions: " + Arrays.toString(currentVersions) + ", Backup-versions: " + Arrays.toString(replicaVersions));
        }
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Address(com.hazelcast.nio.Address) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) ILogger(com.hazelcast.logging.ILogger) IPartition(com.hazelcast.spi.partition.IPartition)

Example 33 with InternalPartitionService

use of com.hazelcast.internal.partition.InternalPartitionService in project hazelcast by hazelcast.

the class Backup method run.

@Override
public void run() throws Exception {
    if (!valid) {
        onExecutionFailure(new IllegalStateException("Wrong target! " + toString() + " cannot be processed!"));
        return;
    }
    ensureBackupOperationInitialized();
    backupOp.beforeRun();
    backupOp.run();
    backupOp.afterRun();
    NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
    InternalPartitionService partitionService = nodeEngine.getPartitionService();
    partitionService.updatePartitionReplicaVersions(getPartitionId(), replicaVersions, getReplicaIndex());
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService)

Example 34 with InternalPartitionService

use of com.hazelcast.internal.partition.InternalPartitionService in project hazelcast by hazelcast.

the class XAService method clearPartitionReplica.

private void clearPartitionReplica(int partitionId) {
    InternalPartitionService partitionService = nodeEngine.getPartitionService();
    Iterator<Map.Entry<SerializableXID, List<XATransaction>>> iterator = transactions.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<SerializableXID, List<XATransaction>> entry = iterator.next();
        SerializableXID xid = entry.getKey();
        int xidPartitionId = partitionService.getPartitionId(xid);
        if (xidPartitionId == partitionId) {
            iterator.remove();
        }
    }
}
Also used : InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) MigrationEndpoint(com.hazelcast.spi.partition.MigrationEndpoint)

Example 35 with InternalPartitionService

use of com.hazelcast.internal.partition.InternalPartitionService in project hazelcast by hazelcast.

the class OperationBackupHandler method asyncBackups.

int asyncBackups(int requestedSyncBackups, int requestedAsyncBackups, boolean syncForced) {
    if (syncForced || requestedAsyncBackups == 0) {
        // if there are no asyncBackups then we are also done.
        return 0;
    }
    InternalPartitionService partitionService = node.getPartitionService();
    int maxBackupCount = partitionService.getMaxAllowedBackupCount();
    return min(maxBackupCount - requestedSyncBackups, requestedAsyncBackups);
}
Also used : InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService)

Aggregations

InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)45 Address (com.hazelcast.nio.Address)11 HazelcastInstance (com.hazelcast.core.HazelcastInstance)10 Test (org.junit.Test)10 Node (com.hazelcast.instance.Node)9 ParallelTest (com.hazelcast.test.annotation.ParallelTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 ArrayList (java.util.ArrayList)8 Config (com.hazelcast.config.Config)6 Data (com.hazelcast.nio.serialization.Data)6 IPartition (com.hazelcast.spi.partition.IPartition)6 HashMap (java.util.HashMap)6 InternalPartition (com.hazelcast.internal.partition.InternalPartition)5 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)5 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)5 List (java.util.List)5 Map (java.util.Map)5 ICacheService (com.hazelcast.cache.impl.ICacheService)4 ICacheRecordStore (com.hazelcast.cache.impl.ICacheRecordStore)3 CacheConfig (com.hazelcast.config.CacheConfig)3