Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class is not registered: io.atomix.cluster.MemberId #1053

Closed
eonie opened this issue Oct 2, 2019 · 5 comments
Closed

Class is not registered: io.atomix.cluster.MemberId #1053

eonie opened this issue Oct 2, 2019 · 5 comments
Labels
archived Archived issues from the legacy Java implementation of Atomix legacy Issues from the legacy Java implementation of Atomix

Comments

@eonie
Copy link

eonie commented Oct 2, 2019

Expected behavior

Run leader election successful

Actual behavior

When run leader election, i got an error

Exception in thread "main" java.lang.IllegalArgumentException: Class is not registered: io.atomix.cluster.MemberId
Note: To register this class use: kryo.register(io.atomix.cluster.MemberId.class);
	at com.esotericsoftware.kryo.Kryo.getRegistration(Kryo.java:503)
	at com.esotericsoftware.kryo.util.DefaultClassResolver.writeClass(DefaultClassResolver.java:97)
	at com.esotericsoftware.kryo.Kryo.writeClass(Kryo.java:540)
	at com.esotericsoftware.kryo.Kryo.writeClassAndObject(Kryo.java:645)
	at io.atomix.utils.serializer.Namespace.lambda$null$0(Namespace.java:347)
	at com.esotericsoftware.kryo.pool.KryoPoolQueueImpl.run(KryoPoolQueueImpl.java:58)
	at io.atomix.utils.serializer.Namespace.lambda$serialize$1(Namespace.java:346)
	at io.atomix.utils.serializer.KryoIOPool.run(KryoIOPool.java:45)
	at io.atomix.utils.serializer.Namespace.serialize(Namespace.java:345)
	at io.atomix.utils.serializer.Namespace.serialize(Namespace.java:334)
	at io.atomix.utils.serializer.Serializer$1.encode(Serializer.java:71)
	at io.atomix.core.election.impl.DefaultLeaderElectionBuilder.lambda$null$1(DefaultLeaderElectionBuilder.java:44)
	at io.atomix.core.election.impl.TranscodingAsyncLeaderElection.run(TranscodingAsyncLeaderElection.java:52)
	at io.atomix.core.election.impl.BlockingLeaderElection.run(BlockingLeaderElection.java:49)
	at org.turnera.server.cluster.Server3.main(Server3.java:21)

Minimal yet complete reproducer code (or URL to code)

public class AotmixServer {
    public static CompletableFuture<Atomix> getServer(int port, Collection<Integer> ports) {
        String server = "server" + port;
        List<String> servers = ports.stream().map(p -> "server" + p).collect(Collectors.toList());

        AtomixBuilder builder = Atomix.builder();
        builder.withMemberId(server).withAddress("127.0.0.1", port)
                .withMembershipProvider(new BootstrapDiscoveryProvider(ports.stream()
                        .map(p -> Node.builder().withId("server" + p)
                                .withAddress(p).build())
                        .collect(Collectors.toList())))
                .withManagementGroup(RaftPartitionGroup.builder("system")
                        .withNumPartitions(1).withMembers(servers)
                        .withDataDirectory(new File("mngdir", server))
                        .withStorageLevel(StorageLevel.MEMORY).build())
                .addPartitionGroup(RaftPartitionGroup.builder("data")
                        .withNumPartitions(1).withMembers(servers)
                        .withDataDirectory(new File("datadir", server))
                        .withStorageLevel(StorageLevel.MEMORY).build());
        Atomix atomix = builder.build();

        atomix.getMembershipService().addListener(event -> System.out.println(event.toString()));

        System.out.println("trying to start " + server + " on port " + port + ".");
        return CompletableFuture.supplyAsync(() -> {
            atomix.start().join();
            return atomix;
        });
    }

}

public class Server1 {

    public static void main(String[] args) {
        List< Integer> ports = Arrays.asList(5002, 5003, 5004);
        int cur = 5002;
        Atomix atomix = AotmixServer.getServer(cur, ports).join();
        AtomicValue<String> value = atomix.getAtomicValue("value");
        // Get or create a leader election
        LeaderElection<MemberId> election = atomix.getLeaderElection("my-election");

        // Enter the election
        Leadership<MemberId> leadership = election.run(atomix.getMembershipService().getLocalMember().id());

        // Check if the current node is the leader
        if (leadership.leader().equals(atomix.getMembershipService().getLocalMember().id())) {
            System.out.println("I am the leader!");
        }

        // Listen for changes in leadership
        election.addListener(event -> {
            if (event.newLeadership().leader().equals(atomix.getMembershipService().getLocalMember().id())) {
                System.out.println("I am the leader!");
            }
        });
        System.out.println("done");
    }
}

Environment

  • Atomix: [3.0.15]
  • OS: [macOS 10.14.4 ]
  • JVM [1.8.0_121]
@santhoshTpixler
Copy link

In Atomix: [3.1.5] the below code works. Not able to find the documentation. Anyway figured it out.

  Serializer s = Serializer.builder().withRegistrationRequired(false).build();

    LeaderElection<MemberId> election =
        atomix
            .<MemberId>leaderElectionBuilder("my-election")
            .withSerializer(s)
            .withProtocol(
                MultiRaftProtocol.builder()
                    .withReadConsistency(ReadConsistency.LINEARIZABLE)
                    .build())
            .build();

@franz1981
Copy link

@santhoshTpixler Thanks, I'm trying with the last version this same fix: but is a required step? I mean, on the doc I haven't found it to be necessary to get the election to work.

@johnou
Copy link
Member

johnou commented Apr 24, 2020

no shouldn't be required, it means the default serializer for the leaderelection code is missing MemberId, setting a custom serializer, especially with reg required false is a hacky work-around.

@johnou
Copy link
Member

johnou commented Apr 26, 2020

so after further investigation, I believe the correct fix for this, is to add a new "elementType" configuration to io.atomix.core.election.LeaderElectionConfig and io.atomix.core.election.LeaderElectorConfig then register that in DefaultLeaderElectionBuilder and DefaultLeaderElectorBuilder in a serializer override.

@johnou
Copy link
Member

johnou commented May 1, 2020

As a work around you might consider using string of the member id.

@kuujo kuujo closed this as completed Jan 13, 2023
@kuujo kuujo added archived Archived issues from the legacy Java implementation of Atomix legacy Issues from the legacy Java implementation of Atomix labels Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
archived Archived issues from the legacy Java implementation of Atomix legacy Issues from the legacy Java implementation of Atomix
Projects
None yet
Development

No branches or pull requests

5 participants