Commit 326b50f6 authored by Zahoor Mohamed's avatar Zahoor Mohamed Committed by GitHub

Add db capacity flag (#250)

* Add db capacity flag
parent 116d95e1
......@@ -16,17 +16,17 @@ import (
"syscall"
"time"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/node"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func (c *command) initStartCmd() (err error) {
const (
optionNameDataDir = "data-dir"
optionNameDBCapacity = "db-capacity"
optionNamePassword = "password"
optionNamePasswordFile = "password-file"
optionNameAPIAddr = "api-addr"
......@@ -93,6 +93,7 @@ func (c *command) initStartCmd() (err error) {
b, err := node.NewBee(node.Options{
DataDir: c.config.GetString(optionNameDataDir),
DBCapacity: c.config.GetUint64(optionNameDBCapacity),
Password: password,
APIAddr: c.config.GetString(optionNameAPIAddr),
DebugAPIAddr: debugAPIAddr,
......@@ -150,6 +151,7 @@ func (c *command) initStartCmd() (err error) {
}
cmd.Flags().String(optionNameDataDir, filepath.Join(c.homeDir, ".bee"), "data directory")
cmd.Flags().Uint64(optionNameDBCapacity, 5000000, "db capacity in chunks")
cmd.Flags().String(optionNamePassword, "", "password for decrypting keys")
cmd.Flags().String(optionNamePasswordFile, "", "path to a file that contains password for decrypting keys")
cmd.Flags().String(optionNameAPIAddr, ":8080", "HTTP API listen address")
......
......@@ -177,6 +177,7 @@ func New(path string, baseKey []byte, o *Options, logger logging.Logger) (db *DB
if db.capacity == 0 {
db.capacity = defaultCapacity
}
db.logger.Info("setting db capacity to: %v", db.capacity)
if maxParallelUpdateGC > 0 {
db.updateGCSem = make(chan struct{}, maxParallelUpdateGC)
}
......
......@@ -57,6 +57,16 @@ func init() {
}
}
func TestDBCapacity(t *testing.T) {
lo := Options{
Capacity: 500,
}
db := newTestDB(t, &lo)
if db.capacity != 500 {
t.Fatal("could not set db capacity")
}
}
// TestDB validates if the chunk can be uploaded and
// correctly retrieved.
func TestDB(t *testing.T) {
......
......@@ -60,6 +60,7 @@ type Bee struct {
type Options struct {
DataDir string
DBCapacity uint64
Password string
APIAddr string
DebugAPIAddr string
......@@ -192,8 +193,10 @@ func NewBee(o Options) (*Bee, error) {
if o.DataDir != "" {
path = filepath.Join(o.DataDir, "localstore")
}
storer, err = localstore.New(path, address.Bytes(), nil, logger)
lo := &localstore.Options{
Capacity: o.DBCapacity,
}
storer, err = localstore.New(path, address.Bytes(), lo, logger)
if err != nil {
return nil, fmt.Errorf("localstore: %w", err)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment