Skip to content

Commit

Permalink
tools/offline_log_viewer: added support for reading serde raft_config
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Maslanka <michal@redpanda.com>
  • Loading branch information
mmaslankaprv committed Oct 3, 2023
1 parent a801e86 commit daa6d25
Showing 1 changed file with 56 additions and 11 deletions.
67 changes: 56 additions & 11 deletions tools/offline_log_viewer/model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from reader import Reader


def read_broker_shard(reader):
b = {}
b['id'] = reader.read_int32()
Expand Down Expand Up @@ -81,19 +84,46 @@ def read_configuration_update(rdr):
}


def read_raft_config(rdr):
cfg = {}
def decode_configuration_update(rdr: Reader, version: int):
ret = {}
ret['replicas_to_add'] = rdr.read_serde_vector(read_vnode_serde)
ret['replicas_to_remove'] = rdr.read_serde_vector(read_vnode_serde)
if version > 0:
ret['learner_start_offset'] = rdr.read_optional(Reader.read_int64)
return ret


cfg['version'] = rdr.read_int8()
if cfg['version'] < 5:
cfg['brokers'] = rdr.read_vector(read_broker)
cfg['current_config'] = read_group_nodes(rdr)
cfg['prev_config'] = rdr.read_optional(read_group_nodes)
cfg['revision'] = rdr.read_int64()
def read_configuration_update_serde(rdr: Reader):
return rdr.read_envelope(decode_configuration_update, max_version=1)

if cfg['version'] >= 4:
cfg['configuration_update'] = rdr.read_optional(
lambda ordr: read_configuration_update(ordr))

def read_raft_config(rdr):
cfg = {}
version = rdr.peek_int8()
if version >= 6:
return rdr.read_envelope(lambda rdr, _: {
"current":
read_group_nodes_serde(rdr),
"configuration_update":
rdr.read_optional(read_configuration_update_serde),
"old":
rdr.read_optional(read_group_nodes_serde),
"revision":
rdr.read_int64()
},
max_version=6)

else:
cfg['version'] = rdr.read_int8()
if cfg['version'] < 5:
cfg['brokers'] = rdr.read_vector(read_broker)
cfg['current_config'] = read_group_nodes(rdr)
cfg['prev_config'] = rdr.read_optional(read_group_nodes)
cfg['revision'] = rdr.read_int64()

if cfg['version'] >= 4:
cfg['configuration_update'] = rdr.read_optional(
lambda ordr: read_configuration_update(ordr))

return cfg

Expand All @@ -112,6 +142,21 @@ def read_group_nodes(r):
return ret


def read_vnode_serde(r):
return r.read_envelope(lambda r, _: {
"id": r.read_int32(),
"revision": r.read_int64()
})


def read_group_nodes_serde(r):
return r.read_envelope(
lambda r, _: {
"voters": r.read_serde_vector(read_vnode_serde),
"learners": r.read_serde_vector(read_vnode_serde)
})


def decode_cleanup_policy(bitflags):
D = 1
C = 1 << 1
Expand Down

0 comments on commit daa6d25

Please sign in to comment.