rename PrefixDB class

This commit is contained in:
Jack Robison 2022-01-31 15:48:04 -05:00
parent de1e2d0e3b
commit a4bb4db8dd
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
5 changed files with 10 additions and 10 deletions

View file

@ -22,7 +22,7 @@ from lbry.wallet.server.hash import hash_to_hex_str
from lbry.wallet.server.tx import TxInput from lbry.wallet.server.tx import TxInput
from lbry.wallet.server.merkle import Merkle, MerkleCache from lbry.wallet.server.merkle import Merkle, MerkleCache
from lbry.wallet.server.db.common import ResolveResult, STREAM_TYPES, CLAIM_TYPES, ExpandedResolveResult, DBError, UTXO from lbry.wallet.server.db.common import ResolveResult, STREAM_TYPES, CLAIM_TYPES, ExpandedResolveResult, DBError, UTXO
from lbry.wallet.server.db.prefixes import PendingActivationValue, ClaimTakeoverValue, ClaimToTXOValue, HubDB as Prefixes from lbry.wallet.server.db.prefixes import PendingActivationValue, ClaimTakeoverValue, ClaimToTXOValue, PrefixDB
from lbry.wallet.server.db.prefixes import ACTIVATED_CLAIM_TXO_TYPE, ACTIVATED_SUPPORT_TXO_TYPE from lbry.wallet.server.db.prefixes import ACTIVATED_CLAIM_TXO_TYPE, ACTIVATED_SUPPORT_TXO_TYPE
from lbry.wallet.server.db.prefixes import PendingActivationKey, TXOToClaimValue, DBStatePrefixRow, MempoolTXPrefixRow from lbry.wallet.server.db.prefixes import PendingActivationKey, TXOToClaimValue, DBStatePrefixRow, MempoolTXPrefixRow
from lbry.wallet.transaction import OutputScript from lbry.wallet.transaction import OutputScript
@ -59,7 +59,7 @@ class HubDB:
if secondary_name: if secondary_name:
assert max_open_files == -1, 'max open files must be -1 for secondary readers' assert max_open_files == -1, 'max open files must be -1 for secondary readers'
self._db_max_open_files = max_open_files self._db_max_open_files = max_open_files
self.prefix_db: typing.Optional[Prefixes] = None self.prefix_db: typing.Optional[PrefixDB] = None
self.hist_unflushed = defaultdict(partial(array.array, 'I')) self.hist_unflushed = defaultdict(partial(array.array, 'I'))
self.hist_unflushed_count = 0 self.hist_unflushed_count = 0
@ -812,7 +812,7 @@ class HubDB:
self._db_dir, self._secondary_name self._db_dir, self._secondary_name
) )
db_path = os.path.join(self._db_dir, 'lbry-rocksdb') db_path = os.path.join(self._db_dir, 'lbry-rocksdb')
self.prefix_db = Prefixes( self.prefix_db = PrefixDB(
db_path, cache_mb=self._cache_MB, db_path, cache_mb=self._cache_MB,
reorg_limit=self._reorg_limit, max_open_files=self._db_max_open_files, reorg_limit=self._reorg_limit, max_open_files=self._db_max_open_files,
unsafe_prefixes={DBStatePrefixRow.prefix, MempoolTXPrefixRow.prefix}, secondary_path=secondary_path unsafe_prefixes={DBStatePrefixRow.prefix, MempoolTXPrefixRow.prefix}, secondary_path=secondary_path

View file

@ -7,7 +7,7 @@ from lbry.wallet.server.db import DB_PREFIXES
from lbry.wallet.server.db.revertable import RevertableOpStack, RevertablePut, RevertableDelete from lbry.wallet.server.db.revertable import RevertableOpStack, RevertablePut, RevertableDelete
class PrefixDB: class BasePrefixDB:
""" """
Base class for a revertable rocksdb database (a rocksdb db where each set of applied changes can be undone) Base class for a revertable rocksdb database (a rocksdb db where each set of applied changes can be undone)
""" """

View file

@ -4,7 +4,7 @@ import array
import base64 import base64
from typing import Union, Tuple, NamedTuple, Optional from typing import Union, Tuple, NamedTuple, Optional
from lbry.wallet.server.db import DB_PREFIXES from lbry.wallet.server.db import DB_PREFIXES
from lbry.wallet.server.db.interface import PrefixDB from lbry.wallet.server.db.interface import BasePrefixDB
from lbry.wallet.server.db.common import TrendingNotification from lbry.wallet.server.db.common import TrendingNotification
from lbry.wallet.server.db.revertable import RevertableOpStack, RevertablePut, RevertableDelete from lbry.wallet.server.db.revertable import RevertableOpStack, RevertablePut, RevertableDelete
from lbry.schema.url import normalize_name from lbry.schema.url import normalize_name
@ -1742,7 +1742,7 @@ class TouchedHashXPrefixRow(PrefixRow):
return cls.pack_key(height), cls.pack_value(touched) return cls.pack_key(height), cls.pack_value(touched)
class HubDB(PrefixDB): class PrefixDB(BasePrefixDB):
def __init__(self, path: str, cache_mb: int = 128, reorg_limit: int = 200, max_open_files: int = 512, def __init__(self, path: str, cache_mb: int = 128, reorg_limit: int = 200, max_open_files: int = 512,
secondary_path: str = '', unsafe_prefixes: Optional[typing.Set[bytes]] = None): secondary_path: str = '', unsafe_prefixes: Optional[typing.Set[bytes]] = None):
super().__init__(path, max_open_files=max_open_files, secondary_path=secondary_path, super().__init__(path, max_open_files=max_open_files, secondary_path=secondary_path,

View file

@ -17,7 +17,7 @@ from lbry.wallet.server.util import class_logger
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
from lbry.wallet.server.session import LBRYSessionManager from lbry.wallet.server.session import LBRYSessionManager
from wallet.server.db.db import LevelDB from wallet.server.db.db import HubDB
@attr.s(slots=True) @attr.s(slots=True)
@ -49,7 +49,7 @@ mempool_process_time_metric = Histogram(
class MemPool: class MemPool:
def __init__(self, coin, db: 'LevelDB', refresh_secs=1.0): def __init__(self, coin, db: 'HubDB', refresh_secs=1.0):
self.coin = coin self.coin = coin
self._db = db self._db = db
self.logger = class_logger(__name__, self.__class__.__name__) self.logger = class_logger(__name__, self.__class__.__name__)

View file

@ -2,7 +2,7 @@ import unittest
import tempfile import tempfile
import shutil import shutil
from lbry.wallet.server.db.revertable import RevertableOpStack, RevertableDelete, RevertablePut, OpStackIntegrity from lbry.wallet.server.db.revertable import RevertableOpStack, RevertableDelete, RevertablePut, OpStackIntegrity
from lbry.wallet.server.db.prefixes import ClaimToTXOPrefixRow, HubDB from lbry.wallet.server.db.prefixes import ClaimToTXOPrefixRow, PrefixDB
class TestRevertableOpStack(unittest.TestCase): class TestRevertableOpStack(unittest.TestCase):
@ -107,7 +107,7 @@ class TestRevertableOpStack(unittest.TestCase):
class TestRevertablePrefixDB(unittest.TestCase): class TestRevertablePrefixDB(unittest.TestCase):
def setUp(self): def setUp(self):
self.tmp_dir = tempfile.mkdtemp() self.tmp_dir = tempfile.mkdtemp()
self.db = HubDB(self.tmp_dir, cache_mb=1, max_open_files=32) self.db = PrefixDB(self.tmp_dir, cache_mb=1, max_open_files=32)
def tearDown(self) -> None: def tearDown(self) -> None:
self.db.close() self.db.close()