in core/lib/payload/cleanup.py [0:0]
def cleanup(self, db="mysql"):
"""
The actual cleanup logic, we will:
- remove all the given files
- drop all the given triggers
- drop all the tables
"""
# Remove file first, because drop trigger may fail because of a full
# disk.
for filepath in self.files_to_clean:
try:
if os.path.isfile(filepath):
util.rm(filepath, self.sudo)
except Exception:
# We will try our best to do the cleanup even when there's an
# exception, because each cleanup entry is independent on each
# other
log.exception("Failed to cleanup file: {}".format(filepath))
# Drop table and triggers
if not self._conn:
self._conn = self.get_conn(db)
self.gen_drop_sqls()
self.get_mysql_settings()
self.init_mysql_version()
self.set_no_binlog()
self.stop_slave_sql()
# Stop sql thread to avoid MDL lock contention and blocking reads before
# running DDLs. Will use high_pri_ddl instead if it's supported
if self.is_high_pri_ddl_supported:
self.enable_priority_ddl()
else:
self.lock_tables(tables=[self.table_name])
self.execute_sql("USE `{}`".format(escape(db)))
current_db = db
for stmt, stmt_db in self.sqls_to_execute:
cleanupError = False
try:
# Switch to the database we are going to work on to avoid
# cross db SQL execution
if stmt_db != current_db:
self.execute_sql("USE `{}`".format(escape(stmt_db)))
current_db = stmt_db
log.info("Executing db: {} sql: {}".format(stmt_db, stmt))
self.execute_sql(stmt)
except MySQLdb.OperationalError as e:
errnum, _ = e.args
# 1507 means the partition doesn't exist, which
# is most likely competing partition maintenance
# 1508 means we tried to drop the last partition in a table
if errnum in [1507, 1508]:
continue
cleanupError = True
error = e
except Exception as e:
cleanupError = True
error = e
if cleanupError:
self.sqls_to_execute = []
if not self.is_high_pri_ddl_supported:
self.unlock_tables()
self.start_slave_sql()
log.error("Failed to execute sql for cleanup")
raise OSCError(
"CLEANUP_EXECUTION_ERROR", {"sql": stmt, "msg": str(error)}
)
if not self.is_high_pri_ddl_supported:
self.unlock_tables()
self.sqls_to_execute = []
self.start_slave_sql()