use of com.hazelcast.internal.partition.InternalPartition in project hazelcast by hazelcast.
the class InternalPartitionServiceImpl method createPartitionStateInternal.
public PartitionRuntimeState createPartitionStateInternal() {
lock.lock();
try {
if (!partitionStateManager.isInitialized()) {
return null;
}
List<MigrationInfo> completedMigrations = migrationManager.getCompletedMigrationsCopy();
InternalPartition[] partitions = partitionStateManager.getPartitions();
PartitionRuntimeState state = new PartitionRuntimeState(partitions, completedMigrations, getPartitionStateVersion());
state.setActiveMigration(migrationManager.getActiveMigration());
return state;
} finally {
lock.unlock();
}
}
use of com.hazelcast.internal.partition.InternalPartition in project hazelcast by hazelcast.
the class PartitionReplicaStateChecker method invokeReplicaSyncOperations.
@SuppressWarnings("checkstyle:npathcomplexity")
private int invokeReplicaSyncOperations(int maxBackupCount, Semaphore semaphore, AtomicBoolean result) {
Address thisAddress = node.getThisAddress();
ExecutionCallback<Object> callback = new ReplicaSyncResponseCallback(result, semaphore);
ClusterServiceImpl clusterService = node.getClusterService();
ClusterState clusterState = clusterService.getClusterState();
boolean isClusterActive = clusterState == ClusterState.ACTIVE || clusterState == ClusterState.IN_TRANSITION;
int ownedCount = 0;
for (InternalPartition partition : partitionStateManager.getPartitions()) {
Address owner = partition.getOwnerOrNull();
if (owner == null) {
result.set(false);
continue;
}
if (!thisAddress.equals(owner)) {
continue;
}
ownedCount++;
if (maxBackupCount == 0) {
if (partition.isMigrating()) {
result.set(false);
}
continue;
}
for (int index = 1; index <= maxBackupCount; index++) {
Address replicaAddress = partition.getReplicaAddress(index);
if (replicaAddress == null) {
result.set(false);
semaphore.release();
continue;
}
if (!isClusterActive && clusterService.isMemberRemovedWhileClusterIsNotActive(replicaAddress)) {
semaphore.release();
continue;
}
CheckReplicaVersionTask task = new CheckReplicaVersionTask(nodeEngine, partitionService, partition.getPartitionId(), index, callback);
nodeEngine.getOperationService().execute(task);
}
}
return ownedCount;
}
use of com.hazelcast.internal.partition.InternalPartition in project hazelcast by hazelcast.
the class PartitionStateGeneratorImpl method initialize.
private void initialize(InternalPartition[] currentState, Address[][] state) {
int partitionCount = currentState.length;
for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
InternalPartition p = currentState[partitionId];
Address[] replicas = state[partitionId];
boolean empty = true;
for (int index = 0; index < InternalPartition.MAX_REPLICA_COUNT; index++) {
replicas[index] = p.getReplicaAddress(index);
empty &= replicas[index] == null;
}
if (empty) {
continue;
}
// auto shift-up colder replicas to hotter replicas to fill the empty gaps
int maxReplicaIndex = InternalPartition.MAX_REPLICA_COUNT - 1;
for (int index = 0; index < InternalPartition.MAX_REPLICA_COUNT; index++) {
if (replicas[index] == null) {
for (int k = maxReplicaIndex; k > index; k--) {
if (replicas[k] != null) {
replicas[index] = replicas[k];
replicas[k] = null;
maxReplicaIndex = k - 1;
break;
}
}
}
}
}
}
use of com.hazelcast.internal.partition.InternalPartition in project hazelcast by hazelcast.
the class MigrationRequestOperation method run.
@Override
public void run() {
NodeEngine nodeEngine = getNodeEngine();
verifyGoodMaster(nodeEngine);
Address source = migrationInfo.getSource();
Address destination = migrationInfo.getDestination();
verifyExistingTarget(nodeEngine, destination);
if (destination.equals(source)) {
getLogger().warning("Source and destination addresses are the same! => " + toString());
setFailed();
return;
}
InternalPartition partition = getPartition();
verifySource(nodeEngine.getThisAddress(), partition);
setActiveMigration();
if (!migrationInfo.startProcessing()) {
getLogger().warning("Migration is cancelled -> " + migrationInfo);
setFailed();
return;
}
try {
executeBeforeMigrations();
Collection<Operation> tasks = prepareMigrationOperations();
InternalPartitionServiceImpl partitionService = getService();
long[] replicaVersions = partitionService.getPartitionReplicaVersions(migrationInfo.getPartitionId());
invokeMigrationOperation(destination, replicaVersions, tasks);
returnResponse = false;
} catch (Throwable e) {
logThrowable(e);
setFailed();
} finally {
migrationInfo.doneProcessing();
}
}
use of com.hazelcast.internal.partition.InternalPartition in project hazelcast by hazelcast.
the class ReplicatedMapService method triggerAntiEntropy.
/** Send an operation to all replicas to check their replica versions for all partitions for which this node is the owner */
public void triggerAntiEntropy() {
if (clusterService.getSize(DATA_MEMBER_SELECTOR) == 1) {
return;
}
Collection<Address> addresses = new ArrayList<Address>(getMemberAddresses(DATA_MEMBER_SELECTOR));
addresses.remove(nodeEngine.getThisAddress());
for (int i = 0; i < partitionContainers.length; i++) {
Address thisAddress = nodeEngine.getThisAddress();
InternalPartition partition = partitionService.getPartition(i, false);
Address ownerAddress = partition.getOwnerOrNull();
if (!thisAddress.equals(ownerAddress)) {
continue;
}
PartitionContainer partitionContainer = partitionContainers[i];
if (partitionContainer.isEmpty()) {
continue;
}
for (Address address : addresses) {
CheckReplicaVersionOperation checkReplicaVersionOperation = new CheckReplicaVersionOperation(partitionContainer);
checkReplicaVersionOperation.setPartitionId(i);
checkReplicaVersionOperation.setValidateTarget(false);
operationService.createInvocationBuilder(SERVICE_NAME, checkReplicaVersionOperation, address).setTryCount(INVOCATION_TRY_COUNT).invoke();
}
}
}
Aggregations