Git Product home page Git Product logo

Comments (14)

sakno avatar sakno commented on August 16, 2024

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.

LCastilloSymbiotic avatar LCastilloSymbiotic commented on August 16, 2024

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.

sakno avatar sakno commented on August 16, 2024

In case of 4.x, the programming model follows recommendations from Raft paper:

  1. Get IRaftHttpCluster interface from DI
  2. Call AddMemberAsync or RemoveMemberAsync
  3. Optionally register an instance of ClusterMemberAnnouncer in DI

Also I recommend to read this article about node bootstrapping.

from dotnext.

LCastilloSymbiotic avatar LCastilloSymbiotic commented on August 16, 2024

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.

sakno avatar sakno commented on August 16, 2024

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.

LCastilloSymbiotic avatar LCastilloSymbiotic commented on August 16, 2024

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.

sakno avatar sakno commented on August 16, 2024

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.

LCastilloSymbiotic avatar LCastilloSymbiotic commented on August 16, 2024

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.

sakno avatar sakno commented on August 16, 2024

It does.

from dotnext.

LCastilloSymbiotic avatar LCastilloSymbiotic commented on August 16, 2024

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.

LCastilloSymbiotic avatar LCastilloSymbiotic commented on August 16, 2024

If you had an example I would really appreciate it.

from dotnext.

sakno avatar sakno commented on August 16, 2024

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.

sakno avatar sakno commented on August 16, 2024

.NET JSON configuration uses JSON arrays instead of indexing array elements directly:

{
  "members": ["https://192.168.31.144:3262"]
}

from dotnext.

sakno avatar sakno commented on August 16, 2024

Closing the issue due to inactivity.

from dotnext.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.