use of com.hazelcast.spi.impl.operationservice.OperationService in project hazelcast by hazelcast.
the class TablesStorage method awaitMappingOnAllMembers.
/**
* Temporary measure to ensure schema is propagated to all the members.
*/
@SuppressWarnings("BusyWait")
private void awaitMappingOnAllMembers(String name, IdentifiedDataSerializable metadata) {
Data keyData = nodeEngine.getSerializationService().toData(name);
int keyPartitionId = nodeEngine.getPartitionService().getPartitionId(keyData);
OperationService operationService = nodeEngine.getOperationService();
Collection<Address> memberAddresses = getMemberAddresses();
for (int i = 0; i < MAX_CHECK_ATTEMPTS && !memberAddresses.isEmpty(); i++) {
List<CompletableFuture<Address>> futures = memberAddresses.stream().map(memberAddress -> {
Operation operation = new GetOperation(CATALOG_MAP_NAME, keyData).setPartitionId(keyPartitionId).setValidateTarget(false);
return operationService.createInvocationBuilder(ReplicatedMapService.SERVICE_NAME, operation, memberAddress).setTryCount(1).invoke().toCompletableFuture().thenApply(result -> Objects.equals(metadata, result) ? memberAddress : null);
}).collect(toList());
for (CompletableFuture<Address> future : futures) {
try {
memberAddresses.remove(future.join());
} catch (Exception e) {
logger.warning("Error occurred while trying to fetch mapping: " + e.getMessage(), e);
}
}
if (!memberAddresses.isEmpty()) {
try {
Thread.sleep(SLEEP_MILLIS);
} catch (InterruptedException e) {
break;
}
}
}
}
use of com.hazelcast.spi.impl.operationservice.OperationService in project hazelcast by hazelcast.
the class MigrationManager method publishCompletedMigrations.
private void publishCompletedMigrations() {
if (!partitionService.isLocalMemberMaster()) {
return;
}
assert partitionStateManager.isInitialized();
final List<MigrationInfo> migrations = getCompletedMigrationsCopy();
if (logger.isFineEnabled()) {
logger.fine("Publishing completed migrations [" + migrations.size() + "]: " + migrations);
}
OperationService operationService = nodeEngine.getOperationService();
ClusterServiceImpl clusterService = node.clusterService;
final Collection<Member> members = clusterService.getMembers();
final AtomicInteger latch = new AtomicInteger(members.size() - 1);
for (Member member : members) {
if ((member.localMember())) {
continue;
}
Operation operation = new PublishCompletedMigrationsOperation(migrations);
InternalCompletableFuture<Boolean> f = operationService.invokeOnTarget(SERVICE_NAME, operation, member.getAddress());
f.whenCompleteAsync((response, t) -> {
if (t == null) {
if (!Boolean.TRUE.equals(response)) {
logger.fine(member + " rejected completed migrations with response " + response);
partitionService.sendPartitionRuntimeState(member.getAddress());
return;
}
if (latch.decrementAndGet() == 0) {
logger.fine("Evicting " + migrations.size() + " completed migrations.");
evictCompletedMigrations(migrations);
}
} else {
logger.fine("Failure while publishing completed migrations to " + member, t);
partitionService.sendPartitionRuntimeState(member.getAddress());
}
}, asyncExecutor);
}
}
use of com.hazelcast.spi.impl.operationservice.OperationService in project hazelcast by hazelcast.
the class PartitionReplicaStateChecker method hasOnGoingMigrationMaster.
boolean hasOnGoingMigrationMaster(Level level) {
ClusterService clusterService = node.getClusterService();
Address masterAddress = clusterService.getMasterAddress();
if (masterAddress == null) {
return clusterService.isJoined();
}
Operation operation = new HasOngoingMigration();
OperationService operationService = nodeEngine.getOperationService();
InvocationFuture<Boolean> future = operationService.createInvocationBuilder(SERVICE_NAME, operation, masterAddress).setTryCount(INVOCATION_TRY_COUNT).setTryPauseMillis(INVOCATION_TRY_PAUSE_MILLIS).invoke();
try {
return future.joinInternal();
} catch (Exception e) {
logger.log(level, "Could not get a response from master about migrations! -> " + e.toString());
}
return false;
}
use of com.hazelcast.spi.impl.operationservice.OperationService in project hazelcast by hazelcast.
the class InternalPartitionServiceImpl method publishPartitionRuntimeState.
/**
* Called on the master node to publish the current partition state to all cluster nodes. It will not publish the partition
* state if the partitions have not yet been initialized, there is ongoing repartitioning or a node is joining the cluster.
*/
@SuppressWarnings("checkstyle:npathcomplexity")
void publishPartitionRuntimeState() {
if (!partitionStateManager.isInitialized()) {
// do not send partition state until initialized!
return;
}
if (!isLocalMemberMaster()) {
return;
}
if (!areMigrationTasksAllowed()) {
// migration is disabled because of a member leave, wait till enabled!
return;
}
PartitionRuntimeState partitionState = createPartitionStateInternal();
if (partitionState == null) {
return;
}
if (logger.isFineEnabled()) {
logger.fine("Publishing partition state, stamp: " + partitionState.getStamp());
}
PartitionStateOperation op = new PartitionStateOperation(partitionState, false);
OperationService operationService = nodeEngine.getOperationService();
Collection<Member> members = node.clusterService.getMembers();
for (Member member : members) {
if (!member.localMember()) {
try {
operationService.send(op, member.getAddress());
} catch (Exception e) {
logger.finest(e);
}
}
}
}
use of com.hazelcast.spi.impl.operationservice.OperationService in project hazelcast by hazelcast.
the class AbstractPartitionPrimaryReplicaAntiEntropyTask method invokePartitionBackupReplicaAntiEntropyOp.
final void invokePartitionBackupReplicaAntiEntropyOp(int replicaIndex, PartitionReplica target, Collection<ServiceNamespace> namespaces, BiConsumer<Object, Throwable> callback) {
if (skipSendingToTarget(target)) {
return;
}
PartitionReplicaManager replicaManager = partitionService.getReplicaManager();
Map<ServiceNamespace, Long> versionMap = new HashMap<>();
for (ServiceNamespace ns : namespaces) {
long[] versions = replicaManager.getPartitionReplicaVersions(partitionId, ns);
long currentReplicaVersion = versions[replicaIndex - 1];
versionMap.put(ns, currentReplicaVersion);
}
boolean hasCallback = (callback != null);
Operation op = new PartitionBackupReplicaAntiEntropyOperation(versionMap, hasCallback);
op.setPartitionId(partitionId).setReplicaIndex(replicaIndex).setServiceName(SERVICE_NAME);
ILogger logger = nodeEngine.getLogger(getClass());
if (logger.isFinestEnabled()) {
logger.finest("Sending anti-entropy operation to " + target + " for partitionId=" + partitionId + ", replicaIndex=" + replicaIndex + ", namespaces=" + versionMap);
}
OperationService operationService = nodeEngine.getOperationService();
if (hasCallback) {
operationService.createInvocationBuilder(SERVICE_NAME, op, target.address()).setTryCount(OPERATION_TRY_COUNT).setTryPauseMillis(OPERATION_TRY_PAUSE_MILLIS).invoke().whenCompleteAsync(callback);
} else {
operationService.send(op, target.address());
}
}
Aggregations