Search in sources :

Example 1 with NoneRole

use of io.atomix.protocols.backup.roles.NoneRole 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);
            }
        }
    }
}
Also used : NoneRole(io.atomix.protocols.backup.roles.NoneRole) PrimaryRole(io.atomix.protocols.backup.roles.PrimaryRole) BackupRole(io.atomix.protocols.backup.roles.BackupRole) PrimaryBackupRole(io.atomix.protocols.backup.roles.PrimaryBackupRole) Member(io.atomix.primitive.partition.Member)

Aggregations

Member (io.atomix.primitive.partition.Member)1 BackupRole (io.atomix.protocols.backup.roles.BackupRole)1 NoneRole (io.atomix.protocols.backup.roles.NoneRole)1 PrimaryBackupRole (io.atomix.protocols.backup.roles.PrimaryBackupRole)1 PrimaryRole (io.atomix.protocols.backup.roles.PrimaryRole)1