[Pending PR] RawBlockCore dead code 정리
[!tldr] 업무 관점 takeaway LMCache 첫 PR 후보.
core.py내부의 dead/redundant 코드 3건을 묶은 pure refactor. 동작 변경 없고 53/53 테스트 통과. M3(io_uring setup flag)가 #3274 머지 대기 중인 사이 워밍업 PR로 적합하다. 리뷰 리스크 중간:slot < 0제거가 defensive code 선호 반론 가능 — 도달 불가 근거를 PR description에 명시해야 함.
- 대상 파일:
lmcache/v1/storage_backend/raw_block/core.py - 성격: Pure refactoring (동작 변경 없음)
- 테스트: 53/53 통과 (상세는 아래)
- PR 제목 후보:
[Cleanup] Remove redundant conditions in RawBlockCore
변경 항목 3건
① delete_many — existed 변수 제거 (L672)
# Before
existed = encoded_key in self._index or encoded_key in self._inflight
...
deleted.append(existed and (removed_entry is not None or inflight is not None))
# After
deleted.append(removed_entry is not None or inflight is not None)
_lock 보호 하에 평가와 pop/get 사이 상태 변경 불가능 → 4가지 케이스 모두 existed가 결과에 영향 없음. 논리적 redundant.
| 케이스 | _index | _inflight | existed | removed∥inflight |
|---|---|---|---|---|
| A | ✓ | ✗ | True | True |
| B | ✗ | ✓ | True | True |
| C | ✓ | ✓ | True | True |
| D | ✗ | ✗ | False | False |
② _is_valid_checkpoint_entry — slot < 0 제거 (L1227)
# Before
if slot < 0 or slot >= self._max_slots:
# After
if slot >= self._max_slots:
도달 불가 이유:
- L1221에서
offset < self._data_base_offset→ 이미 return False rel = offset - self._data_base_offset >= 0보장slot_bytes > 0(init에서 검증됨) →양수 // 양수 >= 0slot < 0은 dead code
[!note] 리뷰 리스크 (중간) defensive code 선호 의견이 나올 수 있다. PR description에 위 invariant를 명시해 선제 대응. 대안:
slot < 0그대로 두고# invariant: slot >= 0주석 추가.
③ _apply_loaded_state — data.get("device_path") 중복 호출 제거 (L1237)
# Before
if data.get("device_path") and data.get("device_path") != self.device_path:
# After
checkpoint_device_path = data.get("device_path")
if checkpoint_device_path and checkpoint_device_path != self.device_path:
같은 키 두 번 lookup → 변수 하나로 단순화. 동작 동일.
테스트 결과
pytest -xvs tests/v1/storage_backend/test_raw_block_core.py # 4 passed
pytest -xvs tests/v1/storage_backend/test_rust_raw_block_backend.py # 29 passed
pytest -x tests/v1/distributed/test_raw_block_l2_adapter.py \
tests/v1/multiprocess/test_raw_block_l2_adapter.py # 20 passed
# 합계: 53/53 통과
새 테스트 추가 불필요 (동작 동일).
PR 제출 체크리스트
-
devbase 브랜치 생성 - 3항목 한 커밋 or 분리 커밋
-
pre-commit run --all-files통과 - PR description에 ②
slot < 0도달 불가 근거 명시 -
Refs #<연관 이슈 없음>— 순수 정리 PR
관련 페이지
- [[raw_block-내부구조]] —
delete_many,_is_valid_checkpoint_entry코드 맥락 - [[LMCache-기여-가이드]] — PR 제출 절차