Skip to content

Commit

Permalink
Perform object storage test at startup (#5281)
Browse files Browse the repository at this point in the history
Signed-off-by: Changxin Miao <[email protected]>
  • Loading branch information
polyrabbit authored Nov 8, 2024
1 parent 754269a commit c90a175
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ func storageFlags() []cli.Flag {
Name: "download-limit",
Usage: "bandwidth limit for download in Mbps",
},
&cli.BoolFlag{
Name: "check-storage",
// AK/SK should have been checked before creating volume, here checks client access to the storage
Usage: "test storage before mounting to expose access issues early",
},
})
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func doTesting(store object.ObjectStorage, key string, data []byte) error {
return err
}
if !bytes.Equal(data, data2) {
return fmt.Errorf("Read wrong data")
return fmt.Errorf("read wrong data: expected %x, got %x", data, data2)
}
err = store.Delete(key)
if err != nil {
Expand All @@ -362,6 +362,7 @@ func test(store object.ObjectStorage) error {
if err == nil {
break
}
logger.Warnf("Test storage %s failed: %s, tries: #%d", store, err, i+1)
time.Sleep(time.Second * time.Duration(i*3+1))
}
if err == nil {
Expand Down
10 changes: 10 additions & 0 deletions cmd/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,16 @@ func mount(c *cli.Context) error {
}
}
if blob != nil {
// test storage at startup to fail fast instead of throwing EIO in the middle of user's workload
if c.Bool("check-storage") {
start := time.Now()
if err = test(blob); err != nil {
logger.Errorf("Object storage test failed: %s", err)
return err
} else {
logger.Infof("Object storage test passed in %s", time.Since(start))
}
}
object.Shutdown(blob)
}
var foreground bool
Expand Down

0 comments on commit c90a175

Please sign in to comment.