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 ( ...@@ -16,17 +16,17 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/ethersphere/bee/pkg/logging" "github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/node" "github.com/ethersphere/bee/pkg/node"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
) )
func (c *command) initStartCmd() (err error) { func (c *command) initStartCmd() (err error) {
const ( const (
optionNameDataDir = "data-dir" optionNameDataDir = "data-dir"
optionNameDBCapacity = "db-capacity"
optionNamePassword = "password" optionNamePassword = "password"
optionNamePasswordFile = "password-file" optionNamePasswordFile = "password-file"
optionNameAPIAddr = "api-addr" optionNameAPIAddr = "api-addr"
...@@ -93,6 +93,7 @@ func (c *command) initStartCmd() (err error) { ...@@ -93,6 +93,7 @@ func (c *command) initStartCmd() (err error) {
b, err := node.NewBee(node.Options{ b, err := node.NewBee(node.Options{
DataDir: c.config.GetString(optionNameDataDir), DataDir: c.config.GetString(optionNameDataDir),
DBCapacity: c.config.GetUint64(optionNameDBCapacity),
Password: password, Password: password,
APIAddr: c.config.GetString(optionNameAPIAddr), APIAddr: c.config.GetString(optionNameAPIAddr),
DebugAPIAddr: debugAPIAddr, DebugAPIAddr: debugAPIAddr,
...@@ -150,6 +151,7 @@ func (c *command) initStartCmd() (err error) { ...@@ -150,6 +151,7 @@ func (c *command) initStartCmd() (err error) {
} }
cmd.Flags().String(optionNameDataDir, filepath.Join(c.homeDir, ".bee"), "data directory") 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(optionNamePassword, "", "password for decrypting keys")
cmd.Flags().String(optionNamePasswordFile, "", "path to a file that contains 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") 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 ...@@ -177,6 +177,7 @@ func New(path string, baseKey []byte, o *Options, logger logging.Logger) (db *DB
if db.capacity == 0 { if db.capacity == 0 {
db.capacity = defaultCapacity db.capacity = defaultCapacity
} }
db.logger.Info("setting db capacity to: %v", db.capacity)
if maxParallelUpdateGC > 0 { if maxParallelUpdateGC > 0 {
db.updateGCSem = make(chan struct{}, maxParallelUpdateGC) db.updateGCSem = make(chan struct{}, maxParallelUpdateGC)
} }
......
...@@ -57,6 +57,16 @@ func init() { ...@@ -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 // TestDB validates if the chunk can be uploaded and
// correctly retrieved. // correctly retrieved.
func TestDB(t *testing.T) { func TestDB(t *testing.T) {
......
...@@ -60,6 +60,7 @@ type Bee struct { ...@@ -60,6 +60,7 @@ type Bee struct {
type Options struct { type Options struct {
DataDir string DataDir string
DBCapacity uint64
Password string Password string
APIAddr string APIAddr string
DebugAPIAddr string DebugAPIAddr string
...@@ -192,8 +193,10 @@ func NewBee(o Options) (*Bee, error) { ...@@ -192,8 +193,10 @@ func NewBee(o Options) (*Bee, error) {
if o.DataDir != "" { if o.DataDir != "" {
path = filepath.Join(o.DataDir, "localstore") path = filepath.Join(o.DataDir, "localstore")
} }
lo := &localstore.Options{
storer, err = localstore.New(path, address.Bytes(), nil, logger) Capacity: o.DBCapacity,
}
storer, err = localstore.New(path, address.Bytes(), lo, logger)
if err != nil { if err != nil {
return nil, fmt.Errorf("localstore: %w", err) 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