-
Notifications
You must be signed in to change notification settings - Fork 122
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
Example raft cluster consensus #74
Comments
Hi @LCastilloSymbiotic , the link is broken because the project has moved to .NET Foundation. The correct link is https://github.com/dotnet/dotNext/tree/develop/src/examples/RaftNode |
Hi @sakno , I try to replicate your example, but when i try to import IClusterMemberLifetime from DotNext.Net.Cluster.Consensus.Raft; it's show a not found exeception. Do know you why? |
Could you please provide a full stack trace? |
I have this code, that's the same of your example:
Generate this error: Severity Code Description Project File Line Suppression State |
Check your ProjectReference/PackageReference elements in csproj file and import paths. The interface is definitely public and even visible on FuGet package explorer: https://www.fuget.org/packages/DotNext.AspNetCore.Cluster/3.3.0/lib/netcoreapp3.1/DotNext.AspNetCore.Cluster.dll/DotNext.Net.Cluster.Consensus.Raft/IClusterMemberLifetime |
|
No, it has both imports: https://github.com/dotnet/dotNext/blob/master/src/examples/RaftNode/RaftNode.csproj#L25 |
Ok, that's work!!! |
Hi, when execute this code:
raise this error: No service for type 'DotNext.Net.Cluster.Consensus.Raft.Http.Embedding.RaftEmbeddedCluster' has been registered.', Do you know why? This is the complete code of the startup:
|
Probably you forgot to call JoinCluster method on WebHost. I recommend you to start from the following article: https://dotnet.github.io/dotNext/features/cluster/aspnetcore.html. There is a good explanation of differences between Embedded and Hosted modes. |
Hi, not i call this, you can see the code of the Program:
and the code for the RaftManager:
And the parameters are: PersistentStorage: null |
Hello, I managed to execute the code of the example, and I read what you sent me, I have a doubt, the only thing that is synchronized (a consensus is reached) between the nodes is the Term that comes there or is it possible to customize the data to be replicated? |
@LCastilloSymbiotic , of course, there is persistent Write-Ahead Log for that and you can implement state machine on top of it. Examine this article for information. Also, the example has a replication process of monotonically increasing int64 counter. |
Hi @sakno , your implementation of Int64 LogEntry, it is as follows:
I would like to do something like the following:
But this does not work, since IRaftLogEntry (which a class in the library) uses a Long term, can I simply not use this interface or what other alternative is there? |
No, Term is a part of Raft protocol and it should be int64. |
BTW, you don't need to implement |
Perfect, I'm going to read it!!! |
To be sure if I understand, the structures to be replicated through consensus are serializable structures in JSON like the following, right?
PD:Excuse me asking so many questions, I've been confused about this. |
No, there is no restrictions about the actual binary format. JSON is just an option. For efficient I/O you need to implement |
No, but you need to implement serialization logic using |
ok, for example I have the following code: I understand that when applying the operation "var entry = state.CreateJsonLogEntry (new SubtractCommand {X = 10, Y = 20});" This would be replicated in all nodes, right? I must use these commands to replicate the data and the consensus algorithm internally will take care of the consistency of the order of execution of this command in all the nodes, right? Now in the hypothetical case that n nodes are alive and a node n + 1 connects to the network, this node (n + 1) would receive the last command which would allow it to be congruent with the rest of the nodes? |
Yes, you can use built-in JSON support for convenience (but not for performance). Overriding |
Ok, I will try to implement it, in my case it is necessary to apply it like this, since what I need to replicate is a complex object with various data. |
Probably you're trying to register multiple command handlers with the same ID. |
ok, i show you the code:
As I understand the only place where an id is placed is when creating the command, can you see that both id are different, do you see any error in that code? |
Yes, you must have only one handler for each type of command. And of course you cannot have multiple handlers for the snapshot. |
Ok it worked, I have another question, if I have the following structure:
when I go to implement it in CommandFormatter it does not allow me to write strings: Any solution for this problem? |
ValueTask WriteAsync(ReadOnlyMemory<char> chars, EncodingContext context, LengthFormat? lengthFormat, CancellationToken token = default) |
|
Do you have some example of Because, when I try to use |
You can find a lot of examples directly in tests: https://github.com/dotnet/dotNext/blob/master/src/DotNext.Tests/IO/AsyncBinaryReaderWriterTests.cs#L305 |
Do the samples work for .net core 3.1? Bause your code is this:
And my code show this error: The other problem I have is the constant, that AsMemory () can be used with string variables? |
In C#, there is no way to restrict the method to be called on |
In your example, you use this to read:
but in the library (net.core 3.1) the overload for ReadStringAsync are there: What i need to send in DecodingContext context? Can i send null? |
Hi, I got the string send to work, instead of putting null, I put default and it worked. |
I have a question about the operation of the cluster, doing tests I notice that the commands "sent" by the cluster master are replicated, but if they are sent by the slave this is not done, how can I enable or make the commands to be issued by the slave as well replicate? |
Or is there a way for a slave node to send a command to the master? |
According to Raft protocol only the leader node is responsible for replication. Otherwise, it's a violation of data consistency and linearizability. I recommend you to read basics about Raft here. |
Hello, thank you very much for your collaboration throughout these days, I have already managed to implement the library 100%, I will proceed to close the topic. Thank you!!! |
Hi,
I read your documentation and try to enter in this web link: https://github.com/sakno/dotNext/tree/develop/src/examples/RaftNode , but is show 404 error. I would like to know if you have some simple example project to use consensus for some data.
Greetings,
Luis
The text was updated successfully, but these errors were encountered: