Skip to content
Permalink
Browse files

server,config,blobstore: don't check BlobsFile at startup

  • Loading branch information...
tsileo committed Mar 19, 2019
1 parent a3d0db3 commit 6246fcd7cf2cc945eea26c7d3a8f1a25e01ff984
Showing with 18 additions and 3 deletions.
  1. +3 −0 blobstash.go
  2. +8 −3 pkg/blobstore/blobstore.go
  3. +1 −0 pkg/config/config.go
  4. +6 −0 pkg/server/server.go
@@ -13,11 +13,13 @@ var (
scan bool
s3scan bool
s3restore bool
check bool
loglevel string
err error
)

func main() {
flag.BoolVar(&check, "check", false, "Check the blobstore consistency.")
flag.BoolVar(&scan, "scan", false, "Trigger a BlobStore rescan.")
flag.BoolVar(&s3scan, "s3-scan", false, "Trigger a BlobStore rescan of the S3 backend.")
flag.BoolVar(&s3restore, "s3-restore", false, "Trigger a BlobStore restore of the S3 backend.")
@@ -32,6 +34,7 @@ func main() {
}

// Set the ScanMode in the config
conf.CheckMode = check
conf.ScanMode = scan
conf.S3ScanMode = s3scan
conf.S3RestoreMode = s3restore
@@ -69,9 +69,6 @@ func New(logger log.Logger, root bool, dir string, conf2 *config.Config, hub *hu
if err != nil {
return nil, fmt.Errorf("failed to init BlobsFile: %v", err)
}
if err := back.CheckBlobsFiles(); err != nil {
return nil, err
}
var s3back *s3.S3Backend
if root && conf2 != nil {
if s3repl := conf2.S3Repl; s3repl != nil && s3repl.Bucket != "" {
@@ -92,6 +89,14 @@ func New(logger log.Logger, root bool, dir string, conf2 *config.Config, hub *hu
}, nil
}

func (bs *BlobStore) Check() error {
if err := bs.back.CheckBlobsFiles(); err != nil {
return err
}

return nil
}

func (bs *BlobStore) ReplicationEnabled() bool {
return bs.s3back != nil
}
@@ -112,6 +112,7 @@ type Config struct {
ReplicateFrom *ReplicateFrom `yaml:"replicate_from"`

// Items defined with the CLI flags
CheckMode bool `yaml:"-"`
ScanMode bool `yaml:"-"`
S3ScanMode bool `yaml:"-"`
S3RestoreMode bool `yaml:"-"`
@@ -94,6 +94,12 @@ func New(conf *config.Config) (*Server, error) {
if err != nil {
return nil, fmt.Errorf("failed to initialize blobstore app: %v", err)
}

if conf.CheckMode {
if err := rootBlobstore.Check(); err != nil {
return nil, fmt.Errorf("failed to check the blobstore: %v", err)
}
}
s.blobstore = rootBlobstore

s.router.Handle("/api/status", basicAuth(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

0 comments on commit 6246fcd

Please sign in to comment.
You can’t perform that action at this time.