guille / RaftCore

An implementation of the Raft algorithm using .NET Core
MIT License
67 stars 22 forks source link

APIRaftConnector > requestvote & appendentries API endpoints #11

Closed dhabierre closed 2 years ago

dhabierre commented 2 years ago

Hi,

First, thanks a lot for this work. I am playing with RaftCore and IAPIRaftConnector.

My goal is to host the cluster (+ 1 node) and the API in a ConsoleApp in .NET 6 using OWIN.

Perhaps I am missing something but I can't find the requestvote & appendentries API endpoints.

APIRaftConnector.cs

private async Task<string> SendRequestVote(int term, uint candidateId, int lastLogIndex, int lastLogTerm) {
{
  ...
  var response = await client.PostAsync(baseURL + "requestvote", content); // <=== requestvote
  ...
}

private async Task<string> SendAppendEntries(int term, uint leaderId, int prevLogIndex, int prevLogTerm, List<LogEntry> entries, int leaderCommit)
{
  ...
  var response = await client.PostAsync(baseURL + "appendentries", content); // <=== appendentries
  ...
}

NodesController.cs

[HttpGet("[controller]")]
public IEnumerable<IEnumerable<string>> GetNodesInfo() {
  ...
}

// GET /nodes/log/:elems
[HttpGet("[controller]/log/{elems}")]
public JsonResult GetLogs(int elems) {
  ...
}

// GET /nodes/sm
[HttpGet("[controller]/sm")]
public IEnumerable<string> GetStateMachines() {
  ...
}

// PATCH /nodes
[HttpPatch("[controller]/{id}")]
public string SwitchState(int id) {
  ...
}

// POST /nodes/requests
[HttpPost("[controller]/requests")]
public string MakeRequest() {
  ...
}

Where is my mistake? Thanks.

guille commented 2 years ago

Hey @dhabierre

RaftCoreWeb is a separate project that runs a cluster locally to visualise how the algorithm works. In order to simplify things, and since it was always meant to run only locally, it doesn't use an APIRaftConnector, but an ObjectRaftConnector (see here).

I have not developed any HTTP server implementation, but it should be relatively straightforward. Section 2.2 in the project's README, specially the last paragraph, should be helpful.

Please keep in mind the other open issues, mostly #7, if you plan to use RaftCore for anything more or less serious.

Thanks for checking out the project, though. Take care.