Skip to content

Commit

Permalink
tools[log_viewer]: Map record header types to enum
Browse files Browse the repository at this point in the history
Example:

INFO:viewer:{
  "header_crc": 1126531443,
  "batch_size": 90,
  "base_offset": 3,
  "type": 9,
  "crc": 1766141844,
  "attrs": 32,
  "delta": 0,
  "first_ts": 1656554802864,
  "max_ts": 1656554802864,
  "producer_id": 1002,
  "producer_epoch": 1,
  "base_seq": -1,
  "record_count": 1,
  "type_name": "tx_prepare", <====
  "expanded_attrs": {
    "compression": "none",
    "transactional": false,
    "control_batch": true,
    "timestamp_type": false
  }
}
  • Loading branch information
bharathv committed Jun 30, 2022
1 parent a1cd943 commit 9eea0e7
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tools/offline_log_viewer/storage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import collections
from enum import Enum
import os

import struct
Expand Down Expand Up @@ -104,6 +105,36 @@ def __next__(self):
headers)


class BatchType(Enum):
"""Keep this in sync with model/record_batch_types.h"""
raft_data = 1
raft_configuration = 2
controller = 3
kvstore = 4
checkpoint = 5
topic_management_cmd = 6
ghost_batch = 7
id_allocator = 8
tx_prepare = 9
tx_fence = 10
tm_update = 11
user_management_cmd = 12
acl_management_cmd = 13
group_prepare_tx = 14
group_commit_tx = 15
group_abort_tx = 16
node_management_cmd = 17
data_policy_management_cmd = 18
archival_metadata = 19
cluster_config_cmd = 20
feature_update = 21
unknown = -1

@classmethod
def _missing_(e, value):
return e.unknown


class Batch:
class CompressionType(Enum):
none = 0
Expand Down Expand Up @@ -141,6 +172,7 @@ def __init__(self, index, header, records):
def header_dict(self):
header = self.header._asdict()
attrs = header['attrs']
header["type_name"] = BatchType(header["type"]).name
header['expanded_attrs'] = {
'compression':
Batch.CompressionType(attrs & Batch.compression_mask).name,
Expand Down

0 comments on commit 9eea0e7

Please sign in to comment.