Skip to content
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

fix(backport v3.8.x): ota_proxy: fix disk space usage checker not working & backport #418 #441

Merged
merged 3 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/ota_proxy/cache_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ async def cache_streaming(
Raises:
CacheStreamingFailed if any exception happens during retrieving.
"""
_cache_write_gen = None
try:
_cache_write_gen = await tracker.start_provider(cache_meta)
_cache_writer_failed = False
Expand Down Expand Up @@ -370,8 +371,9 @@ async def cache_streaming(
finally:
# force terminate the generator in all condition at exit, this
# can ensure the generator being gced after cache_streaming exits.
with contextlib.suppress(StopAsyncIteration):
await _cache_write_gen.athrow(StopAsyncIteration)
if _cache_write_gen:
with contextlib.suppress(StopAsyncIteration):
await _cache_write_gen.athrow(StopAsyncIteration)

# remove the refs
fd, tracker = None, None # type: ignore
Expand Down
4 changes: 2 additions & 2 deletions src/ota_proxy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
class Config:
BASE_DIR = "/ota-cache"
CHUNK_SIZE = 1 * 1024 * 1024 # 4MB
DISK_USE_LIMIT_SOFT_P = 70 # in p%
DISK_USE_LIMIT_HARD_P = 80 # in p%
DISK_USE_LIMIT_SOFT_P = 90 # in p%
DISK_USE_LIMIT_HARD_P = 92 # in p%
DISK_USE_PULL_INTERVAL = 2 # in seconds
# value is the largest numbers of files that
# might need to be deleted for the bucket to hold a new entry
Expand Down
10 changes: 5 additions & 5 deletions src/ota_proxy/ota_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def _background_check_free_space(self):
self._storage_below_hard_limit_event.clear()
break

current_used_p = disk_usage.used / disk_usage.total * 100
current_used_p = int(disk_usage.used / disk_usage.total * 100)

_previous_below_hard = self._storage_below_hard_limit_event.is_set()
_current_below_hard = True
Expand All @@ -266,13 +266,13 @@ def _background_check_free_space(self):
# logging space monitoring result
if _previous_below_hard and not _current_below_hard:
logger.warning(
f"disk usage reached hard limit({current_used_p=:.1}%,"
f"{cfg.DISK_USE_LIMIT_HARD_P:.1}%), cache disabled"
f"disk usage reached hard limit({current_used_p=}%,"
f"{cfg.DISK_USE_LIMIT_HARD_P=}%), cache disabled"
)
elif not _previous_below_hard and _current_below_hard:
logger.info(
f"disk usage is below hard limit({current_used_p=:.1}%),"
f"{cfg.DISK_USE_LIMIT_SOFT_P:.1}%), cache enabled again"
f"disk usage is below hard limit({current_used_p=}%),"
f"{cfg.DISK_USE_LIMIT_SOFT_P=}%), cache enabled again"
)
time.sleep(cfg.DISK_USE_PULL_INTERVAL)

Expand Down
Loading