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

refactoring: remove outdated stuff #851

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
55 changes: 3 additions & 52 deletions qdrant_client/local/persistence.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,13 @@
import base64
import dbm
import logging
import pickle
import sqlite3
from pathlib import Path
from typing import Iterable, Optional

from qdrant_client.http import models

STORAGE_FILE_NAME_OLD = "storage.dbm"
STORAGE_FILE_NAME = "storage.sqlite"


def try_migrate_to_sqlite(location: str) -> None:
dbm_path = Path(location) / STORAGE_FILE_NAME_OLD
sql_path = Path(location) / STORAGE_FILE_NAME

if sql_path.exists():
return

if not dbm_path.exists():
return

try:
dbm_storage = dbm.open(str(dbm_path), "c")

con = sqlite3.connect(str(sql_path))
cur = con.cursor()

# Create table
cur.execute("CREATE TABLE IF NOT EXISTS points (id TEXT PRIMARY KEY, point BLOB)")

for key in dbm_storage.keys():
value = dbm_storage[key]
if isinstance(key, str):
key = key.encode("utf-8")
key = pickle.loads(key)
sqlite_key = CollectionPersistence.encode_key(key)
# Insert a row of data
cur.execute(
"INSERT INTO points VALUES (?, ?)",
(
sqlite_key,
sqlite3.Binary(value),
),
)
con.commit()
con.close()
dbm_storage.close()
dbm_path.unlink()
except Exception as e:
logging.error("Failed to migrate dbm to sqlite:", e)
logging.error(
"Please try to use previous version of qdrant-client or re-create collection"
)
raise e
STORAGE_FILE_NAME = "storage.sqlite"


class CollectionPersistence:
Expand All @@ -70,9 +23,6 @@ def __init__(self, location: str, force_disable_check_same_thread: bool = False)
Args:
location: path to the collection directory.
"""

try_migrate_to_sqlite(location)

self.location = Path(location) / STORAGE_FILE_NAME
self.location.parent.mkdir(exist_ok=True, parents=True)

Expand All @@ -92,7 +42,8 @@ def __init__(self, location: str, force_disable_check_same_thread: bool = False)
self.__class__.CHECK_SAME_THREAD = False

self.storage = sqlite3.connect(
str(self.location), check_same_thread=self.CHECK_SAME_THREAD # type: ignore
str(self.location),
check_same_thread=self.CHECK_SAME_THREAD, # type: ignore
)

self._ensure_table()
Expand Down
Loading