Skip to content

Commit

Permalink
log_viewer: fix false assert
Browse files Browse the repository at this point in the history
the checks didn't handle well empty dirs
  • Loading branch information
rystsov committed Aug 19, 2022
1 parent 1a30165 commit 906a9e7
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions tools/offline_log_viewer/storage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import collections
from enum import Enum
import os
import re
from os.path import join

import struct
import crc32c
Expand Down Expand Up @@ -273,25 +275,25 @@ def __str__(self):
return "{0.nspace}/{0.topic}/{0.partition}_{0.ntp_id}".format(self)


def listdirs(path):
return [x for x in os.listdir(path) if os.path.isdir(join(path, x))]


class Store:
def __init__(self, base_dir):
self.base_dir = os.path.abspath(base_dir)
self.ntps = []
self.__search()

def __search(self):
dirs = os.walk(self.base_dir)
for ntpd in (p[0] for p in dirs if not p[1]):
if 'cloud_storage_cache' in ntpd:
for nspace in listdirs(self.base_dir):
if nspace == "cloud_storage_cache":
continue
head, part_ntp_id = os.path.split(ntpd)
[part, ntp_id] = part_ntp_id.split("_")
head, topic = os.path.split(head)
head, nspace = os.path.split(head)
if head != self.base_dir:
logger.warn(
"Unexpected directory layout (should be <namespace>/<topic>/<partition>, and use top of tree as your --path"
)
assert head == self.base_dir
ntp = Ntp(self.base_dir, nspace, topic, int(part), int(ntp_id))
self.ntps.append(ntp)
for topic in listdirs(join(self.base_dir, nspace)):
for part_ntp_id in listdirs(join(self.base_dir, nspace,
topic)):
assert re.match("^\\d+_\\d+$", part_ntp_id)
[part, ntp_id] = part_ntp_id.split("_")
ntp = Ntp(self.base_dir, nspace, topic, int(part),
int(ntp_id))
self.ntps.append(ntp)

0 comments on commit 906a9e7

Please sign in to comment.