These are chat archives for atomix/atomix

5th
May 2017
Ambud
@ambud
May 05 2017 00:55

Should a single node bootstrapping server be elected a leader? If yes, how long should it take, what determines the duration?

Storage storage = Storage.builder().withCompactionThreads(2).withStorageLevel(StorageLevel.MEMORY).build();
        AtomixReplica.Builder builder = AtomixReplica.builder(new Address("localhost", 8900))
                .withElectionTimeout(Duration.ofSeconds(5)).withHeartbeatInterval(Duration.ofSeconds(2))
                .withStorage(storage);
        AtomixReplica replica = builder.build().bootstrap(new Address("localhost", 8900)).join();
        ClusterTable table = new ClusterTable(replica, new Node("localhost", 8991));
        table.init();
        for (int i = 0; i < 10; i++) {
            System.out.println(table.getLeader("db" + i));
        }

here's the getLeader method:

public GroupMember getLeader(String dbName) throws InterruptedException, ExecutionException {
        DistributedGroup group = groupMap.get(dbName);
        if (group == null) {
            group = replica.getGroup(dbName).join();
            groupMap.put(dbName, group);
            producer.send(dbName).get();
            logger.info("Electing a new leader for database:" + dbName);
            final AtomicBoolean election = new AtomicBoolean(false);
            group.election().onElection(new Consumer<Term>() {

                @Override
                public void accept(Term t) {
                    logger.info("Leader election completed:" + t);
                    election.set(true);
                }
            });
            System.out.print("Waiting for leader election.");
            while (!election.get()) {
                System.out.print(".");
                Thread.sleep(1000);
            }
        }
        return group.election().term().leader();
    }
Currently this is stuck in waiting for leader forever with a single node
josh gruenberg
@joshng
May 05 2017 02:05
I'm not the expert, and I might be misunderstanding, but I don't see anything joining the group, so I wouldn't expect an election to take place.
Ambud
@ambud
May 05 2017 02:50
@joshng I thought this would do it group = replica.getGroup(dbName).join();```
Ambud
@ambud
May 05 2017 03:09
My bad, missing another join for group join
terrytan
@txm119161336_twitter
May 05 2017 10:16
@kuujo Thank you for your reply