Make flushing tokens more robust
Commit token flushes between batches in order to lower resource
consumption and make flushing more robust for replication
Change-Id: I9be37e420353a336a8acd820eadd47d4bcf7324f
Closes-Bug: #1649616
(cherry picked from commit dc7f810831
)
This commit is contained in:
parent
736149c0cd
commit
6074166b29
|
@ -277,6 +277,8 @@ class Token(token.persistence.TokenDriverBase):
|
|||
|
||||
def flush_expired_tokens(self):
|
||||
with sql.session_for_write() as session:
|
||||
# Turn off autocommit, as it doesn't work well with batch delete
|
||||
session.autocommit = False
|
||||
dialect = session.bind.dialect.name
|
||||
expiry_range_func = self._expiry_range_strategy(dialect)
|
||||
query = session.query(TokenModel.expires)
|
||||
|
@ -286,6 +288,10 @@ class Token(token.persistence.TokenDriverBase):
|
|||
delete_query = query.filter(TokenModel.expires <=
|
||||
expiry_time)
|
||||
row_count = delete_query.delete(synchronize_session=False)
|
||||
# Explicitly commit each batch so as to free up
|
||||
# resources early. We do not actually need
|
||||
# transactional semantics here.
|
||||
session.commit()
|
||||
total_removed += row_count
|
||||
LOG.debug('Removed %d total expired tokens', total_removed)
|
||||
|
||||
|
|
Loading…
Reference in New Issue