use of com.hazelcast.internal.partition.PartitionRuntimeState in project hazelcast by hazelcast.
the class PromotionCommitOperation method readInternal.
@Override
protected void readInternal(ObjectDataInput in) throws IOException {
super.readInternal(in);
expectedMemberUuid = in.readUTF();
partitionState = new PartitionRuntimeState();
partitionState.readData(in);
int len = in.readInt();
if (len > 0) {
promotions = new ArrayList<MigrationInfo>(len);
for (int i = 0; i < len; i++) {
MigrationInfo migrationInfo = new MigrationInfo();
migrationInfo.readData(in);
promotions.add(migrationInfo);
}
}
}
use of com.hazelcast.internal.partition.PartitionRuntimeState in project hazelcast by hazelcast.
the class ClusterJoinManager method startJoin.
/**
* Starts join process on master member.
*/
private void startJoin() {
logger.fine("Starting join...");
clusterServiceLock.lock();
try {
InternalPartitionService partitionService = node.getPartitionService();
boolean shouldTriggerRepartition = true;
try {
joinInProgress = true;
// pause migrations until join, member-update and post-join operations are completed
partitionService.pauseMigration();
MemberMap memberMap = clusterService.getMembershipManager().getMemberMap();
MembersView newMembersView = MembersView.cloneAdding(memberMap.toMembersView(), joiningMembers.values());
long time = clusterClock.getClusterTime();
// member list must be updated on master before preparation of pre-/post-join ops so other operations which have
// to be executed on stable cluster can detect the member list version change and retry in case of topology change
UUID thisUuid = clusterService.getThisUuid();
if (!clusterService.updateMembers(newMembersView, node.getThisAddress(), thisUuid, thisUuid)) {
return;
}
// post join operations must be lock free, that means no locks at all:
// no partition locks, no key-based locks, no service level locks!
OnJoinOp preJoinOp = preparePreJoinOps();
OnJoinOp postJoinOp = preparePostJoinOp();
// this is the current partition assignment state, not taking into account the
// currently joining members
PartitionRuntimeState partitionRuntimeState = partitionService.createPartitionState();
for (MemberInfo member : joiningMembers.values()) {
if (isMemberRestartingWithPersistence(member.getAttributes()) && isMemberRejoining(memberMap, member.getAddress(), member.getUuid())) {
logger.info(member + " is rejoining the cluster");
// do not trigger repartition immediately, wait for joining member to load hot-restart data
shouldTriggerRepartition = false;
}
long startTime = clusterClock.getClusterStartTime();
Operation op = new FinalizeJoinOp(member.getUuid(), newMembersView, preJoinOp, postJoinOp, time, clusterService.getClusterId(), startTime, clusterStateManager.getState(), clusterService.getClusterVersion(), partitionRuntimeState, !shouldTriggerRepartition);
op.setCallerUuid(thisUuid);
invokeClusterOp(op, member.getAddress());
}
for (MemberImpl member : memberMap.getMembers()) {
if (member.localMember() || joiningMembers.containsKey(member.getAddress())) {
continue;
}
Operation op = new MembersUpdateOp(member.getUuid(), newMembersView, time, partitionRuntimeState, true);
op.setCallerUuid(thisUuid);
invokeClusterOp(op, member.getAddress());
}
} finally {
reset();
if (shouldTriggerRepartition) {
partitionService.resumeMigration();
}
}
} finally {
clusterServiceLock.unlock();
}
}
use of com.hazelcast.internal.partition.PartitionRuntimeState in project hazelcast by hazelcast.
the class InternalPartitionServiceImpl method createPromotionCommitPartitionState.
/**
* Creates a transient {@link PartitionRuntimeState} to commit promotions by applying the {@code migrationInfos}.
* The partition table version is incremented by number of promotions.
* This method will acquire the partition service lock.
*
* @param migrationInfos the promotions to be executed on the destination
* @return the partition table with the executed migrations or {@code null} if the partitions are not initialized (assigned)
*/
PartitionRuntimeState createPromotionCommitPartitionState(Collection<MigrationInfo> migrationInfos) {
lock.lock();
try {
if (!partitionStateManager.isInitialized()) {
return null;
}
List<MigrationInfo> completedMigrations = migrationManager.getCompletedMigrationsCopy();
InternalPartition[] partitions = partitionStateManager.getPartitionsCopy(false);
for (MigrationInfo migrationInfo : migrationInfos) {
int partitionId = migrationInfo.getPartitionId();
InternalPartitionImpl partition = (InternalPartitionImpl) partitions[partitionId];
applyMigration(partition, migrationInfo);
migrationInfo.setStatus(MigrationStatus.SUCCESS);
}
long stamp = calculateStamp(partitions);
return new PartitionRuntimeState(partitions, completedMigrations, stamp);
} finally {
lock.unlock();
}
}
use of com.hazelcast.internal.partition.PartitionRuntimeState 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);
}
}
}
}
Aggregations