mongodb: update TTL on expirer run
It's counter-intuitive to need to have to call dbsync when changing the value in the config file, as one expect it to be updated also when running the expirer. Expirer is the standard way. Change-Id: I04bee39ee116f58566e1aabbe72e8af09121776a
This commit is contained in:
parent
e38a3426bf
commit
5760b50204
@ -12,7 +12,6 @@
|
||||
# under the License.
|
||||
"""MongoDB storage backend"""
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
import pymongo
|
||||
|
||||
@ -88,21 +87,19 @@ class Connection(pymongo_base.Connection):
|
||||
('timestamp', pymongo.ASCENDING)],
|
||||
name='event_type_idx'
|
||||
)
|
||||
ttl = cfg.CONF.database.event_time_to_live
|
||||
self.update_ttl(ttl, 'event_ttl', 'timestamp', self.db.event)
|
||||
|
||||
def clear(self):
|
||||
self.conn.drop_database(self.db.name)
|
||||
# Connection will be reopened automatically if needed
|
||||
self.conn.close()
|
||||
|
||||
@staticmethod
|
||||
def clear_expired_event_data(ttl):
|
||||
def clear_expired_event_data(self, ttl):
|
||||
"""Clear expired data from the backend storage system.
|
||||
|
||||
Clearing occurs according to the time-to-live.
|
||||
|
||||
:param ttl: Number of seconds to keep records for.
|
||||
"""
|
||||
LOG.debug("Clearing expired event data is based on native "
|
||||
self.update_ttl(ttl, 'event_ttl', 'timestamp', self.db.event)
|
||||
LOG.info("Clearing expired event data is based on native "
|
||||
"MongoDB time to live feature and going in background.")
|
||||
|
@ -29,40 +29,26 @@ from panko.tests import db as tests_db
|
||||
@tests_db.run_with('mongodb')
|
||||
class IndexTest(tests_db.TestBase):
|
||||
|
||||
def _test_ttl_index_absent(self, conn, coll_name, ttl_opt):
|
||||
# create a fake index and check it is deleted
|
||||
coll = getattr(conn.db, coll_name)
|
||||
index_name = '%s_ttl' % coll_name
|
||||
self.CONF.set_override(ttl_opt, -1, group='database')
|
||||
conn.upgrade()
|
||||
self.assertNotIn(index_name, coll.index_information())
|
||||
|
||||
self.CONF.set_override(ttl_opt, 456789, group='database')
|
||||
conn.upgrade()
|
||||
self.assertEqual(456789,
|
||||
coll.index_information()
|
||||
[index_name]['expireAfterSeconds'])
|
||||
|
||||
def test_event_ttl_index_absent(self):
|
||||
self._test_ttl_index_absent(self.event_conn, 'event',
|
||||
'event_time_to_live')
|
||||
# create a fake index and check it is deleted
|
||||
self.event_conn.clear_expired_event_data(-1)
|
||||
self.assertNotIn("event_ttl",
|
||||
self.event_conn.db.event.index_information())
|
||||
|
||||
def _test_ttl_index_present(self, conn, coll_name, ttl_opt):
|
||||
coll = getattr(conn.db, coll_name)
|
||||
self.CONF.set_override(ttl_opt, 456789, group='database')
|
||||
conn.upgrade()
|
||||
index_name = '%s_ttl' % coll_name
|
||||
self.event_conn.clear_expired_event_data(456789)
|
||||
self.assertEqual(456789,
|
||||
coll.index_information()
|
||||
[index_name]['expireAfterSeconds'])
|
||||
|
||||
self.CONF.set_override(ttl_opt, -1, group='database')
|
||||
conn.upgrade()
|
||||
self.assertNotIn(index_name, coll.index_information())
|
||||
self.event_conn.db.event.index_information()
|
||||
["event_ttl"]['expireAfterSeconds'])
|
||||
|
||||
def test_event_ttl_index_present(self):
|
||||
self._test_ttl_index_present(self.event_conn, 'event',
|
||||
'event_time_to_live')
|
||||
self.event_conn.clear_expired_event_data(456789)
|
||||
self.assertEqual(456789,
|
||||
self.event_conn.db.event.index_information()
|
||||
["event_ttl"]['expireAfterSeconds'])
|
||||
|
||||
self.event_conn.clear_expired_event_data(-1)
|
||||
self.assertNotIn("event_ttl",
|
||||
self.event_conn.db.event.index_information())
|
||||
|
||||
|
||||
class CapabilitiesTest(test_base.BaseTestCase):
|
||||
|
Loading…
Reference in New Issue
Block a user