cinder-manage: Use same timestamp for purging deleted rows
The ``cinder-manage db purge <age_in_days>`` command currently recalculates the timetamp for deleting rows for each table it processes. This can lead to foreign key constraint errors, as secondary (dependent) tables may be deleted before their corresponding primary (parent) tables, each using slightly different timestamps. This patch addresses the issue by calculating the timestamp once and reusing it across all bulk delete operations, ensuring that all tables are purged relative to the same point in time. Closes-Bug: #2111461 Change-Id: I2aa881936b85b3876d6c9c9cfe3b26932f65241a
This commit is contained in:
@@ -8100,6 +8100,7 @@ def purge_deleted_rows(context, age_in_days):
|
||||
metadata = MetaData()
|
||||
metadata.reflect(engine)
|
||||
|
||||
deleted_age = timeutils.utcnow() - dt.timedelta(days=age_in_days)
|
||||
for table in reversed(metadata.sorted_tables):
|
||||
if 'deleted' not in table.columns.keys():
|
||||
continue
|
||||
@@ -8110,7 +8111,6 @@ def purge_deleted_rows(context, age_in_days):
|
||||
{'age': age_in_days, 'table': table},
|
||||
)
|
||||
|
||||
deleted_age = timeutils.utcnow() - dt.timedelta(days=age_in_days)
|
||||
try:
|
||||
# Delete child records first from quality_of_service_specs
|
||||
# table to avoid FK constraints
|
||||
|
||||
Reference in New Issue
Block a user