Comments (14)
In 3.x, there is no example for IMemberDiscoveryService
because its actual implementation fully depends on the external discovery mechanism. It can be Consul, etcd, Kubernetes or even file watcher. However, you must use IMemberDiscoveryService
carefully: one node can be removed or added at a time. This restriction is not implemented by the interface or underlying Raft implementation. Otherwise, there is a non-zero probability to have more than one leader in the cluster for a short period of time.
In 4.x, this situation is solved completely. No more IMemberDiscoveryService
or configurable list of cluster members. Raft defines its own membership protocol that is implemented in the upcoming major version. For now, 4.x is available as a preview package on NuGet.
from dotnext.
Ok ok, a question in version 4.x are there examples of how to use this new union members model?
Best regards,
Luis
from dotnext.
In case of 4.x, the programming model follows recommendations from Raft paper:
- Get IRaftHttpCluster interface from DI
- Call
AddMemberAsync
orRemoveMemberAsync
- Optionally register an instance of ClusterMemberAnnouncer in DI
Also I recommend to read this article about node bootstrapping.
from dotnext.
Hi In 3.x, Is it possible to add a node manually?
I am trying something like this:
private readonly IRaftCluster _cluster;
IPEndPoint checkIP = new IPEndPoint(IPAddress.Loopback), 3262);
_cluster.Members.Aggregate(checkIP);
But I get an error for the type as it requests an IClusterMember
from dotnext.
Yes, the configuration is tracked by RaftCluster
at runtime via IOptionsMonitor. So you can change the configuration at run-time. If you're using the file for storing configuration, then just open and edit it (add new member to members
section).
from dotnext.
Don't you have an example of how to do that?
This is my normal host creation:
private static Task UseAspNetCoreHost(int port, string? persistentStorage = null)
{
var configuration = new Dictionary<string, string>
{
{"partitioning", "false"},
{"lowerElectionTimeout", "150" },
{"upperElectionTimeout", "300" },
{"requestJournal:memoryLimit", "5" },
{"requestJournal:expiration", "00:01:00" }
};
//Set local URI
LocalURI = String.Format("{0}{1}", "https://", NodesMembers[0].ToString());
//Set nodes members
for (int i = 0; i < NodesMembers.Count; i++)
{
configuration.Add(String.Format("members:{0}", i),
String.Format("{0}{1}", "https://", NodesMembers[i].ToString()));
}
if (!string.IsNullOrEmpty(persistentStorage))
configuration[CustomPersistentState.LogLocation] = persistentStorage;
return new HostBuilder().ConfigureWebHost(webHost =>
{
webHost.UseKestrel(options =>
{
options.ListenLocalhost(port, listener => listener.UseHttps(LoadCertificate()));
})
.UseStartup<StartupReplication>();
})
.ConfigureLogging(builder => builder.AddConsole().SetMinimumLevel(LogLevel.Error))
.ConfigureAppConfiguration(builder => builder.AddInMemoryCollection(configuration))
.JoinCluster()
.Build()
.RunAsync();
}
from dotnext.
Raft impl for ASP.NET Core fully relies on Configuration Model and Options pattern from the framework:
As far as I know, in-memory configuration doesn't support change tracking. Therefore, you need to write your own configuration provider with in-memory storage capabilities or change another source of configuration, e.g. json file. You can find a lot of examples in the articles mentioned above.
from dotnext.
Writing configs in eg .json doesn't make it static? I think about it in this sense, I imagine that the data from the configuration file is loaded when the cluster is created, but once it is up, it does not check the file again or does it?
from dotnext.
It does.
from dotnext.
When I insert the configuration from a dictionary like this:
var configuration = new Dictionary<string, string>
{
{"partitioning", "false"},
{"lowerElectionTimeout", "150" },
{"upperElectionTimeout", "300" },
{"requestJournal:memoryLimit", "5" },
{"requestJournal:expiration", "00:01:00" },
{"members:0", "https://192.168.31.144:3262" }
};
As I understand it, the equivalent in JSON is the following file:
{
"partitioning": "false",
"lowerElectionTimeout": "150",
"upperElectionTimeout": "300",
"requestJournal": {
"memoryLimit": "5",
"expiration": "00:01:00"
},
"members": {
"0": "https://192.168.31.144:3262"
}
}
When I insert the dictionary configuration like this, everything works perfectly:
.ConfigureAppConfiguration(builder => builder.AddInMemoryCollection(configuration))
But if I insert it via JSON this way it doesn't work, do you know why?
.ConfigureAppConfiguration(builder => builder.AddJsonFile("settingsRaft.json", optional: false, reloadOnChange: true))
from dotnext.
If you had an example I would really appreciate it.
from dotnext.
I'm not sure that the configuration mentioned above satisfies the requirements of JSON-based configuration in ASP.NET Core. Probably, the array or members should be defined in another way.
from dotnext.
.NET JSON configuration uses JSON arrays instead of indexing array elements directly:
{
"members": ["https://192.168.31.144:3262"]
}
from dotnext.
Closing the issue due to inactivity.
from dotnext.
Related Issues (20)
- `AsyncBarrier.AddParticipant()` does not work
- Cluster node status HOT 1
- DotNext vs Community toolkit
- How to use Optional<string> as query parameter? HOT 5
- Support for non-LTS .NET releases HOT 1
- Various trimming warnings in DotNext.Metaprogramming HOT 15
- Potential addition of an `OrderedDictionary<TKey, TValue>` type HOT 7
- raft leader loses leadership and the node gets stuck HOT 19
- Metaprogramming: Try-catch not catching exception HOT 2
- ask for set up workaround to make AOT works HOT 4
- Directly reference algorithm used in int sqrt HOT 3
- Not seeing expected improvement in throughput of RaftCluster.ReplicateAsync method when cluster minority is inaccessible HOT 20
- Seemingly random NullReferenceException in async state machine HOT 13
- Cache bound by weighted count HOT 1
- AsyncReaderWriterLock overload parity between Enter and Acquire HOT 1
- Add `IDisposable`-returning extension method for upgrading read lock to write lock HOT 7
- DotNext.Net.Cluster crash in production since I think version 5.4.0 HOT 24
- DotNext.Net.Cluster: System.ArgumentOutOfRangeException: Non-negative number required. (Parameter 'length') HOT 44
- If ColdStarted node is down, new leader is not elected HOT 1
- Did you remove "IEnumerable<T>.FirstOrNone"? HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dotnext.