Skip to content
Merged
Show file tree
Hide file tree
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
28 changes: 28 additions & 0 deletions lib/overlay-database-utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/overlay-database-utils.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions src/overlay-database-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ export enum OverlayDatabaseMode {

export const CODEQL_OVERLAY_MINIMUM_VERSION = "2.22.3";

/**
* The maximum (uncompressed) size of the overlay base database that we will
* upload. Actions Cache has an overall capacity of 10 GB, and the Actions Cache
* client library uses zstd compression.
*
* Ideally we would apply a size limit to the compressed overlay-base database,
* but we cannot do so because compression is handled transparently by the
* Actions Cache client library. Instead we place a limit on the uncompressed
* size of the overlay-base database.
*
* Assuming 2.5:1 compression ratio, the 6 GB limit on uncompressed data would
* translate to a limit of around 2.4 GB after compression.
Comment on lines +31 to +32
Copy link
Member

Choose a reason for hiding this comment

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

2.4GB seems like a relatively large allowance, given that you may have multiple overlay databases, and the 10GB quota is shared between all caches and workflows in a repo.

In the context of Advanced Setup, I am not too worried about this, because users can opt-out of overlay databases if they find that the cache interferes too much with other caches they depend on. (It would probably be nice to also give those users an option to customise the limit, but I appreciate that's unlikely to be a priority right now.)

In the context of Default Setup, this is more of a problem, because users can't opt-out but they may still have other workflows in the same repo that require the cache quota.

That said, a limit is obviously better than no limit and I am happy to approve the PR for that reason.

In the long run, we probably want to start working on a coherent strategy for the use of the cache quota across all three consumers we have in the CodeQL Action now (TRAP caching, dependency caching, and overlay databases). I don't think we have an internal issue to track that, and I'll open one on our team's end if it doesn't exist.

*/
const OVERLAY_BASE_DATABASE_MAX_UPLOAD_SIZE_MB = 6000;
const OVERLAY_BASE_DATABASE_MAX_UPLOAD_SIZE_BYTES =
OVERLAY_BASE_DATABASE_MAX_UPLOAD_SIZE_MB * 1_000_000;

/**
* Writes a JSON file containing Git OIDs for all tracked files (represented
* by path relative to the source root) under the source root. The file is
Expand Down Expand Up @@ -212,6 +229,26 @@ export async function uploadOverlayBaseDatabaseToCache(
});

const dbLocation = config.dbLocation;

const databaseSizeBytes = await tryGetFolderBytes(dbLocation, logger);
if (databaseSizeBytes === undefined) {
logger.warning(
"Failed to determine database size. " +
"Skip uploading overlay-base database to cache.",
);
return false;
}

if (databaseSizeBytes > OVERLAY_BASE_DATABASE_MAX_UPLOAD_SIZE_BYTES) {
const databaseSizeMB = Math.round(databaseSizeBytes / 1_000_000);
logger.warning(
`Database size (${databaseSizeMB} MB) ` +
`exceeds maximum upload size (${OVERLAY_BASE_DATABASE_MAX_UPLOAD_SIZE_MB} MB). ` +
"Skip uploading overlay-base database to cache.",
);
return false;
}

const codeQlVersion = (await codeql.getVersion()).version;
const checkoutPath = getRequiredInput("checkout_path");
const cacheKey = await generateCacheKey(config, codeQlVersion, checkoutPath);
Expand Down
Loading