Let make_db_file_path accept epoch=None
...in which case it should strip the epoch if the original path had one. Change-Id: I8739a474c56c0f2376a276d2691c84448cb9c647
This commit is contained in:
@@ -5370,22 +5370,24 @@ def make_db_file_path(db_path, epoch):
|
|||||||
Given a path to a db file, return a modified path whose filename part has
|
Given a path to a db file, return a modified path whose filename part has
|
||||||
the given epoch.
|
the given epoch.
|
||||||
|
|
||||||
A db filename takes the form <hash>[_<epoch>].db; this method replaces the
|
A db filename takes the form ``<hash>[_<epoch>].db``; this method replaces
|
||||||
<epoch> part of the given ``db_path`` with the given ``epoch`` value.
|
the ``<epoch>`` part of the given ``db_path`` with the given ``epoch``
|
||||||
|
value, or drops the epoch part if the given ``epoch`` is ``None``.
|
||||||
|
|
||||||
:param db_path: Path to a db file that does not necessarily exist.
|
:param db_path: Path to a db file that does not necessarily exist.
|
||||||
:param epoch: A string that will be used as the epoch in the new path's
|
:param epoch: A string (or ``None``) that will be used as the epoch
|
||||||
filename; the value will be normalized to the normal string
|
in the new path's filename; non-``None`` values will be
|
||||||
representation of a :class:`~swift.common.utils.Timestamp`.
|
normalized to the normal string representation of a
|
||||||
|
:class:`~swift.common.utils.Timestamp`.
|
||||||
:return: A modified path to a db file.
|
:return: A modified path to a db file.
|
||||||
:raises ValueError: if the ``epoch`` is not valid for constructing a
|
:raises ValueError: if the ``epoch`` is not valid for constructing a
|
||||||
:class:`~swift.common.utils.Timestamp`.
|
:class:`~swift.common.utils.Timestamp`.
|
||||||
"""
|
"""
|
||||||
if epoch is None:
|
|
||||||
raise ValueError('epoch must not be None')
|
|
||||||
epoch = Timestamp(epoch).normal
|
|
||||||
hash_, _, ext = parse_db_filename(db_path)
|
hash_, _, ext = parse_db_filename(db_path)
|
||||||
db_dir = os.path.dirname(db_path)
|
db_dir = os.path.dirname(db_path)
|
||||||
|
if epoch is None:
|
||||||
|
return os.path.join(db_dir, hash_ + ext)
|
||||||
|
epoch = Timestamp(epoch).normal
|
||||||
return os.path.join(db_dir, '%s_%s%s' % (hash_, epoch, ext))
|
return os.path.join(db_dir, '%s_%s%s' % (hash_, epoch, ext))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -329,9 +329,7 @@ class ContainerBroker(DatabaseBroker):
|
|||||||
if db_file == ':memory:':
|
if db_file == ':memory:':
|
||||||
base_db_file = db_file
|
base_db_file = db_file
|
||||||
else:
|
else:
|
||||||
db_dir = os.path.dirname(db_file)
|
base_db_file = make_db_file_path(db_file, None)
|
||||||
hash_, other, ext = parse_db_filename(db_file)
|
|
||||||
base_db_file = os.path.join(db_dir, hash_ + ext)
|
|
||||||
super(ContainerBroker, self).__init__(
|
super(ContainerBroker, self).__init__(
|
||||||
base_db_file, timeout, logger, account, container, pending_timeout,
|
base_db_file, timeout, logger, account, container, pending_timeout,
|
||||||
stale_reads_ok, skip_commits=skip_commits)
|
stale_reads_ok, skip_commits=skip_commits)
|
||||||
@@ -361,9 +359,8 @@ class ContainerBroker(DatabaseBroker):
|
|||||||
"""
|
"""
|
||||||
hsh = hash_path(account, container)
|
hsh = hash_path(account, container)
|
||||||
db_dir = storage_directory(DATADIR, part, hsh)
|
db_dir = storage_directory(DATADIR, part, hsh)
|
||||||
db_path = os.path.join(device_path, db_dir, hsh + '.db')
|
db_path = make_db_file_path(
|
||||||
if epoch:
|
os.path.join(device_path, db_dir, hsh + '.db'), epoch)
|
||||||
db_path = make_db_file_path(db_path, epoch)
|
|
||||||
broker = ContainerBroker(db_path, account=account, container=container,
|
broker = ContainerBroker(db_path, account=account, container=container,
|
||||||
logger=logger)
|
logger=logger)
|
||||||
if not os.path.exists(broker.db_file):
|
if not os.path.exists(broker.db_file):
|
||||||
|
|||||||
@@ -3955,6 +3955,11 @@ cluster_dfw1 = http://dfw1.host/v1/
|
|||||||
actual = utils.make_db_file_path(actual, epoch)
|
actual = utils.make_db_file_path(actual, epoch)
|
||||||
self.assertEqual('/path/to/hash_%s.db' % epoch.internal, actual)
|
self.assertEqual('/path/to/hash_%s.db' % epoch.internal, actual)
|
||||||
|
|
||||||
|
# None strips epoch
|
||||||
|
self.assertEqual('hash.db', utils.make_db_file_path('hash.db', None))
|
||||||
|
self.assertEqual('/path/to/hash.db', utils.make_db_file_path(
|
||||||
|
'/path/to/hash_withepoch.db', None))
|
||||||
|
|
||||||
# epochs shouldn't have offsets
|
# epochs shouldn't have offsets
|
||||||
epoch = utils.Timestamp.now(offset=10)
|
epoch = utils.Timestamp.now(offset=10)
|
||||||
actual = utils.make_db_file_path(actual, epoch)
|
actual = utils.make_db_file_path(actual, epoch)
|
||||||
@@ -3963,9 +3968,6 @@ cluster_dfw1 = http://dfw1.host/v1/
|
|||||||
self.assertRaises(ValueError, utils.make_db_file_path,
|
self.assertRaises(ValueError, utils.make_db_file_path,
|
||||||
'/path/to/hash.db', 'bad epoch')
|
'/path/to/hash.db', 'bad epoch')
|
||||||
|
|
||||||
self.assertRaises(ValueError, utils.make_db_file_path,
|
|
||||||
'/path/to/hash.db', None)
|
|
||||||
|
|
||||||
def test_modify_priority(self):
|
def test_modify_priority(self):
|
||||||
pid = os.getpid()
|
pid = os.getpid()
|
||||||
logger = debug_logger()
|
logger = debug_logger()
|
||||||
|
|||||||
Reference in New Issue
Block a user