use of com.hazelcast.internal.partition.impl.PartitionStateManager 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);
}
}
use of com.hazelcast.internal.partition.impl.PartitionStateManager 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);
}
}
use of com.hazelcast.internal.partition.impl.PartitionStateManager in project hazelcast by hazelcast.
the class ReplicaSyncRequest method preCheckReplicaSync.
/** Checks if we can continue with the replication or not. Can send a retry or empty response to the replica in some cases */
private boolean preCheckReplicaSync(NodeEngineImpl nodeEngine, int partitionId, int replicaIndex) throws IOException {
InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) nodeEngine.getPartitionService();
PartitionStateManager partitionStateManager = partitionService.getPartitionStateManager();
InternalPartitionImpl partition = partitionStateManager.getPartitionImpl(partitionId);
Address owner = partition.getOwnerOrNull();
long[] replicaVersions = partitionService.getPartitionReplicaVersions(partitionId);
long currentVersion = replicaVersions[replicaIndex - 1];
ILogger logger = getLogger();
if (!nodeEngine.getThisAddress().equals(owner)) {
if (logger.isFinestEnabled()) {
logger.finest("Wrong target! " + toString() + " cannot be processed! Target should be: " + owner);
}
sendRetryResponse();
return false;
}
if (currentVersion == 0) {
if (logger.isFinestEnabled()) {
logger.finest("Current replicaVersion=0, sending empty response for partitionId=" + getPartitionId() + ", replicaIndex=" + getReplicaIndex() + ", replicaVersions=" + Arrays.toString(replicaVersions));
}
sendEmptyResponse();
return false;
}
if (!partitionService.getReplicaManager().tryToAcquireReplicaSyncPermit()) {
if (logger.isFinestEnabled()) {
logger.finest("Max parallel replication process limit exceeded! Could not run replica sync -> " + toString());
}
sendRetryResponse();
return false;
}
return true;
}
use of com.hazelcast.internal.partition.impl.PartitionStateManager in project hazelcast by hazelcast.
the class FinalizeMigrationOperation method run.
@Override
public void run() {
NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
notifyServices(nodeEngine);
if (endpoint == MigrationEndpoint.SOURCE && success) {
commitSource();
} else if (endpoint == MigrationEndpoint.DESTINATION && !success) {
rollbackDestination();
}
InternalPartitionServiceImpl partitionService = getService();
PartitionStateManager partitionStateManager = partitionService.getPartitionStateManager();
partitionStateManager.clearMigratingFlag(migrationInfo.getPartitionId());
if (success) {
nodeEngine.onPartitionMigrate(migrationInfo);
}
}
use of com.hazelcast.internal.partition.impl.PartitionStateManager in project hazelcast by hazelcast.
the class BaseMigrationOperation method setActiveMigration.
void setActiveMigration() {
InternalPartitionServiceImpl partitionService = getService();
MigrationManager migrationManager = partitionService.getMigrationManager();
MigrationInfo currentActiveMigration = migrationManager.setActiveMigration(migrationInfo);
if (currentActiveMigration != null) {
throw new RetryableHazelcastException("Cannot set active migration to " + migrationInfo + ". Current active migration is " + currentActiveMigration);
}
PartitionStateManager partitionStateManager = partitionService.getPartitionStateManager();
partitionStateManager.setMigratingFlag(migrationInfo.getPartitionId());
}
Aggregations