Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change run deletion (session/synchronize) #1374

Merged
merged 1 commit into from
Feb 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 42 additions & 36 deletions libcodechecker/server/api/report_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1703,46 +1703,52 @@ def getPackageVersion(self):
def removeRunResults(self, run_ids):
self.__require_store()

with DBSession(self.__Session) as session:

runs_to_delete = []
for run_id in run_ids:
LOG.debug('Run id to delete: ' + str(run_id))

run_to_delete = session.query(Run).get(run_id)
if not run_to_delete.can_delete:
LOG.debug("Can't delete " + str(run_id))
continue
failed = False
for run_id in run_ids:
try:
with DBSession(self.__Session) as session:
LOG.debug('Run id to delete: ' + str(run_id))

run_to_delete = session.query(Run).get(run_id)
if not run_to_delete.can_delete:
LOG.debug("Can't delete " + str(run_id))
continue

# Check if there is an existing lock on the given run name,
# which has not expired yet. If so, the run cannot be
# deleted, as someone is assumed to be storing into it.
locks_expired_at = datetime.now() - \
timedelta(
seconds=db_cleanup.RUN_LOCK_TIMEOUT_IN_DATABASE)
lock = session.query(RunLock) \
.filter(RunLock.name == run_to_delete.name,
RunLock.locked_at >= locks_expired_at) \
.one_or_none()
if lock:
LOG.info("Can't delete '{0}' as it is locked."
.format(run_to_delete.name))
continue

run_to_delete.can_delete = False
# Commmit the can_delete flag.
session.commit()

# Check if there is an existing lock on the given run name,
# which has not expired yet. If so, the run cannot be
# deleted, as someone is assumed to be storing into it.
locks_expired_at = datetime.now() - \
timedelta(seconds=db_cleanup.RUN_LOCK_TIMEOUT_IN_DATABASE)
lock = session.query(RunLock) \
.filter(RunLock.name == run_to_delete.name,
RunLock.locked_at >= locks_expired_at) \
.one_or_none()
if lock:
LOG.info("Can't delete '{0}' as it is locked."
.format(run_to_delete.name))
continue
session.query(Run)\
.filter(Run.id == run_id)\
.delete(synchronize_session=False)

run_to_delete.can_delete = False
session.commit()
runs_to_delete.append(run_to_delete)
# Delete files and contents that are not present
# in any bug paths.
db_cleanup.remove_unused_files(session)
session.commit()
session.close()

for run_to_delete in runs_to_delete:
# FIXME: clean up bugpaths. Once run_id is a foreign key there,
# it should be automatic.
session.delete(run_to_delete)
session.commit()
except Exception as ex:
LOG.error("Failed to remove run: " + str(run_id))
LOG.error(ex)
failed = True

# Delete files and contents that are not present in any bug paths.
db_cleanup.remove_unused_files(session)
session.commit()
session.close()
return True
return not failed

# -----------------------------------------------------------------------
@exc_to_thrift_reqfail
Expand Down