use of io.atomix.protocols.backup.roles.BackupRole in project atomix by atomix.
the class PrimaryBackupServiceContext method changeRole.
/**
* Changes the roles.
*/
private void changeRole(PrimaryTerm term) {
if (term.term() > currentTerm) {
log.debug("Term changed: {}", term);
currentTerm = term.term();
primary = term.primary() != null ? term.primary().nodeId() : null;
backups = term.backups(descriptor.backups()).stream().map(Member::nodeId).collect(Collectors.toList());
if (Objects.equals(primary, clusterService.getLocalNode().id())) {
if (this.role == null) {
this.role = new PrimaryRole(this);
log.debug("{} transitioning to {}", clusterService.getLocalNode().id(), Role.PRIMARY);
} else if (this.role.role() != Role.PRIMARY) {
this.role.close();
this.role = new PrimaryRole(this);
log.debug("{} transitioning to {}", clusterService.getLocalNode().id(), Role.PRIMARY);
}
} else if (backups.contains(clusterService.getLocalNode().id())) {
if (this.role == null) {
this.role = new BackupRole(this);
log.debug("{} transitioning to {}", clusterService.getLocalNode().id(), Role.BACKUP);
} else if (this.role.role() != Role.BACKUP) {
this.role.close();
this.role = new BackupRole(this);
log.debug("{} transitioning to {}", clusterService.getLocalNode().id(), Role.BACKUP);
}
} else {
if (this.role == null) {
this.role = new NoneRole(this);
log.debug("{} transitioning to {}", clusterService.getLocalNode().id(), Role.NONE);
} else if (this.role.role() != Role.NONE) {
this.role.close();
this.role = new NoneRole(this);
log.debug("{} transitioning to {}", clusterService.getLocalNode().id(), Role.NONE);
}
}
}
}
Aggregations