aboutsummaryrefslogtreecommitdiffstats
path: root/syz-cluster/pkg/service
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2025-04-16 17:16:44 +0200
committerAleksandr Nogikh <nogikh@google.com>2025-04-17 07:57:04 +0000
commit94b0f8be5c512cccc2d1dbb405dab561b4d23940 (patch)
treeeaa8113ba775e3dbe7265dde77ba1653057a1285 /syz-cluster/pkg/service
parent552876f8f8f64b90e59c3ecc76806b04f4a30b1c (diff)
syz-cluster: enable atomic updates for SessionTestRepo
A raw InsertOrUpdate method is not very reliable in case of concurrent update requests. Add a callback inside which the modified fields would be set. Refactor the existing code that used to call the old method.
Diffstat (limited to 'syz-cluster/pkg/service')
-rw-r--r--syz-cluster/pkg/service/sessiontest.go30
1 files changed, 16 insertions, 14 deletions
diff --git a/syz-cluster/pkg/service/sessiontest.go b/syz-cluster/pkg/service/sessiontest.go
index a59126860..be410fdb7 100644
--- a/syz-cluster/pkg/service/sessiontest.go
+++ b/syz-cluster/pkg/service/sessiontest.go
@@ -39,25 +39,26 @@ func (s *SessionTestService) Save(ctx context.Context, req *api.TestResult) erro
TestName: req.TestName,
}
}
- entity.Result = req.Result
- entity.UpdatedAt = time.Now()
- if req.BaseBuildID != "" {
- entity.BaseBuildID = spanner.NullString{StringVal: req.BaseBuildID, Valid: true}
- }
- if req.PatchedBuildID != "" {
- entity.PatchedBuildID = spanner.NullString{StringVal: req.PatchedBuildID, Valid: true}
- }
- // TODO: the code does not really handle simultaneous requests.
+ logURI := entity.LogURI
if len(req.Log) > 0 {
- entity.LogURI, err = s.uploadOrUpdate(ctx, entity.LogURI, bytes.NewReader(req.Log))
+ logURI, err = s.uploadOrUpdate(ctx, logURI, bytes.NewReader(req.Log))
if err != nil {
return fmt.Errorf("failed to save the log: %w", err)
}
}
- return s.testRepo.InsertOrUpdate(ctx, entity)
+ return s.testRepo.InsertOrUpdate(ctx, entity, func(test *db.SessionTest) {
+ test.Result = req.Result
+ test.UpdatedAt = time.Now()
+ test.LogURI = logURI
+ if req.BaseBuildID != "" {
+ test.BaseBuildID = spanner.NullString{StringVal: req.BaseBuildID, Valid: true}
+ }
+ if req.PatchedBuildID != "" {
+ test.PatchedBuildID = spanner.NullString{StringVal: req.PatchedBuildID, Valid: true}
+ }
+ })
}
-// TODO: this function has the same problems as Save().
func (s *SessionTestService) SaveArtifacts(ctx context.Context, sessionID, testName string, reader io.Reader) error {
entity, err := s.testRepo.Get(ctx, sessionID, testName)
if err != nil {
@@ -69,8 +70,9 @@ func (s *SessionTestService) SaveArtifacts(ctx context.Context, sessionID, testN
if err != nil {
return fmt.Errorf("failed to save the artifacts archive: %w", err)
}
- entity.ArtifactsArchiveURI = newArchiveURI
- return s.testRepo.InsertOrUpdate(ctx, entity)
+ return s.testRepo.InsertOrUpdate(ctx, entity, func(test *db.SessionTest) {
+ test.ArtifactsArchiveURI = newArchiveURI
+ })
}
func (s *SessionTestService) uploadOrUpdate(ctx context.Context, uri string, reader io.Reader) (string, error) {