use of com.hazelcast.spi.impl.operationservice.OperationService in project hazelcast by hazelcast.
the class CRDTReplicationMigrationService method tryProcessOnOtherMembers.
/**
* Attempts to process the {@code operation} on at least one non-local
* member. The method will iterate through the member list and try once on
* each member.
* The method returns as soon as the first member successfully processes
* the operation or once there are no more members to try.
*
* @param serviceName the service name
* @return {@code true} if at least one member successfully processed the
* operation, {@code false} otherwise.
*/
private boolean tryProcessOnOtherMembers(Operation operation, String serviceName, long timeoutNanos) {
final OperationService operationService = nodeEngine.getOperationService();
final Collection<Member> targets = nodeEngine.getClusterService().getMembers(DATA_MEMBER_SELECTOR);
final Member localMember = nodeEngine.getLocalMember();
for (Member target : targets) {
if (target.equals(localMember)) {
continue;
}
long start = System.nanoTime();
try {
logger.fine("Replicating " + serviceName + " to " + target);
InternalCompletableFuture<Object> future = operationService.createInvocationBuilder(null, operation, target.getAddress()).setTryCount(1).invoke();
future.get(timeoutNanos, TimeUnit.NANOSECONDS);
return true;
} catch (Exception e) {
logger.fine("Failed replication of " + serviceName + " for target " + target, e);
}
timeoutNanos -= (System.nanoTime() - start);
if (timeoutNanos < 0) {
break;
}
}
return false;
}
use of com.hazelcast.spi.impl.operationservice.OperationService in project hazelcast by hazelcast.
the class CRDTMigrationTask method migrate.
/**
* Performs migration of a {@link CRDTReplicationAwareService} to the
* given target.
*
* @param service the service to migrate
* @param target the target to migrate to
* @param maxConfiguredReplicaCount the maximum configured replica count
* for the CRDTs to be migrated (excluding)
* @see CRDTReplicationAwareService
*/
private boolean migrate(CRDTReplicationAwareService service, Member target, int maxConfiguredReplicaCount) {
if (Thread.currentThread().isInterrupted()) {
return false;
}
final OperationService operationService = nodeEngine.getOperationService();
final CRDTReplicationContainer migrationOperation = service.prepareMigrationOperation(maxConfiguredReplicaCount);
if (migrationOperation == null) {
logger.finest("Skipping migration of " + service.getName() + " for target " + target);
return true;
}
try {
logger.finest("Migrating " + service.getName() + " to " + target);
operationService.invokeOnTarget(null, migrationOperation.getOperation(), target.getAddress()).joinInternal();
final boolean allMigrated = service.clearCRDTState(migrationOperation.getVectorClocks());
if (!allMigrated) {
logger.fine(service.getName() + " CRDTs have been mutated since migrated to target " + target + ". Rescheduling migration in " + MIGRATION_RETRY_DELAY_SECONDS + " second(s).");
}
return allMigrated;
} catch (Exception e) {
if (logger.isFineEnabled()) {
logger.fine("Failed migration of " + service.getName() + " for target " + target + ". Rescheduling migration in " + MIGRATION_RETRY_DELAY_SECONDS + " second(s).", e);
} else {
logger.info("Failed migration of " + service.getName() + " for target " + target + ". Rescheduling migration in " + MIGRATION_RETRY_DELAY_SECONDS + " second(s).");
}
return false;
}
}
use of com.hazelcast.spi.impl.operationservice.OperationService in project hazelcast by hazelcast.
the class CRDTReplicationTask method replicate.
/**
* Performs replication of a {@link CRDTReplicationAwareService} to the
* given target. The service may optimise the returned operation based on
* the target member and the previous successful replication operations.
*
* @param service the service to replicate
* @param target the target to replicate to
* @see CRDTReplicationAwareService
*/
private void replicate(CRDTReplicationAwareService service, Member target) {
if (Thread.currentThread().isInterrupted()) {
return;
}
final int targetIndex = getDataMemberListIndex(target);
final Map<String, VectorClock> lastSuccessfullyReplicatedClocks = replicationMigrationService.getReplicatedVectorClocks(service.getName(), target.getUuid());
final OperationService operationService = nodeEngine.getOperationService();
final CRDTReplicationContainer replicationOperation = service.prepareReplicationOperation(lastSuccessfullyReplicatedClocks, targetIndex);
if (replicationOperation == null) {
logger.finest("Skipping replication of " + service.getName() + " for target " + target);
return;
}
try {
logger.finest("Replicating " + service.getName() + " to " + target);
operationService.invokeOnTarget(null, replicationOperation.getOperation(), target.getAddress()).joinInternal();
replicationMigrationService.setReplicatedVectorClocks(service.getName(), target.getUuid(), replicationOperation.getVectorClocks());
} catch (Exception e) {
if (logger.isFineEnabled()) {
logger.fine("Failed replication of " + service.getName() + " for target " + target, e);
} else {
logger.info("Failed replication of " + service.getName() + " for target " + target);
}
}
}
use of com.hazelcast.spi.impl.operationservice.OperationService in project hazelcast by hazelcast.
the class InternalPartitionServiceImpl method sendPartitionRuntimeState.
void sendPartitionRuntimeState(Address target) {
if (!isLocalMemberMaster()) {
return;
}
assert partitionStateManager.isInitialized();
PartitionRuntimeState partitionState = createPartitionStateInternal();
assert partitionState != null;
if (logger.isFineEnabled()) {
logger.fine("Sending partition state, stamp: " + partitionState.getStamp() + ", to " + target);
}
OperationService operationService = nodeEngine.getOperationService();
PartitionStateOperation op = new PartitionStateOperation(partitionState, true);
operationService.invokeOnTarget(SERVICE_NAME, op, target);
}
use of com.hazelcast.spi.impl.operationservice.OperationService in project hazelcast by hazelcast.
the class InternalPartitionServiceImpl method checkClusterPartitionRuntimeStates.
void checkClusterPartitionRuntimeStates() {
if (!partitionStateManager.isInitialized()) {
return;
}
if (!isLocalMemberMaster()) {
return;
}
if (!areMigrationTasksAllowed()) {
// migration is disabled because of a member leave, wait till enabled!
return;
}
long stamp = getPartitionStateStamp();
if (logger.isFineEnabled()) {
logger.fine("Checking partition state, stamp: " + stamp);
}
OperationService operationService = nodeEngine.getOperationService();
Collection<Member> members = node.clusterService.getMembers();
for (Member member : members) {
if (!member.localMember()) {
PartitionStateCheckOperation op = new PartitionStateCheckOperation(stamp);
InvocationFuture<Boolean> future = operationService.invokeOnTarget(SERVICE_NAME, op, member.getAddress());
future.whenCompleteAsync((response, throwable) -> {
if (throwable == null) {
if (!Boolean.TRUE.equals(response)) {
logger.fine(member + " has a stale partition state. Will send the most recent partition state now.");
sendPartitionRuntimeState(member.getAddress());
}
} else {
logger.fine("Failure while checking partition state on " + member, throwable);
sendPartitionRuntimeState(member.getAddress());
}
});
}
}
}
Aggregations