You need to sign in or sign up before continuing.
Unverified Commit ef5d4ebb authored by Ozan Tezcan's avatar Ozan Tezcan Committed by GitHub
Browse files

Assign random id automatically to the entries (#158)

`raft_entry_t` has `id` field which is used for debugging purposes. 
Currently, it has the value of zero but we can assign a random value by default. 
User might override it if required.
parent 59a177bf
...@@ -1905,6 +1905,7 @@ raft_entry_t *raft_entry_new(unsigned int data_len) ...@@ -1905,6 +1905,7 @@ raft_entry_t *raft_entry_new(unsigned int data_len)
raft_entry_t *ety = raft_calloc(1, sizeof(raft_entry_t) + data_len); raft_entry_t *ety = raft_calloc(1, sizeof(raft_entry_t) + data_len);
ety->data_len = data_len; ety->data_len = data_len;
ety->refs = 1; ety->refs = 1;
ety->id = rand();
return ety; return ety;
} }
......
...@@ -1171,30 +1171,37 @@ class RaftServer(object): ...@@ -1171,30 +1171,37 @@ class RaftServer(object):
This is a virtraft specific check to make sure entry passing is This is a virtraft specific check to make sure entry passing is
working correctly. working correctly.
""" """
if ety.type == lib.RAFT_LOGTYPE_NO_OP: def get_last_user_entry(idx):
return while True:
if idx == lib.raft_get_snapshot_last_idx(self.raft):
return None
ci = lib.raft_get_current_idx(self.raft) prev_ety = lib.raft_get_entry_from_idx(self.raft, idx)
if 0 < ci and not lib.raft_get_snapshot_last_idx(self.raft) == ci:
other_id = None
try:
prev_ety = lib.raft_get_entry_from_idx(self.raft, ci)
assert prev_ety assert prev_ety
if prev_ety.type == lib.RAFT_LOGTYPE_NO_OP: if prev_ety.type == lib.RAFT_LOGTYPE_NO_OP:
if lib.raft_get_snapshot_last_idx(self.raft) != ci - 1: lib.raft_entry_release(prev_ety)
lib.raft_entry_release(prev_ety) idx = idx - 1
prev_ety = lib.raft_get_entry_from_idx(self.raft, ci - 1) continue
assert prev_ety
else: return prev_ety
lib.raft_entry_release(prev_ety)
return if ety.type == lib.RAFT_LOGTYPE_NO_OP:
other_id = prev_ety.id return
assert other_id < ety.id
lib.raft_entry_release(prev_ety) last_ety = None
except Exception as e:
logger.error(other_id, ety.id) try:
self.abort_exception = e ci = lib.raft_get_current_idx(self.raft)
raise last_ety = get_last_user_entry(ci)
if not last_ety:
return
assert ety.id > last_ety.id
except Exception as e:
logger.error("ids", last_ety.id, ety.id)
self.abort_exception = e
raise
def entry_append(self, ety, ety_idx): def entry_append(self, ety, ety_idx):
try: try:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment