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

[feat] Use open-as-secondary feature of rocksdb in read_only mode #2957

Merged
merged 2 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def package_files(directory):
# What packages are required for this module to be executed?
REQUIRED = [
f'aim-ui=={__version__}',
'aimrocks==0.4.0',
'aimrocks==0.5.1',
'khash==0.5.0a5',
'cachetools>=4.0.0',
'click>=7.0',
Expand Down
16 changes: 14 additions & 2 deletions src/python/aim/_core/storage/rockscontainer.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import logging
import os
import tempfile
from pathlib import Path
from cachetools.func import ttl_cache

import aimrocks

Expand Down Expand Up @@ -131,9 +133,17 @@ class RocksContainer(Container):
def _lock(self, value):
self._resources._lock = value

@ttl_cache(ttl=5)
def _refresh(self):
if not self.read_only:
return
assert self._db is not None
self._db.try_catch_up_with_primary()

@property
def db(self) -> aimrocks.DB:
if self._db is not None:
self._refresh()
return self._db

logger.debug(f'opening {self.path} as aimrocks db')
Expand All @@ -144,15 +154,17 @@ class RocksContainer(Container):
lock_cls = self.get_lock_cls()
self._lock = lock_cls(self._lock_path, timeout)
self._lock.acquire()
secondary_path = None
else:
self.optimize_for_read()

secondary_path = tempfile.mkdtemp()
self._db = aimrocks.DB(str(self.path),
aimrocks.Options(**self._db_opts),
read_only=self.read_only)
read_only=self.read_only, secondary_path=secondary_path)

return self._db


def finalize(self, index: Container):
"""Finalize the Container.

Expand Down
Loading