Skip to content

Commit

Permalink
tools: fixed incorrect parsing of some controller commands
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Maslanka <michal@redpanda.com>
  • Loading branch information
mmaslankaprv committed Dec 16, 2022
1 parent f12e562 commit e445183
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tools/offline_log_viewer/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def decode_topic_command_serde(k_rdr: Reader, rdr: Reader):
cmd['replicas'] = rdr.read_serde_vector(read_broker_shard)
elif cmd['type'] == 3:
cmd['type_string'] = 'finish_partitions_update'
cmd['namespace'] = k_rdr.read_string()
cmd['topic'] = k_rdr.read_string()
cmd['partition'] = k_rdr.read_int32()
cmd['replicas'] = rdr.read_serde_vector(read_broker_shard)
Expand All @@ -189,6 +190,9 @@ def decode_topic_command_serde(k_rdr: Reader, rdr: Reader):
})
elif cmd['type'] == 7:
cmd['type_string'] = 'cancel_moving_partition_replicas'
cmd['namespace'] = k_rdr.read_string()
cmd['topic'] = k_rdr.read_string()
cmd['partition'] = k_rdr.read_int32()
cmd |= rdr.read_envelope(lambda rdr, _: {'force': rdr.read_bool()})
return cmd

Expand Down Expand Up @@ -560,22 +564,31 @@ def decode_node_management_command(k_rdr: Reader, rdr: Reader):
'type_string': 'decommission_node',
'node_id': k_rdr.read_int32()
}
rdr.read_int8()
elif cmd['type'] == 1:
cmd |= {
'type_string': 'recommission_node',
'node_id': k_rdr.read_int32()
}
rdr.read_int8()
elif cmd['type'] == 2:
cmd |= {
'type_string': 'finish_reallocations',
'node_id': k_rdr.read_int32()
}
rdr.read_int8()
elif cmd['type'] == 3:
cmd |= {
'type_string': 'maintenance_mode',
'node_id': k_rdr.read_int32(),
'enabled': rdr.read_bool()
}
elif cmd['type'] == 4:
cmd |= {
'type_string': 'register_node_uuid',
'uuid': k_rdr.read_uuid().hex(),
'id': rdr.read_optional(lambda r: r.read_int32())
}
return cmd


Expand Down
3 changes: 3 additions & 0 deletions tools/offline_log_viewer/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ def read_bytes(self, length):
def peek(self, length):
return self.stream.peek(length)

def read_uuid(self):
return self.stream.read(16)

def peek_int8(self):
# peek returns the whole memory buffer, slice is needed to conform to struct format string
return struct.unpack('<b', self.stream.peek(1)[:1])[0]
Expand Down

0 comments on commit e445183

Please sign in to comment.