Commit ·
7ad1d9b
1
Parent(s): 21786f2
Keep the Space cache under its ~50 GB disk quota
Browse filesCo-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
backend/app/protein/localcache.py
CHANGED
|
@@ -28,7 +28,10 @@ BUCKET_URL = os.getenv(
|
|
| 28 |
"MUSPROT_BUCKET_URL", "https://huggingface.co/buckets/omaib/MuSProt-storage/resolve"
|
| 29 |
).rstrip("/")
|
| 30 |
# smallest first: the index serves search/browse/graphs and is ready in seconds;
|
| 31 |
-
# the advanced-search Parquet (scripts/build_search.py)
|
|
|
|
|
|
|
|
|
|
| 32 |
FILES = [
|
| 33 |
"MuSProt-index.db",
|
| 34 |
"MuSProt-search-facets.json",
|
|
@@ -36,8 +39,10 @@ FILES = [
|
|
| 36 |
"MuSProt-search-partners.parquet",
|
| 37 |
"MuSProt-search-nodes.parquet",
|
| 38 |
"MuSProt.db",
|
| 39 |
-
"MuSProt-search-edges.parquet",
|
| 40 |
]
|
|
|
|
|
|
|
|
|
|
| 41 |
CHUNK = 8 * 1024 * 1024
|
| 42 |
PARALLEL = int(os.getenv("MUSPROT_LOCAL_CACHE_PARALLEL", "8"))
|
| 43 |
DISK_MARGIN = 2 * 1024**3
|
|
@@ -163,6 +168,7 @@ def _verify(name: str, path: Path) -> None:
|
|
| 163 |
|
| 164 |
def _run() -> None:
|
| 165 |
CACHE_DIR.mkdir(parents=True, exist_ok=True)
|
|
|
|
| 166 |
for name in FILES:
|
| 167 |
url = f"{BUCKET_URL}/{name}"
|
| 168 |
dest = CACHE_DIR / name
|
|
@@ -170,6 +176,11 @@ def _run() -> None:
|
|
| 170 |
try:
|
| 171 |
size = _remote_size(url)
|
| 172 |
_status[name].update(size=size, downloaded=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
if not (dest.exists() and dest.stat().st_size == size):
|
| 174 |
part = dest.with_name(dest.name + ".part")
|
| 175 |
part.unlink(missing_ok=True)
|
|
|
|
| 28 |
"MUSPROT_BUCKET_URL", "https://huggingface.co/buckets/omaib/MuSProt-storage/resolve"
|
| 29 |
).rstrip("/")
|
| 30 |
# smallest first: the index serves search/browse/graphs and is ready in seconds;
|
| 31 |
+
# then the advanced-search Parquet (scripts/build_search.py) and the DB.
|
| 32 |
+
# MuSProt-search-edges.parquet (6.7 GB) is left out: with the 47 GB DB it would
|
| 33 |
+
# exceed the Space's ~50 GB ephemeral disk, and the Space is evicted when it
|
| 34 |
+
# does (2026-10-15).
|
| 35 |
FILES = [
|
| 36 |
"MuSProt-index.db",
|
| 37 |
"MuSProt-search-facets.json",
|
|
|
|
| 39 |
"MuSProt-search-partners.parquet",
|
| 40 |
"MuSProt-search-nodes.parquet",
|
| 41 |
"MuSProt.db",
|
|
|
|
| 42 |
]
|
| 43 |
+
# the Space's ephemeral disk quota; disk_usage() reports the host disk, which is
|
| 44 |
+
# far larger, so the cache keeps its own running total under this
|
| 45 |
+
QUOTA = int(float(os.getenv("MUSPROT_LOCAL_CACHE_QUOTA_GB", "48")) * 1024**3)
|
| 46 |
CHUNK = 8 * 1024 * 1024
|
| 47 |
PARALLEL = int(os.getenv("MUSPROT_LOCAL_CACHE_PARALLEL", "8"))
|
| 48 |
DISK_MARGIN = 2 * 1024**3
|
|
|
|
| 168 |
|
| 169 |
def _run() -> None:
|
| 170 |
CACHE_DIR.mkdir(parents=True, exist_ok=True)
|
| 171 |
+
used = 0
|
| 172 |
for name in FILES:
|
| 173 |
url = f"{BUCKET_URL}/{name}"
|
| 174 |
dest = CACHE_DIR / name
|
|
|
|
| 176 |
try:
|
| 177 |
size = _remote_size(url)
|
| 178 |
_status[name].update(size=size, downloaded=0)
|
| 179 |
+
if used + size > QUOTA:
|
| 180 |
+
_status[name]["state"] = f"skipped: {size} bytes would exceed the {QUOTA} byte cache quota"
|
| 181 |
+
logger.warning("local cache: %s", _status[name]["state"])
|
| 182 |
+
continue
|
| 183 |
+
used += size
|
| 184 |
if not (dest.exists() and dest.stat().st_size == size):
|
| 185 |
part = dest.with_name(dest.name + ".part")
|
| 186 |
part.unlink(missing_ok=True)
|