๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Kafka

kafka CLI ์‚ฌ์šฉํ•˜๊ธฐ - kafka-dump-log

by Soono991 2023. 4. 4.
๐Ÿ’ก ์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” kafka-dump-log์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

kafka-dump-log ์„ค๋ช…์„ ๋ณด๋ฉด ๋กœ๊ทธ ํŒŒ์ผ์„ ํŒŒ์‹ฑ ํ•˜์—ฌ ๊ทธ ๋‚ด์šฉ์„ ์ฝ˜์†”์— ๋คํ”„ ํ•˜๋„๋ก ๋„์™€์ฃผ๋ฉฐ, ์†์ƒ๋œ ๋กœ๊ทธ ์„ธ๊ทธ๋จผํŠธ๋ฅผ ๋””๋ฒ„๊น…ํ•˜๋Š”๋ฐ ๋„์›€์ด ๋œ๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

 

user@ubuntu:~/confluent/bin$ kafka-dump-log --help
This tool helps to parse a log file and dump its contents to the console, useful for debugging a seemingly corrupt log segment.
Option                               Description                                
------                               -----------                                
--cluster-metadata-decoder           if set, log data will be parsed as cluster 
                                       metadata records.                        
--deep-iteration                     if set, uses deep instead of shallow       
                                       iteration. Automatically set if print-   
                                       data-log is enabled.                     
--files <String: file1, file2, ...>  REQUIRED: The comma separated list of data 
                                       and index log files to be dumped.        
--help                               Print usage information.                   
--index-sanity-check                 if set, just checks the index sanity       
                                       without printing its content. This is    
                                       the same check that is executed on       
                                       broker startup to determine if an index  
                                       needs rebuilding or not.                 
--key-decoder-class [String]         if set, used to deserialize the keys. This 
                                       class should implement kafka.serializer. 
                                       Decoder trait. Custom jar should be      
                                       available in kafka/libs directory.       
                                       (default: kafka.serializer.StringDecoder)
--max-message-size <Integer: size>   Size of largest message. (default: 5242880)
--offsets-decoder                    if set, log data will be parsed as offset  
                                       data from the __consumer_offsets topic.  
--print-data-log                     if set, printing the messages content when 
                                       dumping data logs. Automatically set if  
                                       any decoder option is specified.         
--skip-record-metadata               whether to skip printing metadata for each 
                                       record.                                  
--transaction-log-decoder            if set, log data will be parsed as         
                                       transaction metadata from the            
                                       __transaction_state topic.               
--value-decoder-class [String]       if set, used to deserialize the messages.  
                                       This class should implement kafka.       
                                       serializer.Decoder trait. Custom jar     
                                       should be available in kafka/libs        
                                       directory. (default: kafka.serializer.   
                                       StringDecoder)                           
--verify-index-only                  if set, just verify the index log without  
                                       printing its content.                    
--version                            Display Kafka version.

 

๊ธฐ๋ณธ์ ์œผ๋กœ kafka log๋Š” kafka-logs ๋””๋ ‰ํ„ฐ๋ฆฌ ๋ฐ‘์— ๊ฐ topic๋ณ„๋กœ {topic name}-{partition number} ๋””๋ ‰ํ„ฐ๋ฆฌ๊ฐ€ ์ƒ์„ฑ๋˜๋Š”๋ฐ ์ด ๋””๋ ‰ํ„ฐ๋ฆฌ ๋‚ด๋ถ€์— *.log ํŒŒ์ผ์— ๋ฐ์ดํ„ฐ๊ฐ€ ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.

 

์ด ํŒŒ์ผ์„ ๋‹จ์ˆœ cat, vi ๋ช…๋ น์–ด๋กœ ํ™•์ธํ•ด๋ณด๋ฉด ์••์ถ•์ด ์ง„ํ–‰๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ์ด์ƒํ•œ ๋ฌธ์ž๋“ค์ด ํ•จ๊ป˜ ์ถœ๋ ฅ์ด ๋ฉ๋‹ˆ๋‹ค.

kafka-dump-log ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์••์ถ•์„ ํ•ด์ œํ•œ ์ •์ƒ์ ์ธ ๋ฐ์ดํ„ฐ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

kafka-dump-log --files ./00000000000000000000.log

 

--files ๋ช…๋ น์— ์–ด๋–ค ํŒŒ์ผ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ํ™•์ธํ•  ๊ฒƒ์ธ์ง€ ๋ฐ˜๋“œ์‹œ ๋ช…์‹œํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๋‹ค๋ฅธ ์˜ต์…˜์„ ์ฃผ์ง€ ์•Š์„ ๊ฒฝ์šฐ ๋ฐ์ดํ„ฐ๋Š” ์ถœ๋ ฅ๋˜์ง€ ์•Š์œผ๋ฉฐ offset์ด๋‚˜ ๊ด€๋ จ ๋ฉ”ํƒ€ ์ •๋ณด๋งŒ ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.

 

์ด ๊ฒฝ์šฐ --print-data-log ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ฐ์ดํ„ฐ๋„ ํ•จ๊ป˜ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

 

--print-data-log ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜๋ฉด --deep-iteration ์˜ต์…˜์ด ๊ฐ™์ด ํ™œ์„ฑํ™”๋œ๋‹ค๊ณ  ํ•˜๋Š”๋ฐ, -deep-iteration์„ ์‚ฌ์šฉํ•˜๋ฉด record์˜ ๋ฉ”ํƒ€ ๋ฐ์ดํ„ฐ๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ --deep-iteration ์˜ต์…˜๋งŒ ์‚ฌ์šฉํ•˜๊ฒŒ ๋  ๊ฒฝ์šฐ --print-data-log์™€ ๋‹ฌ๋ฆฌ key์™€ payload ํ•ญ๋ชฉ์€ ์ถœ๋ ฅ๋˜์ง€ ์•Š๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

๋งŒ์•ฝ ๋ฐ˜๋Œ€๋กœ key, payload๋งŒ ์ถœ๋ ฅํ•˜๊ณ  record์˜ ๋ฉ”ํƒ€ ๋ฐ์ดํ„ฐ๋Š” ์ถœ๋ ฅํ•˜๊ณ  ์‹ถ์ง€ ์•Š์€ ๊ฒฝ์šฐ์—๋Š” --print-data-log ์˜ต์…˜๊ณผ --skip-record-metadata ์˜ต์…˜์„ ๊ฐ™์ด ์‚ฌ์šฉํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

 

 

kafka-dump-log ๋ช…๋ น์–ด์™€ ์œ„์˜ ์˜ต์…˜๋“ค์„ ํ™œ์šฉํ•ด์„œ ํŠน์ • topic์— ๋ฐ์ดํ„ฐ๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ๋“ค์–ด๊ฐ”๋Š”์ง€ ์–ด๋–ป๊ฒŒ ๋ฐ์ดํ„ฐ๊ฐ€ ์ €์žฅ๋˜์–ด ์žˆ๋Š”์ง€ ๋“ฑ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์ฐธ๊ณ  ์ž๋ฃŒ

'Kafka' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

kafka CLI ์‚ฌ์šฉํ•˜๊ธฐ - kafka-configs.(sh | bat)  (0) 2023.04.08
kafka CLI ์‚ฌ์šฉํ•˜๊ธฐ - kafka-consumer-group.(sh | bat)  (0) 2023.04.08
KafkaProducer  (0) 2023.04.04
Producer  (0) 2023.04.03
kafka CLI ์‚ฌ์šฉํ•˜๊ธฐ - kafka-console-consumer.(sh | bat)  (0) 2023.03.28

๋Œ“๊ธ€