storj/pkg/pointerdb/config.go
Egon Elbre 83df0ee1b0
Implement ListV2 with storage rework (#303)
1. Added KeyValueStore.Iterate for implementing the different List, ListV2 etc. implementations. This allows for more efficient use of memory depending on the situation.
2. Implemented an inmemory teststore for running tests. This should allow to replace MockKeyValueStore in most places.
3. Rewrote tests
4. Pulled out logger from bolt implementation so it can be used for all other storage implementations.
5. Fixed multiple things in bolt and redis implementations.
2018-09-05 19:10:35 +03:00

50 lines
1.3 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/provider"
"storj.io/storj/pkg/utils"
proto "storj.io/storj/protos/pointerdb"
"storj.io/storj/storage/boltdb"
)
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.NewClient(zap.L(), dburl.Path, PointerBucket)
if err != nil {
return err
}
defer func() { _ = bdb.Close() }()
proto.RegisterPointerDBServer(server.GRPC(), NewServer(bdb, zap.L(), c))
return server.Run(ctx)
}