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

have problem with PersistentClusterConfigurationStorage #77

Closed
mbasij1 opened this issue Oct 26, 2021 · 3 comments
Closed

have problem with PersistentClusterConfigurationStorage #77

mbasij1 opened this issue Oct 26, 2021 · 3 comments
Assignees
Labels
question Further information is requested
Projects
Milestone

Comments

@mbasij1
Copy link

mbasij1 commented Oct 26, 2021

Hi,
I found that if I want to persist the config on file should use the class PersistentClusterConfigurationStorage. I don't know is correct or not but from tracing the source I create the class
`
internal class PersistentClusterConfigurationStorage : PersistentClusterConfigurationStorage
{
public PersistentClusterConfigurationStorage(string path, int fileBufferSize = 512, MemoryAllocator allocator = null) : base(path, fileBufferSize, allocator)
{
}
protected override void Encode(IPEndPoint address, ref BufferWriterSlim output)
{
output.WriteEndPoint(address);
}

    protected override IPEndPoint Decode(ref SequenceReader reader)
    {
        return (IPEndPoint)reader.ReadEndPoint();
    }
}

and using for persisting data
static async ValueTask AddMembersToCluster(AppSettingConfig serverConfig, PersistentClusterConfigurationStorage storage)
{
if (serverConfig.Members == null) return;
for (int i = 0; i < serverConfig.Members.Length; i++)
{
var t = Dns.GetHostAddresses(serverConfig.Members[i].EndPoint);
var ipEndPint = new IPEndPoint(t[0], serverConfig.Members[i]?.Port ?? serverConfig.PeerCommunicationPort);
await storage.AddMemberAsync(ClusterMemberId.FromEndPoint(ipEndPint), ipEndPint);
}
}
`
but when the running application LeaderChanged is not called and can't understand what is false.

@sakno sakno self-assigned this Oct 26, 2021
@sakno sakno added this to Opened in Cluster via automation Oct 26, 2021
@sakno sakno added this to the 4.0 milestone Oct 26, 2021
@sakno sakno added the question Further information is requested label Oct 26, 2021
@sakno
Copy link
Collaborator

sakno commented Oct 27, 2021

Hi @mbasij1 ,
It will not work in that way. You can add only one node at a time. I recommend you to start from this article. There is explanation of how to bootstrap the cluster. In case of HTTP transport, you don't need to implement your own persistent storage for cluster members.

@mbasij1
Copy link
Author

mbasij1 commented Oct 27, 2021

Thank You for your response.
I trying to solve a false thing!
I Delete initialized cluster from the beginning and worked. but I can't understand why we could use the AddMembersToCluster(_serverConfig, config.UseInMemoryConfigurationStorage()) and work?
Although I found that when using UseInMemoryConfigurationStorage() every node of cluster comes leader and I think they not join together!

@sakno
Copy link
Collaborator

sakno commented Oct 27, 2021

Adding multiple members at the boot time is a mistake. According to documentation, there are two ways to bootstrap the node:

  1. If you starting the first node in the cluster, use Cold Start mode. In that case, the active configuration must be empty. The node will add itself to the configuration automatically.
  2. When the cluster contains at least one node, a new member must be started in Announcement mode. The node will be in frozen state and you need to inform the cluster about that node. Usually, it's necessary to announce the node via calling of AddMemberAsync method on the leader node. Only leader node can modify the cluster configuration.

Also I recommend to read the detailed explanation of that behavior in the official paper published by the author of Raft consensus protocol: https://raw.githubusercontent.com/ongardie/dissertation/master/book.pdf, Chapter 4

@mbasij1 mbasij1 closed this as completed Oct 31, 2021
Cluster automation moved this from Opened to Closed Oct 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
Cluster
Closed
Development

No branches or pull requests

2 participants