ae38817fa3
* Loads cache from context for PointerDB access * WIP adds overlay lookups to pointerdb requests * Pointer lookup code is added for Get * adds feature flag for pointerdb return * refactors pointerdb code * removes some unnecessary debug logs * Fixes indent in config * adds early return for non-remote pointers * formats code, removes some comments * Fixes tests broken by pointer proto changes * adds error check and merges variable declaration * removes commented out proto import * adds error check to pdbclient
55 lines
1.5 KiB
Go
55 lines
1.5 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/overlay"
|
|
"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"`
|
|
Overlay bool `default:"false" help:"toggle flag if overlay is enabled"`
|
|
}
|
|
|
|
// 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() }()
|
|
|
|
cache := overlay.LoadFromContext(ctx)
|
|
bdblogged := storelogger.New(zap.L(), bdb)
|
|
pb.RegisterPointerDBServer(server.GRPC(), NewServer(bdblogged, cache, zap.L(), c))
|
|
|
|
return server.Run(ctx)
|
|
}
|