-
Notifications
You must be signed in to change notification settings - Fork 3
feat(stovepipe): add BuildStore extension with MySQL implementation #370
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
behinddwalls
merged 4 commits into
uber:main
from
roychying:chenghan.ying/stovepipe-build-storage-extension
Jul 15, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3bcb74f
feat(stovepipe): add BuildStore extension with MySQL implementation
roychying 83bb505
chore(stovepipe): regenerate storage mocks for BuildStore
roychying b861aff
test(stovepipe): add BuildStore contract test suite
roychying d19b86d
remove uri & baseuri from stovepipe build table
roychying 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,45 @@ | ||
| // Copyright (c) 2025 Uber Technologies, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package storage | ||
|
|
||
| //go:generate mockgen -source=build_store.go -destination=mock/build_store_mock.go -package=mock | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/uber/submitqueue/stovepipe/entity" | ||
| ) | ||
|
|
||
| // BuildStore persists builds, keyed by build ID (the runner-assigned id minted at Trigger). | ||
| // build is the sole creator of a row; buildsignal is the sole writer of Status/Version | ||
| // afterward. No reverse index from Request to its builds is needed — buildsignal and record | ||
| // reach a build by the id carried in their messages. | ||
| type BuildStore interface { | ||
| // Create persists a new build. The build must have a unique ID already assigned. | ||
| // Returns ErrAlreadyExists if a build with the same ID already exists. | ||
| Create(ctx context.Context, build entity.Build) error | ||
|
|
||
| // Get retrieves a build by ID. Returns ErrNotFound if the build is not found. | ||
| Get(ctx context.Context, id string) (entity.Build, error) | ||
|
|
||
| // Update persists the mutable fields of build if the currently stored version matches | ||
| // oldVersion, writing newVersion as the new version. Returns ErrVersionMismatch if the | ||
| // stored version does not match (including when the build does not exist). | ||
| // | ||
| // Version arithmetic is owned by the caller: it computes newVersion (typically oldVersion+1) | ||
| // and only assigns build.Version = newVersion after this call succeeds. The store performs | ||
| // a pure conditional write and does not read build.Version. | ||
| Update(ctx context.Context, build entity.Build, oldVersion, newVersion int32) error | ||
| } |
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,130 @@ | ||
| // Copyright (c) 2025 Uber Technologies, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package mysql | ||
|
|
||
| import ( | ||
| "context" | ||
| "database/sql" | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| "github.com/uber-go/tally" | ||
|
|
||
| "github.com/uber/submitqueue/platform/metrics" | ||
| "github.com/uber/submitqueue/stovepipe/entity" | ||
| "github.com/uber/submitqueue/stovepipe/extension/storage" | ||
| ) | ||
|
|
||
| type buildStore struct { | ||
| db *sql.DB | ||
| scope tally.Scope | ||
| } | ||
|
|
||
| // NewBuildStore creates a new MySQL-backed BuildStore. | ||
| func NewBuildStore(db *sql.DB, scope tally.Scope) storage.BuildStore { | ||
| return &buildStore{db: db, scope: scope} | ||
| } | ||
|
|
||
| // Create persists a new build. Returns ErrAlreadyExists if the build ID already exists. | ||
| func (b *buildStore) Create(ctx context.Context, build entity.Build) (retErr error) { | ||
| op := metrics.Begin(b.scope, "create") | ||
| defer func() { op.Complete(retErr) }() | ||
|
|
||
| _, err := b.db.ExecContext(ctx, | ||
| `INSERT INTO build (id, request_id, status, version) | ||
| VALUES (?, ?, ?, ?)`, | ||
| build.ID, | ||
| build.RequestID, | ||
| build.Status, | ||
| build.Version, | ||
| ) | ||
| if err != nil { | ||
| if isDuplicateEntry(err) { | ||
| return fmt.Errorf("build entity id=%s: %w", build.ID, storage.ErrAlreadyExists) | ||
| } | ||
| return fmt.Errorf("failed to insert build entity id=%s: %w", build.ID, err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // Get retrieves a build by ID. Returns ErrNotFound if the build is not found. | ||
| func (b *buildStore) Get(ctx context.Context, id string) (ret entity.Build, retErr error) { | ||
| op := metrics.Begin(b.scope, "get") | ||
| defer func() { op.Complete(retErr) }() | ||
|
|
||
| var build entity.Build | ||
| err := b.db.QueryRowContext(ctx, | ||
| `SELECT id, request_id, status, version | ||
| FROM build WHERE id = ?`, | ||
| id, | ||
| ).Scan( | ||
| &build.ID, | ||
| &build.RequestID, | ||
| &build.Status, | ||
| &build.Version, | ||
| ) | ||
|
|
||
| if errors.Is(err, sql.ErrNoRows) { | ||
| return entity.Build{}, storage.WrapNotFound(err) | ||
| } | ||
| if err != nil { | ||
| return entity.Build{}, fmt.Errorf("failed to get build entity id=%s from the database: %w", id, err) | ||
| } | ||
|
|
||
| return build, nil | ||
| } | ||
|
|
||
| // Update persists the mutable fields of build (status) if the stored version matches | ||
| // oldVersion, writing newVersion. Returns ErrVersionMismatch if the stored version does not | ||
| // match (including when the build does not exist). This is a pure conditional write; the | ||
| // caller owns version arithmetic. | ||
| func (b *buildStore) Update(ctx context.Context, build entity.Build, oldVersion, newVersion int32) (retErr error) { | ||
| op := metrics.Begin(b.scope, "update") | ||
| defer func() { op.Complete(retErr) }() | ||
|
|
||
| result, err := b.db.ExecContext(ctx, | ||
| `UPDATE build | ||
| SET status = ?, version = ? | ||
| WHERE id = ? AND version = ?`, | ||
| build.Status, | ||
| newVersion, | ||
| build.ID, | ||
| oldVersion, | ||
| ) | ||
| if err != nil { | ||
| return fmt.Errorf( | ||
| "failed to update build id=%q oldVersion=%d newVersion=%d: %w", | ||
| build.ID, oldVersion, newVersion, err, | ||
| ) | ||
| } | ||
|
|
||
| rowsAffected, err := result.RowsAffected() | ||
| if err != nil { | ||
| return fmt.Errorf( | ||
| "failed to get rows affected from update for id=%q oldVersion=%d newVersion=%d: %w", | ||
| build.ID, oldVersion, newVersion, err, | ||
| ) | ||
| } | ||
|
|
||
| if rowsAffected != 1 { | ||
| return fmt.Errorf( | ||
| "version mismatch for build update: id=%q expected_version=%d: %w", | ||
| build.ID, oldVersion, storage.ErrVersionMismatch, | ||
| ) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
This file contains hidden or 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,9 @@ | ||
| -- build holds one CI build triggered for a request's commit. id is the runner-assigned build id | ||
| -- minted at Trigger (e.g. a Buildkite build number), opaque and never parsed or derived. | ||
| CREATE TABLE IF NOT EXISTS build ( | ||
| id VARCHAR(255) NOT NULL, | ||
| request_id VARCHAR(255) NOT NULL, | ||
| status VARCHAR(64) NOT NULL, | ||
| version INT NOT NULL, | ||
| PRIMARY KEY (id) | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; |
This file contains hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.