Skip to content

Commit

Permalink
Can work with big inflights
Browse files Browse the repository at this point in the history
  • Loading branch information
resetius committed Nov 28, 2023
1 parent 45bb770 commit 6f3aa60
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <server.h>

uint64_t inflight = 0;
uint64_t maxInflight = 1;
uint64_t maxInflight = 128;

struct TLineSplitter {
public:
Expand Down
8 changes: 7 additions & 1 deletion src/raft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,11 @@ TMessageHolder<TRequestVoteRequest> TRaft::CreateVote() {
}

std::vector<TMessageHolder<TAppendEntriesRequest>> TRaft::CreateAppendEntries() {
static constexpr int batchSize = 128;
std::vector<TMessageHolder<TAppendEntriesRequest>> res;
for (auto [nodeId, _] : Nodes) {
auto prevIndex = VolatileState->NextIndex[nodeId] - 1;
auto lastIndex = std::min(prevIndex+1, (uint64_t)State->Log.size());
auto lastIndex = std::min(prevIndex+batchSize, (uint64_t)State->Log.size());
if (VolatileState->MatchIndex[nodeId]+1 < VolatileState->NextIndex[nodeId]) {
lastIndex = prevIndex;
}
Expand Down Expand Up @@ -378,6 +379,11 @@ std::unique_ptr<TResult> TRaft::Leader(ITimeSource::Time now, TMessageHolder<TMe
void TRaft::Become(EState newStateName) {
if (StateName != newStateName) {
StateName = newStateName;
if (StateName == EState::LEADER) {
for (auto [id, _] : Nodes) {
VolatileState->NextIndex[id] = State->Log.size()+1;
}
}
Process(NewTimeout());
}
}
Expand Down

0 comments on commit 6f3aa60

Please sign in to comment.