storj/pkg/pointerdb/config.go
Egon Elbre b6b6111173
Flatten proto definitions into a single package (#360)
* protos: move streams to pb
* protos: move overlay to pb
* protos: move pointerdb to pb
* protos: move piecestore to pb
* fix statdb import naming
2018-09-18 07:39:06 +03:00

52 lines
1.4 KiB
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package pointerdb
import (
"context"
"go.uber.org/zap"
"storj.io/storj/pkg/pb"
"storj.io/storj/pkg/provider"
"storj.io/storj/pkg/utils"
"storj.io/storj/storage/boltdb"
"storj.io/storj/storage/storelogger"
)
const (
// PointerBucket is the string representing the bucket used for `PointerEntries`
PointerBucket = "pointers"
)
// Config is a configuration struct that is everything you need to start a
// PointerDB responsibility
type Config struct {
DatabaseURL string `help:"the database connection string to use" default:"bolt://$CONFDIR/pointerdb.db"`
MinInlineSegmentSize int64 `default:"1240" help:"minimum inline segment size"`
MaxInlineSegmentSize int `default:"8000" help:"maximum inline segment size"`
}
// Run implements the provider.Responsibility interface
func (c Config) Run(ctx context.Context, server *provider.Provider) error {
dburl, err := utils.ParseURL(c.DatabaseURL)
if err != nil {
return err
}
if dburl.Scheme != "bolt" {
return Error.New("unsupported db scheme: %s", dburl.Scheme)
}
bdb, err := boltdb.New(dburl.Path, PointerBucket)
if err != nil {
return err
}
defer func() { _ = bdb.Close() }()
bdblogged := storelogger.New(zap.L(), bdb)
pb.RegisterPointerDBServer(server.GRPC(), NewServer(bdblogged, zap.L(), c))
return server.Run(ctx)
}