-
Notifications
You must be signed in to change notification settings - Fork 573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tools/metadata_viewer: Refactor metadata_viewer and add transaction metadata support #5294
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
60e28ae
tools[log_viewer]: cleanup metadata_viewer
bharathv e9e2ece
tools[log_viewer]: Expand batch attrs
bharathv 9b51495
tools[log_viewer]: support kafka_internal ns
bharathv 8d96c0c
tools[log_viewer]: Map record header types to enum
bharathv 45f4288
tools[log_viewer]: Populate txn control markers
bharathv 64f1b39
tools/log_viewer: Switch to BatchType enum
bharathv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Offline tool to parse RedPanda disk logs. | ||
Usage: `python viewer.py -h` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from storage import Segment | ||
from enum import Enum | ||
from io import BytesIO | ||
from reader import Reader | ||
import struct | ||
|
||
|
||
class KafkaControlRecordType(Enum): | ||
"""Valid control record types defined by Kafka, currently only | ||
used for transactional control records. | ||
Keep this in sync with model::control_record_type | ||
""" | ||
tx_abort = 0 | ||
tx_commit = 1 | ||
unknown = -1 | ||
|
||
|
||
class KafkaLog: | ||
def __init__(self, ntp, headers_only): | ||
self.ntp = ntp | ||
self.headers_only = headers_only | ||
|
||
def get_control_record_type(self, key): | ||
rdr = Reader(BytesIO(key)) | ||
rdr.skip(2) # skip the 16bit version. | ||
# Encoded as big endian | ||
type_rdr = Reader(BytesIO(struct.pack(">h", rdr.read_int16()))) | ||
return KafkaControlRecordType(type_rdr.read_int16()).name | ||
|
||
def decode(self): | ||
self.results = [] | ||
for batch in self.batches(): | ||
header = batch.header_dict() | ||
yield header | ||
if not self.headers_only: | ||
records = [] | ||
for record in batch: | ||
attrs = header["expanded_attrs"] | ||
is_tx_ctrl = attrs["transactional"] and attrs[ | ||
"control_batch"] | ||
record_dict = record.kv_dict() | ||
records.append(record_dict) | ||
if is_tx_ctrl: | ||
record_dict["type"] = self.get_control_record_type( | ||
record.key) | ||
yield record_dict | ||
|
||
def batches(self): | ||
for path in self.ntp.segments: | ||
s = Segment(path) | ||
for batch in s: | ||
yield batch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good -- controller.py already has some of these magic numbers in, so maybe those could be replaced with references to this class at the same time as adding it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I did some sanity testing on my local controller log and kvstore data and things seem ok.