Skip to content

Clean up the database if it will be uploaded #3010

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

Merged
merged 6 commits into from
Aug 7, 2025

Conversation

henrymercer
Copy link
Contributor

Even with --expect-discarded-cache, intermediate results may still be written to the database if there is high RAM pressure. So clean up the database if we will upload it.

There are a couple of approaches to doing this. I went with moving the cleanup into the upload stage to avoid needing to pull out separate logic about whether the upload should take place or not (and potentially needing to run this logic twice). This does make the cleanup slightly less transparent — I added comments and don't think this is too problematic but feedback welcome.

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Confirm the readme has been updated if necessary.
  • Confirm the changelog has been updated if necessary.

@henrymercer henrymercer requested a review from cklin August 7, 2025 11:20
@henrymercer henrymercer requested a review from a team as a code owner August 7, 2025 11:20
@Copilot Copilot AI review requested due to automatic review settings August 7, 2025 11:20
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors database cleanup to ensure databases are properly cleaned before upload operations. The primary purpose is to address the issue where intermediate results may still be written to databases even with --expect-discarded-cache when there is high RAM pressure, requiring cleanup before uploading.

Key changes include:

  • Moving database cleanup logic from a separate stage into the respective upload functions
  • Removing the standalone runCleanup function and cleanupLevel parameter from runQueries
  • Adding databaseCleanupCluster method to the CodeQL interface for cleaning all databases in a cluster

Reviewed Changes

Copilot reviewed 14 out of 21 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/codeql.ts Adds new databaseCleanupCluster method to CodeQL interface and implementation
src/database-upload.ts Integrates database cleanup directly into upload flow with "clear" level cleanup
src/overlay-database-utils.ts Adds database cleanup at "overlay" level before caching overlay databases
src/analyze.ts Removes standalone cleanup function and cleanupLevel parameter from runQueries
src/analyze-action.ts Updates workflow to handle cleanup-level input deprecation and reorders upload operations
src/database-upload.test.ts Updates tests to accommodate new CodeQL parameter and mock cleanup method
src/analyze.test.ts Removes cleanupLevel parameter from test calls
Comments suppressed due to low confidence (1)

src/database-upload.ts:19

  • Adding the codeql parameter to this function is a breaking change to the API. Consider documenting this breaking change in the PR description or changelog to help consumers of this function.
  repositoryNwo: RepositoryNwo,
  codeql: CodeQL,
  config: Config,
  apiDetails: GitHubApiDetails,
  logger: Logger,
): Promise<void> {

"The 'cleanup-level' input is ignored since the CodeQL Action no longer writes intermediate results to the database. This input can safely be removed from your workflow.",
);
}

Copy link
Preview

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cleanup-level deprecation warning has been moved earlier in the function but the logic is duplicated - this same warning appears in the original location. Consider removing this duplication to avoid confusing users with multiple identical warnings.

Suggested change

Copilot uses AI. Check for mistakes.

src/codeql.ts Outdated
@@ -155,6 +155,10 @@ export interface CodeQL {
* Run 'codeql database cleanup'.
*/
databaseCleanup(databasePath: string, cleanupLevel: string): Promise<void>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we remove the databaseCleanup() function, since it is now replaced by databaseCleanupCluster() and no longer used?

@henrymercer henrymercer requested a review from cklin August 7, 2025 14:06
Copy link
Contributor

@cklin cklin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the code update!

@henrymercer henrymercer enabled auto-merge August 7, 2025 14:12
@henrymercer henrymercer merged commit 67a6ea7 into main Aug 7, 2025
282 checks passed
@henrymercer henrymercer deleted the henrymercer/cleanup-for-mrva branch August 7, 2025 14:31
@github-actions github-actions bot mentioned this pull request Aug 7, 2025
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants