Skip to content

Commit

Permalink
deleter cleanups (commaai#34345)
Browse files Browse the repository at this point in the history
  • Loading branch information
incognitojam authored Jan 9, 2025
1 parent 5dd1972 commit f761f53
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions system/loggerd/deleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def has_preserve_xattr(d: str) -> bool:


def get_preserved_segments(dirs_by_creation: list[str]) -> list[str]:
# skip deleting most recent N preserved segments (and their prior segment)
preserved = []
for n, d in enumerate(filter(has_preserve_xattr, reversed(dirs_by_creation))):
if n == PRESERVE_COUNT:
Expand All @@ -44,15 +45,13 @@ def get_preserved_segments(dirs_by_creation: list[str]) -> list[str]:
return preserved


def deleter_thread(exit_event):
def deleter_thread(exit_event: threading.Event):
while not exit_event.is_set():
out_of_bytes = get_available_bytes(default=MIN_BYTES + 1) < MIN_BYTES
out_of_percent = get_available_percent(default=MIN_PERCENT + 1) < MIN_PERCENT

if out_of_percent or out_of_bytes:
dirs = listdir_by_creation(Paths.log_root())

# skip deleting most recent N preserved segments (and their prior segment)
preserved_dirs = get_preserved_segments(dirs)

# remove the earliest directory we can
Expand All @@ -64,10 +63,7 @@ def deleter_thread(exit_event):

try:
cloudlog.info(f"deleting {delete_path}")
if os.path.isfile(delete_path):
os.remove(delete_path)
else:
shutil.rmtree(delete_path)
shutil.rmtree(delete_path)
break
except OSError:
cloudlog.exception(f"issue deleting {delete_path}")
Expand Down

0 comments on commit f761f53

Please sign in to comment.