Merge pull request #1177 from jphein/fix/blob-seq-marker-guard
fix: skip _fix_blob_seq_ids sqlite open on already-migrated palaces (#1090)
This commit is contained in:
@@ -4,6 +4,7 @@ import datetime as _dt
|
||||
import logging
|
||||
import os
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
from typing import Any, Optional
|
||||
|
||||
import chromadb
|
||||
@@ -239,6 +240,9 @@ def _pin_hnsw_threads(collection) -> None:
|
||||
logger.debug("_pin_hnsw_threads modify failed", exc_info=True)
|
||||
|
||||
|
||||
_BLOB_FIX_MARKER = ".blob_seq_ids_migrated"
|
||||
|
||||
|
||||
def _fix_blob_seq_ids(palace_path: str) -> None:
|
||||
"""Fix ChromaDB 0.6.x -> 1.5.x migration bug: BLOB seq_ids -> INTEGER.
|
||||
|
||||
@@ -248,10 +252,19 @@ def _fix_blob_seq_ids(palace_path: str) -> None:
|
||||
type INTEGER) is not compatible with SQL type BLOB".
|
||||
|
||||
Must run BEFORE PersistentClient is created (the compactor fires on init).
|
||||
|
||||
Opening a Python sqlite3 connection against a ChromaDB 1.5.x WAL-mode
|
||||
database leaves state that segfaults the next PersistentClient call. After
|
||||
the migration has run once successfully, a marker file is written so
|
||||
subsequent opens skip the sqlite connection entirely. Already-migrated
|
||||
palaces can touch the marker manually to opt into the fast path.
|
||||
"""
|
||||
db_path = os.path.join(palace_path, "chroma.sqlite3")
|
||||
if not os.path.isfile(db_path):
|
||||
return
|
||||
marker = os.path.join(palace_path, _BLOB_FIX_MARKER)
|
||||
if os.path.isfile(marker):
|
||||
return
|
||||
try:
|
||||
with sqlite3.connect(db_path) as conn:
|
||||
for table in ("embeddings", "max_seq_id"):
|
||||
@@ -269,6 +282,14 @@ def _fix_blob_seq_ids(palace_path: str) -> None:
|
||||
conn.commit()
|
||||
except Exception:
|
||||
logger.exception("Could not fix BLOB seq_ids in %s", db_path)
|
||||
return
|
||||
# Write marker whether or not rows needed migration — the palace is now
|
||||
# confirmed to be in the INTEGER-seq_id state and future opens can skip the
|
||||
# sqlite3.connect() entirely.
|
||||
try:
|
||||
Path(marker).touch()
|
||||
except OSError:
|
||||
logger.exception("Could not write migration marker %s", marker)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user