use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class InternalPartitionServiceImpl method searchUnknownAddressesInPartitionTable.
private void searchUnknownAddressesInPartitionTable(Address sender, Set<Address> unknownAddresses, int partitionId, Address[] addresses) {
final ClusterServiceImpl clusterService = node.clusterService;
final ClusterState clusterState = clusterService.getClusterState();
for (int index = 0; index < InternalPartition.MAX_REPLICA_COUNT; index++) {
Address address = addresses[index];
if (address != null && node.clusterService.getMember(address) == null) {
if (clusterState == ClusterState.ACTIVE || !clusterService.isMemberRemovedWhileClusterIsNotActive(address)) {
if (logger.isFinestEnabled()) {
logger.finest("Unknown " + address + " found in partition table sent from master " + sender + ". It has probably already left the cluster. partitionId=" + partitionId);
}
unknownAddresses.add(address);
}
}
}
}
use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class InternalPartitionServiceImpl method logUnknownAddressesInPartitionTable.
private void logUnknownAddressesInPartitionTable(Address sender, Set<Address> unknownAddresses) {
if (!unknownAddresses.isEmpty() && logger.isWarningEnabled()) {
StringBuilder s = new StringBuilder("Following unknown addresses are found in partition table").append(" sent from master[").append(sender).append("].").append(" (Probably they have recently joined or left the cluster.)").append(" {");
for (Address address : unknownAddresses) {
s.append("\n\t").append(address);
}
s.append("\n}");
logger.warning(s.toString());
}
}
use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class MigrationPlanner method fixCycle.
// Fix cyclic partition replica movements.
// When there are cycles among replica migrations, it's impossible to define a migration order.
// For example followings are cycles:
// - [A,B] -> [B,A]
// - [A,B,C] -> [B,C,A]
boolean fixCycle(Address[] oldReplicas, Address[] newReplicas) {
boolean cyclic = false;
for (int i = 0; i < oldReplicas.length; i++) {
final Address oldAddress = oldReplicas[i];
final Address newAddress = newReplicas[i];
if (oldAddress == null || newAddress == null || oldAddress.equals(newAddress)) {
continue;
}
if (isCyclic(oldReplicas, newReplicas, i)) {
fixCycle(oldReplicas, newReplicas, i);
cyclic = true;
}
}
return cyclic;
}
use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class MigrationPlanner method isCyclic.
// Finds whether there's a migration cycle.
// For example followings are cycles:
// - [A,B] -> [B,A]
// - [A,B,C] -> [B,C,A]
boolean isCyclic(Address[] oldReplicas, Address[] newReplicas) {
for (int i = 0; i < oldReplicas.length; i++) {
final Address oldAddress = oldReplicas[i];
final Address newAddress = newReplicas[i];
if (oldAddress == null || newAddress == null || oldAddress.equals(newAddress)) {
continue;
}
if (isCyclic(oldReplicas, newReplicas, i)) {
return true;
}
}
return false;
}
use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class PartitionReplicaManager method triggerPartitionReplicaSync.
/**
* This method is called on a backup node (replica). Given all conditions are satisfied, this method initiates a replica sync
* operation and registers it to replicaSyncRequest. The operation is scheduled for a future execution if :
* <ul>
* <li>the {@code delayMillis} is greater than 0</li>
* <li>if a migration is not allowed (during repartitioning or a node joining the cluster)</li>
* <li>the partition is currently migrating</li>
* <li>another sync request has already been sent</li>
* <li>the maximum number of parallel synchronizations has already been reached</li>
* </ul>
*
* @param partitionId the partition which is being synchronized
* @param replicaIndex the index of the replica which is being synchronized
* @param delayMillis the delay before the sync operation is sent
* @throws IllegalArgumentException if the replica index is not between 0 and {@link InternalPartition#MAX_REPLICA_COUNT}
*/
public void triggerPartitionReplicaSync(int partitionId, int replicaIndex, long delayMillis) {
if (replicaIndex < 0 || replicaIndex > InternalPartition.MAX_REPLICA_COUNT) {
throw new IllegalArgumentException("Invalid replica index! replicaIndex=" + replicaIndex + " for partitionId=" + partitionId);
}
if (!checkSyncPartitionTarget(partitionId, replicaIndex)) {
return;
}
InternalPartitionImpl partition = partitionStateManager.getPartitionImpl(partitionId);
Address target = partition.getOwnerOrNull();
ReplicaSyncInfo syncInfo = new ReplicaSyncInfo(partitionId, replicaIndex, target);
if (delayMillis > 0) {
schedulePartitionReplicaSync(syncInfo, target, delayMillis, "EXPLICIT DELAY");
return;
}
// conform checkstyle return-count rule.
if (!partitionService.isReplicaSyncAllowed() || partition.isMigrating()) {
schedulePartitionReplicaSync(syncInfo, target, REPLICA_SYNC_RETRY_DELAY, "MIGRATION IS DISABLED OR PARTITION IS MIGRATING");
return;
}
if (replicaSyncRequests.compareAndSet(partitionId, null, syncInfo)) {
if (fireSyncReplicaRequest(syncInfo, target)) {
return;
}
replicaSyncRequests.compareAndSet(partitionId, syncInfo, null);
schedulePartitionReplicaSync(syncInfo, target, REPLICA_SYNC_RETRY_DELAY, "NO PERMIT AVAILABLE");
return;
}
long scheduleDelay = getReplicaSyncScheduleDelay(partitionId);
schedulePartitionReplicaSync(syncInfo, target, scheduleDelay, "ANOTHER SYNC IN PROGRESS");
}
Aggregations