Skip to content

Commit

Permalink
lxd/storage/s3/miniod: Handle error from lock
Browse files Browse the repository at this point in the history
Signed-off-by: Julian Pelizäus <[email protected]>
  • Loading branch information
roosterfish committed Oct 13, 2023
1 parent c28d382 commit dc11fb2
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions lxd/storage/s3/miniod/miniod.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ func (p *Process) Stop(ctx context.Context) error {
return nil
}

spawnUnlock := locking.Lock(context.TODO(), fmt.Sprintf("%s%s", minioLockPrefix, p.bucketName))
spawnUnlock, err := locking.Lock(context.TODO(), fmt.Sprintf("%s%s", minioLockPrefix, p.bucketName))
if err != nil {
return err
}

defer spawnUnlock()

defer p.cancel.Cancel()
Expand Down Expand Up @@ -161,7 +165,11 @@ func EnsureRunning(s *state.State, bucketVol storageDrivers.Volume) (*Process, e
bucketName := bucketVol.Name()

// Prevent concurrent spawning of same bucket.
spawnUnlock := locking.Lock(context.TODO(), fmt.Sprintf("%s%s", minioLockPrefix, bucketName))
spawnUnlock, err := locking.Lock(context.TODO(), fmt.Sprintf("%s%s", minioLockPrefix, bucketName))
if err != nil {
return nil, err
}

defer spawnUnlock()

// Check if there is an existing running minio process for the bucket, and if so return it.
Expand Down Expand Up @@ -346,9 +354,13 @@ func EnsureRunning(s *state.State, bucketVol storageDrivers.Volume) (*Process, e
}

// Get returns an existing MinIO process if it exists.
func Get(bucketName string) *Process {
func Get(bucketName string) (*Process, error) {
// Wait for any ongoing spawn of the bucket process to finish.
spawnUnlock := locking.Lock(context.TODO(), fmt.Sprintf("%s%s", minioLockPrefix, bucketName))
spawnUnlock, err := locking.Lock(context.TODO(), fmt.Sprintf("%s%s", minioLockPrefix, bucketName))
if err != nil {
return nil, err
}

defer spawnUnlock()

// Check if there is an existing running minio process for the bucket, and if so return it.
Expand All @@ -361,10 +373,10 @@ func Get(bucketName string) *Process {
minioProc.transactions++
minios[bucketName] = minioProc

return minioProc
return minioProc, nil
}

return nil
return nil, nil
}

// StopAll stops all MinIO processes cleanly.
Expand Down

0 comments on commit dc11fb2

Please sign in to comment.