Purged unused records from uuids table

This patch also removed transaction id hooks when calling
RootController default get.  As a result, uuids record will
not be created.

Change-Id: I2ca0be02256ec62c8f9d48266867cc44121c1c4b
This commit is contained in:
Chi Lo 2020-02-19 13:36:27 -08:00
parent c7c6cd725a
commit c06ecba646
4 changed files with 38 additions and 4 deletions

View File

@ -7,7 +7,11 @@ class TransactionIdHook(PecanHook):
def before(self, state):
try:
transaction_id = utils.make_transid()
controller = str(state.controller)
if 'RootController._default' in controller:
return
else:
transaction_id = utils.make_transid()
except Exception as exc:
abort(500, headers={'faultstring': str(exc)})

View File

@ -48,6 +48,21 @@ def execute_app_custom_sql(conn):
conn.execute(update_regions, (customer_domain, ))
def execute_purge_uuids_record(conn):
"""Execute custom SQL statements to purge records from uuids table.
Parameters:
conn (sqlalchemy.db): connection object for the SQL database
"""
sql = 'delete from uuids where uuid_type=\'transaction\' and ' \
'uuid not in (select transaction_id from transactions) and ' \
'uuid not in (select tracking_id from transactions) and ' \
'uuid not in (select resource_id from transactions);'
conn.execute(sql)
def main(argv=None):
if argv is None:
@ -112,4 +127,5 @@ def main(argv=None):
conn = engine.connect()
execute_app_custom_sql(conn)
execute_purge_uuids_record(conn)
conn.close()

View File

@ -8,9 +8,13 @@ class TransIdHook(TransactionIdHook):
def before(self, state):
try:
transaction_id = utils.make_transid()
controller = str(state.controller)
if 'RootController._default' in controller:
return
else:
transaction_id = utils.make_transid()
except Exception as exc:
abort(500, headers={'faultstring': exc.message})
abort(500, headers={'faultstring': str(exc)})
tracking_id = state.request.headers['X-RANGER-Tracking-Id'] \
if 'X-RANGER-Tracking-Id' in state.request.headers else transaction_id

View File

@ -1,11 +1,21 @@
from orm.common.orm_common.hooks.transaction_id_hook import TransactionIdHook
from orm.common.orm_common.utils import utils
from pecan import abort
class TransIdHook(TransactionIdHook):
def before(self, state):
transaction_id = utils.make_transid()
try:
controller = str(state.controller)
if 'RootController._default' in controller:
return
else:
transaction_id = utils.make_transid()
except Exception as exc:
abort(500, headers={'faultstring': str(exc)})
tracking_id = state.request.headers['X-RANGER-Tracking-Id'] \
if 'X-RANGER-Tracking-Id' in state.request.headers else transaction_id
setattr(state.request, 'transaction_id', transaction_id)