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

Basic support for overlay databases #2801

Merged
merged 4 commits into from
Mar 11, 2025
Merged

Basic support for overlay databases #2801

merged 4 commits into from
Mar 11, 2025

Conversation

cklin
Copy link
Contributor

@cklin cklin commented Mar 7, 2025

This PR implements basic support for overlay databases. It does not handle the uploading and downloading of overlay-base databases; for now we are assuming that the workflow will provide the necessary functionality.

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.

@cklin cklin force-pushed the cklin/overlay-databases branch 2 times, most recently from a083032 to 6ced3c5 Compare March 7, 2025 21:04
@cklin cklin marked this pull request as ready for review March 7, 2025 21:31
@cklin cklin requested a review from a team as a code owner March 7, 2025 21:31
@cklin cklin requested a review from henrymercer March 7, 2025 21:45
@cklin cklin force-pushed the cklin/overlay-databases branch from 6ced3c5 to abbb392 Compare March 7, 2025 22:05
@cklin cklin marked this pull request as draft March 10, 2025 15:05
@cklin
Copy link
Contributor Author

cklin commented Mar 10, 2025

I thought about it over the weekend and decided to make some changes. So taking the PR back to draft mode for now.

When a user specifies "cleanup-level: overlay", it suggests that the
user wishes to preserve the evaluation cache for future use. So in this
case we should not set --expect-discarded-cache when running queries.
@cklin cklin force-pushed the cklin/overlay-databases branch from abbb392 to 95bbe5b Compare March 10, 2025 20:20
cklin added 3 commits March 10, 2025 13:22
This commit adds a OverlayDatabaseMode parameter to
databaseInitCluster(). The parameter controls the "codeql database init"
flags concerning overlay database creation.

There is no behavior change in this commit because we always pass
OverlayDatabaseMode.None to databaseInitCluster(). That will change in
the next commit.
This commit adds support for creating overlay-base and overlay
databases, controlled via the CODEQL_OVERLAY_DATABASE_MODE environment
variable.
@cklin cklin force-pushed the cklin/overlay-databases branch from 95bbe5b to 0efe12d Compare March 10, 2025 20:31
@cklin
Copy link
Contributor Author

cklin commented Mar 10, 2025

I split the large "Support overlay database creation" commit into smaller commits. In addition to making the PR easier to review, the split also allows me to remove the code changes for file change detection, which is a functionality not used in this PR. As a result the PR as a whole is now smaller too.

@cklin cklin marked this pull request as ready for review March 10, 2025 21:04
Comment on lines +298 to +299
const cleanupLevel =
actionsUtil.getOptionalInput("cleanup-level") || "brutal";
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it meaningful for users to enable overlay databases with a cleanup level that isn't overlay?

Should this default to overlay if overlay mode is enabled and a cleanup mode isn't specified? Note that this would also require changing analyze/action.yml as this default is unfortunately currently specified twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When creating an overlay-base database, the only cleanup levels that make sense are overlay and none. So there is room for selecting a more sensible default cleanup level based on the overlay mode.

At this point we have not decided how we want the overlay database mode selection to work for the long run, which would affect how we communicate the selected overlay database mode to the analyze action. For the purpose of this PR, we are assuming that the invoking workflow handles all the complexity so that we can minimize the action changes, both in terms of new code and new design assumptions / commitments.

So I will keep your suggestion in mind and leave this PR as-is.

): Promise<OverlayDatabaseMode> {
const overlayDatabaseMode = process.env.CODEQL_OVERLAY_DATABASE_MODE;

if (
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional nit: consider using a switch statement with assertNever so if we add new cases to the OverlayDatabaseMode enum, the type checker will remind us to cover them here.

It's optional since we probably won't be adding new cases to this enum.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! I looked at both places and decided that the benefit does not quite justify the increased code verbosity. Hopefully, if we should add a new value to the OverlayDatabaseMode enum, it would be apparent that we need to change where we make the OverlayDatabaseMode selection (here) and where we use the OverlayDatabaseMode value (in databaseInitCluster).

@@ -606,12 +609,20 @@ export async function getCodeQLForCmd(
? "--force-overwrite"
: "--overwrite";

if (overlayDatabaseMode === OverlayDatabaseMode.Overlay) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar nit here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks—responded above.

@cklin cklin merged commit 13f2f96 into main Mar 11, 2025
533 checks passed
@cklin cklin deleted the cklin/overlay-databases branch March 11, 2025 15:33
@github-actions github-actions bot mentioned this pull request Mar 19, 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