use of com.hazelcast.internal.partition.impl.InternalPartitionImpl in project hazelcast by hazelcast.
the class PartitionReplicaSyncResponse 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);
int currentReplicaIndex = partition.getReplicaIndex(PartitionReplica.from(nodeEngine.getLocalMember()));
try {
if (replicaIndex == currentReplicaIndex) {
executeOperations();
} else {
nodeNotOwnsBackup(partition);
}
if (operations != null) {
operations.clear();
}
} finally {
postProcessReplicaSync(partitionService, currentReplicaIndex);
}
}
use of com.hazelcast.internal.partition.impl.InternalPartitionImpl in project hazelcast by hazelcast.
the class PartitionReplicaSyncRequest method checkPartitionOwner.
/**
* Checks if we are the primary owner of the partition.
*/
protected boolean checkPartitionOwner() {
InternalPartitionServiceImpl partitionService = getService();
PartitionStateManager partitionStateManager = partitionService.getPartitionStateManager();
InternalPartitionImpl partition = partitionStateManager.getPartitionImpl(partitionId());
PartitionReplica owner = partition.getOwnerReplicaOrNull();
NodeEngine nodeEngine = getNodeEngine();
if (owner == null || !owner.isIdentical(nodeEngine.getLocalMember())) {
ILogger logger = getLogger();
if (logger.isFinestEnabled()) {
logger.finest("This node is not owner partition. Cannot process request. partitionId=" + partitionId() + ", replicaIndex=" + getReplicaIndex() + ", namespaces=" + namespaces);
}
return false;
}
return true;
}
use of com.hazelcast.internal.partition.impl.InternalPartitionImpl in project hazelcast by hazelcast.
the class InvocationUtilTest method executeLocallyRetriesWhenPartitionIsMigrating.
@Test
public void executeLocallyRetriesWhenPartitionIsMigrating() throws InterruptedException {
final HazelcastInstance instance = createHazelcastInstance(smallInstanceConfig());
final NodeEngineImpl nodeEngineImpl = getNodeEngineImpl(instance);
final InternalPartitionService partitionService = nodeEngineImpl.getPartitionService();
final int randomPartitionId = (int) (Math.random() * partitionService.getPartitionCount());
final InternalPartitionImpl partition = (InternalPartitionImpl) partitionService.getPartition(randomPartitionId);
partition.setMigrating();
final String operationResponse = "operationResponse";
final Operation operation = new LocalOperation(operationResponse).setPartitionId(randomPartitionId);
final LocalRetryableExecution execution = executeLocallyWithRetry(nodeEngineImpl, operation);
spawn(new Runnable() {
@Override
public void run() {
try {
TimeUnit.SECONDS.sleep(10);
} catch (InterruptedException e) {
}
partition.resetMigrating();
}
});
assertTrue(execution.awaitCompletion(1, TimeUnit.MINUTES));
assertEquals(operationResponse, execution.getResponse());
}
Aggregations