Skip to content

Commit 338b28d

Browse files
committed
disk map refactoring changes
1 parent a032887 commit 338b28d

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

src/blkcache/cache/through.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ def __init__(self, config):
2929
# WRONG: WE HAVE A FUNCTION TO DO THIS DON'T GUESS
3030
self.block_size = config.get("block_size") or DEFAULT_BLOCK_SIZE
3131
self.map_path = self.cache.with_suffix(f"{self.cache.suffix}.log")
32-
self.diskmap = DiskMap(self.map_path)
32+
33+
# Get device size for DiskMap
34+
device_size = get_device_size(self.device)
35+
self.diskmap = DiskMap(self.map_path, device_size)
3336

3437
# Initialize cache
3538
self._initialize()

src/blkcache/plugin.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,20 @@
33
"""
44

55
from pathlib import Path
6-
from collections import defaultdict
76

87
# Import constants using full package name for compatibility with nbdkit and pytest
98
from blkcache.constants import (
10-
STATUS_UNTRIED,
119
DEFAULT_BLOCK_SIZE,
1210
)
1311

14-
# Import Cache class
15-
from blkcache.cache.cache import Cache
12+
# Import BlockCache class
13+
from blkcache.cache.through import BlockCache
1614

1715
# Global state
1816
DEV: Path | None = None
1917
CACHE: Path | None = None
2018
BLOCK = DEFAULT_BLOCK_SIZE # Use constant for default block size
2119
METADATA = {}
22-
BLOCK_STATUS = defaultdict(lambda: STATUS_UNTRIED)
2320

2421
# Cache instance - will be created in config_complete
2522
CACHE_INSTANCE = None
@@ -51,15 +48,14 @@ def config(key: str, val: str) -> None:
5148

5249
def config_complete() -> None:
5350
"""Validates required parameters and initializes the cache implementation."""
54-
global DEV, CACHE, BLOCK, METADATA, BLOCK_STATUS, CACHE_INSTANCE
51+
global DEV, CACHE, BLOCK, METADATA, CACHE_INSTANCE
5552

5653
if DEV is None or CACHE is None:
5754
raise RuntimeError("device= and cache= are required")
5855

5956
# Create a BlockCache instance
60-
CACHE_INSTANCE = BlockCache(
61-
device_path=DEV, cache_path=CACHE, block_size=BLOCK if BLOCK != DEFAULT_BLOCK_SIZE else None
62-
)
57+
config = {"device_path": DEV, "cache_path": CACHE, "block_size": BLOCK if BLOCK != DEFAULT_BLOCK_SIZE else None}
58+
CACHE_INSTANCE = BlockCache(config)
6359

6460
# The BlockCache initialization will handle:
6561
# - Loading the mapfile if it exists
@@ -68,8 +64,7 @@ def config_complete() -> None:
6864

6965
# Keep using the legacy variables for now to minimize changes
7066
BLOCK = CACHE_INSTANCE.block_size
71-
METADATA = CACHE_INSTANCE.metadata
72-
BLOCK_STATUS = CACHE_INSTANCE.block_status
67+
METADATA = CACHE_INSTANCE.diskmap.config
7368

7469

7570
def open(_readonly: bool) -> dict[str, int]:

tests/unit/test_blocksize.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ def test_auto_detection_failure(mock_get_sector_size):
6464
assert error_msg in updates["block_size_source"]
6565

6666

67-
6867
def testdetermine_block_size_with_auto_detect():
6968
"""When auto-detection succeeds, the detected size should be used."""
7069
# We'll test the higher-level determine_block_size function instead

0 commit comments

Comments
 (0)