use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class InternalPartitionServiceImpl method requestMemberListUpdateIfUnknownMembersFound.
private void requestMemberListUpdateIfUnknownMembersFound(Address sender, InternalPartition[] partitions) {
ClusterServiceImpl clusterService = node.clusterService;
ClusterState clusterState = clusterService.getClusterState();
Set<PartitionReplica> unknownReplicas = new HashSet<>();
for (InternalPartition partition : partitions) {
for (int index = 0; index < InternalPartition.MAX_REPLICA_COUNT; index++) {
PartitionReplica replica = partition.getReplica(index);
if (replica == null) {
continue;
}
if (node.clusterService.getMember(replica.address(), replica.uuid()) == null && (clusterState.isJoinAllowed() || !clusterService.isMissingMember(replica.address(), replica.uuid()))) {
unknownReplicas.add(replica);
}
}
}
if (!unknownReplicas.isEmpty()) {
if (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 (PartitionReplica replica : unknownReplicas) {
s.append("\n\t").append(replica);
}
s.append("\n}");
logger.warning(s.toString());
}
Address masterAddress = node.getClusterService().getMasterAddress();
// If node is shutting down, master can be null.
if (masterAddress != null && !masterAddress.equals(node.getThisAddress())) {
// unknown addresses found in partition table, request a new member-list from master
nodeEngine.getOperationService().send(new TriggerMemberListPublishOp(), masterAddress);
}
}
}
use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class MigrationManager method finalizeMigration.
/**
* Finalizes a migration that has finished with {@link MigrationStatus#SUCCESS}
* or {@link MigrationStatus#FAILED} by invoking {@link FinalizeMigrationOperation}
* locally if this is the source or destination. The finalization is asynchronous
* and there might be other ongoing migration finalizations.
* <p>
* It will also cleanup the migration state by removing the active migration and
* clearing the migration flag on the partition owner.
* <p>
* This method should not be called on a node which is not the source, destination
* or partition owner for this migration.
*
* @param migrationInfo the migration to be finalized
*/
void finalizeMigration(MigrationInfo migrationInfo) {
try {
PartitionReplica localReplica = PartitionReplica.from(node.getLocalMember());
int partitionId = migrationInfo.getPartitionId();
boolean source = localReplica.equals(migrationInfo.getSource());
boolean destination = localReplica.equals(migrationInfo.getDestination());
assert migrationInfo.getStatus() == MigrationStatus.SUCCESS || migrationInfo.getStatus() == MigrationStatus.FAILED : "Invalid migration: " + migrationInfo;
if (source || destination) {
boolean success = migrationInfo.getStatus() == MigrationStatus.SUCCESS;
MigrationParticipant participant = source ? MigrationParticipant.SOURCE : MigrationParticipant.DESTINATION;
if (success) {
migrationInterceptor.onMigrationCommit(participant, migrationInfo);
} else {
migrationInterceptor.onMigrationRollback(participant, migrationInfo);
}
MigrationEndpoint endpoint = source ? MigrationEndpoint.SOURCE : MigrationEndpoint.DESTINATION;
FinalizeMigrationOperation op = new FinalizeMigrationOperation(migrationInfo, endpoint, success);
op.setPartitionId(partitionId).setNodeEngine(nodeEngine).setValidateTarget(false).setService(partitionService);
registerFinalizingMigration(migrationInfo);
OperationServiceImpl operationService = nodeEngine.getOperationService();
if (logger.isFineEnabled()) {
logger.fine("Finalizing " + migrationInfo);
}
if (operationService.isRunAllowed(op)) {
// When migration finalization is triggered by subsequent migrations
// on partition thread, finalization may run directly on calling thread.
// Otherwise, if previously completed migration and newly submitted migration
// are on the same partition, then finalizing previous migration later will
// break the order, hence safety.
operationService.run(op);
} else {
operationService.execute(op);
}
removeActiveMigration(migrationInfo);
} else {
PartitionReplica partitionOwner = partitionStateManager.getPartitionImpl(partitionId).getOwnerReplicaOrNull();
if (localReplica.equals(partitionOwner)) {
// This is the primary owner of the partition and the migration was a backup replica migration.
// In this case, primary owner has nothing to do anymore,
// just remove the active migration and clear the migrating flag.
removeActiveMigration(migrationInfo);
partitionStateManager.clearMigratingFlag(partitionId);
} else {
logger.severe("Failed to finalize migration because " + localReplica + " is not a participant of the migration: " + migrationInfo);
}
}
} catch (Exception e) {
logger.warning(e);
}
}
use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class MigrationManager method logMigrationCommitFailure.
private void logMigrationCommitFailure(MigrationInfo migration, Throwable t) {
boolean memberLeft = t instanceof MemberLeftException || t.getCause() instanceof TargetNotMemberException || t.getCause() instanceof HazelcastInstanceNotActiveException;
PartitionReplica destination = migration.getDestination();
if (memberLeft) {
if (destination.isIdentical(node.getLocalMember())) {
logger.fine("Migration commit failed for " + migration + " since this node is shutting down.");
return;
}
logger.warning("Migration commit failed for " + migration + " since destination " + destination + " left the cluster");
} else {
logger.severe("Migration commit to " + destination + " failed for " + migration, t);
}
}
use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class OperationBackupHandler method sendSingleBackup.
private int sendSingleBackup(BackupAwareOperation backupAwareOp, InternalPartition partition, long[] replicaVersions, int syncBackups, int replica) {
Operation backupOp = getBackupOperation(backupAwareOp);
PartitionReplica target = partition.getReplica(replica);
if (target != null) {
if (skipSendingBackupToTarget(partition, target)) {
return 0;
}
// without any unnecessary memory allocation and copy when it is used as object inside `Backup`.
if (backupOp instanceof TargetAware) {
((TargetAware) backupOp).setTarget(target.address());
}
boolean isSyncBackup = syncBackups == 1;
Backup backup = newBackup(backupAwareOp, backupOp, replicaVersions, 1, isSyncBackup);
outboundOperationHandler.send(backup, target.address());
if (isSyncBackup) {
return 1;
}
}
return 0;
}
use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class OperationRunnerImpl method ensureNoPartitionProblems.
private void ensureNoPartitionProblems(Operation op) {
int partitionId = op.getPartitionId();
if (partitionId < 0) {
return;
}
if (partitionId != getPartitionId()) {
throw new IllegalStateException("wrong partition, expected: " + getPartitionId() + " but found:" + partitionId);
}
if (internalPartition == null) {
internalPartition = nodeEngine.getPartitionService().getPartition(partitionId);
}
if (!isAllowedToRetryDuringMigration(op) && internalPartition.isMigrating()) {
throw new PartitionMigratingException(thisAddress, partitionId, op.getClass().getName(), op.getServiceName());
}
PartitionReplica owner = internalPartition.getReplica(op.getReplicaIndex());
if (op.validatesTarget() && (owner == null || !owner.isIdentical(node.getLocalMember()))) {
Member target = owner != null ? node.getClusterService().getMember(owner.address(), owner.uuid()) : null;
throw new WrongTargetException(node.getLocalMember(), target, partitionId, op.getReplicaIndex(), op.getClass().getName(), op.getServiceName());
}
}
Aggregations