Comments (4)
I suggest that the library need to provide asynchronous interfaces to write operations.
It is also best to provide batch write interfaces, because one by one is too slow.
such as:
typedef struct
{
/** number of entries within this batch */
int n_entries;
/** array of entries within this batch */
raft_entry_t* entries[0];
} raft_batch_t;
int log_append_entry(log_t* me_, raft_batch_t* bat)
{
log_private_t* me = (log_private_t*)me_;
int e;
e = __ensurecapacity(me, bat->n_entries);
if (e != 0)
return e;
for (int i = 0; i < bat->n_entries; i ++) {
int back = (me->back + i) % me->size;
memcpy(&me->entries[back], bat->entries[i], sizeof(raft_entry_t));
}
void* ud = raft_get_udata(me->raft);
if (me->cb) {
if (me->cb->log_offer_batch) {
int idx = me->base + me->count + 1;
e = me->cb->log_offer_batch(me->raft, ud, bat, idx);
if (0 != e)
return e;
for (int i = 0; i < bat->n_entries; i ++) {
idx = me->base + me->count + 1 + i;
raft_offer_log(me->raft, bat->entries[i], idx);
}
} else if (me->cb->log_offer) {
for (int i = 0; i < bat->n_entries; i ++) {
int idx = me->base + me->count + 1 + i;
e = me->cb->log_offer(me->raft, ud, bat->entries[i], idx);
if (0 != e)
return e;
raft_offer_log(me->raft, bat->entries[i], idx);
}
}
}
me->count += bat->n_entries;
me->back += bat->n_entries;
me->back = me->back % me->size;
return 0;
}
from raft.
I'm not entirely sure @skypexu and @vgfree intended it as well, but it'd be nice to also have the leader not wait for its own log to be written and synced to disk, effectively performing its own local AppendEntries in parallel with the network AppendEntries RPCs. The matchedIndex array should include the leader itself, and the leader should update it when it's done with its local disk write. This eliminates a disk write from raft's critical path. Note that an entry can be then considered committed even before the leader finishes writing it to its own local disk, if a majority of followers respond that they have appended it.
See "10.2.1 Writing to the leader’s disk in parallel" in Ongaro's Consenus: bridging theory and practice
dissertation. His LogCabin implementation of raft uses this optimization.
from raft.
@vgfree regarding batch interfaces feature request, I'd say it's essentially tracked by #16.
from raft.
I'm not entirely sure @skypexu and @vgfree intended it as well, but it'd be nice to also have the leader not wait for its own log to be written and synced to disk, effectively performing its own local AppendEntries in parallel with the network AppendEntries RPCs. The matchedIndex array should include the leader itself, and the leader should update it when it's done with its local disk write. This eliminates a disk write from raft's critical path. Note that an entry can be then considered committed even before the leader finishes writing it to its own local disk, if a majority of followers respond that they have appended it.
See "10.2.1 Writing to the leader’s disk in parallel" in Ongaro's
Consenus: bridging theory and practice
dissertation. His LogCabin implementation of raft uses this optimization.
Yes, I agree it should write to leader's disk in parallel.
from raft.
Related Issues (20)
- Possible issues HOT 1
- How to add SOVERSION to libraft.so?
- Not implemented log_clear callback leads to not synchronized logs
- reserved identifier violation
- Unused raft_term_t term in log_load_from_snapshot
- potential race condition in removing/adding same node?
- Should we submit empty log after a new leader elected?
- Allow easy build without coverage symbols and AddressSanitizer
- Errors `undefined reference to raft_new()` and `undefined reference to raft_add_node(void**, void*, int, int)` HOT 1
- leader election without log involved? HOT 8
- Documents are old HOT 5
- Add PreVote support
- raft_send_appendentries_all logic HOT 1
- Log interface decoupling HOT 5
- Empty AppendEntries requests are sent during non-idle periods
- FSM log entries are applied lazily HOT 1
- Leader goes into infinite send_snapshot loop HOT 4
- Meaning of entry_idx in log_offer
- log_get_from_idx not including entries that have wrapped around? HOT 2
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 raft.