-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
solver: add sqlcachestorage as an alternative to the bolt db #5246
Draft
jsternberg
wants to merge
1
commit into
moby:master
Choose a base branch
from
jsternberg:sqlcachestorage
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
debug = true | ||
|
||
[grpc] | ||
debugAddress = "0.0.0.0:6060" | ||
debugAddress = "0.0.0.0:6060" | ||
|
||
[cache] | ||
index-format = "sqlite" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package sqlcachestorage | ||
|
||
const ( | ||
createResultsTableSQL = ` | ||
CREATE TABLE IF NOT EXISTS results ( | ||
id text NOT NULL, | ||
created_at timestamp, | ||
worker_ref_id text NOT NULL | ||
); | ||
` | ||
|
||
createResultsIndexSQL = ` | ||
CREATE INDEX IF NOT EXISTS results_index | ||
ON results (id); | ||
` | ||
|
||
createResultsByRefIndexSQL = ` | ||
CREATE INDEX IF NOT EXISTS results_by_ref_index | ||
ON results (worker_ref_id); | ||
` | ||
|
||
createLinksTableSQL = ` | ||
CREATE TABLE IF NOT EXISTS links ( | ||
source_result_id text NOT NULL, | ||
vertex_input integer DEFAULT 0, | ||
vertex_output integer DEFAULT 0, | ||
vertex_digest text NOT NULL, | ||
vertex_selector text DEFAULT '', | ||
target_result_id text NOT NULL, | ||
UNIQUE (source_result_id, vertex_input, vertex_output, vertex_digest, vertex_selector, target_result_id) | ||
); | ||
` | ||
|
||
createUnreferencedLinksTriggerSQL = ` | ||
CREATE TRIGGER IF NOT EXISTS unreferenced_links_sql AFTER DELETE ON results | ||
BEGIN | ||
DELETE FROM links WHERE source_result_id = old.id OR target_result_id = old.id; | ||
END | ||
` | ||
|
||
createLinksIndexSQL = ` | ||
CREATE INDEX IF NOT EXISTS links_index | ||
ON links (source_result_id, vertex_input, vertex_output, vertex_digest, vertex_selector, target_result_id); | ||
` | ||
|
||
createBacklinksIndexSQL = ` | ||
CREATE INDEX IF NOT EXISTS backlinks_index | ||
ON links (target_result_id); | ||
` | ||
|
||
existsSQL = ` | ||
SELECT 1 FROM results WHERE id = ? LIMIT 1; | ||
` | ||
|
||
walkSQL = ` | ||
SELECT id FROM results; | ||
` | ||
|
||
walkResultsSQL = ` | ||
SELECT worker_ref_id, created_at FROM results WHERE id = ?; | ||
` | ||
|
||
loadSQL = ` | ||
SELECT worker_ref_id, created_at FROM results | ||
WHERE id = ? AND worker_ref_id = ? | ||
LIMIT 1; | ||
` | ||
|
||
addResultSQL = ` | ||
INSERT INTO results (id, created_at, worker_ref_id) | ||
VALUES(?, ?, ?); | ||
` | ||
|
||
deleteResultByRefIDSQL = ` | ||
DELETE FROM results WHERE worker_ref_id = ?; | ||
` | ||
|
||
walkIDsByResultSQL = ` | ||
SELECT DISTINCT id FROM results WHERE worker_ref_id = ?; | ||
` | ||
|
||
addLinkSQL = ` | ||
INSERT INTO links (source_result_id, vertex_input, vertex_output, vertex_digest, vertex_selector, target_result_id) | ||
VALUES (?, ?, ?, ?, ?, ?); | ||
` | ||
|
||
walkLinksSQL = ` | ||
SELECT target_result_id FROM links | ||
WHERE source_result_id = ? AND vertex_input = ? AND vertex_output = ? AND vertex_digest = ? AND vertex_selector = ?; | ||
` | ||
|
||
hasLinkSQL = ` | ||
SELECT 1 FROM links | ||
WHERE source_result_id = ? | ||
AND vertex_input = ? | ||
AND vertex_output = ? | ||
AND vertex_digest = ? | ||
AND vertex_selector = ? | ||
AND target_result_id = ? | ||
LIMIT 1; | ||
` | ||
|
||
walkBacklinksSQL = ` | ||
SELECT source_result_id, vertex_input, vertex_output, vertex_digest, vertex_selector FROM links WHERE target_result_id = ?; | ||
` | ||
) | ||
|
||
var createSQL = []string{ | ||
createResultsTableSQL, | ||
createResultsIndexSQL, | ||
createResultsByRefIndexSQL, | ||
createLinksTableSQL, | ||
createUnreferencedLinksTriggerSQL, | ||
createLinksIndexSQL, | ||
createBacklinksIndexSQL, | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For CGO mode-free you can look at https://pkg.go.dev/modernc.org/sqlite
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can consider this if we need a CGO free mode. At the current moment, we still have the bolt database and we can just easily say "this feature only exists with cgo". I took a look at that project and the C library seems to be faster in most places.
I updated the PR to include some better messages for when cgo is disabled and to also only enable it on linux and darwin which shouldn't even matter much because I don't think you can run buildkit on darwin or windows anyway.