Skip to content

Commit

Permalink
Yikes, propagate cache sizes to db
Browse files Browse the repository at this point in the history
  • Loading branch information
marcopeereboom committed Jan 15, 2025
1 parent 3cc4168 commit dc7612a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
6 changes: 3 additions & 3 deletions cmd/hemictl/hemictl.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func tbcdb() error {

levelDBHome := "~/.tbcd" // XXX
network := "testnet3"
db, err := level.New(ctx, level.NewConfig(filepath.Join(levelDBHome, network)))
db, err := level.New(ctx, level.NewConfig(filepath.Join(levelDBHome, network), "1mb", "128mb"))
if err != nil {
return err
}
Expand All @@ -322,7 +322,7 @@ func tbcdb() error {

levelDBHome := "~/.tbcd" // XXX
network := "testnet3"
db, err := level.New(ctx, level.NewConfig(filepath.Join(levelDBHome, network)))
db, err := level.New(ctx, level.NewConfig(filepath.Join(levelDBHome, network), "1mb", "128mb"))
if err != nil {
return err
}
Expand All @@ -340,7 +340,7 @@ func tbcdb() error {

levelDBHome := "~/.tbcd" // XXX
network := "testnet3"
db, err := level.New(ctx, level.NewConfig(filepath.Join(levelDBHome, network)))
db, err := level.New(ctx, level.NewConfig(filepath.Join(levelDBHome, network), "1mb", "128mb"))
if err != nil {
return err
}
Expand Down
18 changes: 13 additions & 5 deletions database/tbcd/level/level.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@ const (

type IteratorError error

var log = loggo.GetLogger("level")
var (
log = loggo.GetLogger("level")

var ErrIterator = IteratorError(errors.New("iteration error"))
ErrIterator = IteratorError(errors.New("iteration error"))

noStats tbcd.CacheStats
)

func init() {
if err := loggo.ConfigureLoggers(logLevel); err != nil {
Expand Down Expand Up @@ -116,8 +120,7 @@ type Config struct {
blockheaderCacheSize int // parsed size of block header cache
}

func NewConfig(home string) *Config {
blockheaderCacheSizeS := "128mb" // Cache all blockheaders on mainnet
func NewConfig(home, blockheaderCacheSizeS, blockCacheSizeS string) *Config {
blockheaderCacheSize, err := humanize.ParseBytes(blockheaderCacheSizeS)
if err != nil {
panic(err)
Expand All @@ -126,7 +129,6 @@ func NewConfig(home string) *Config {
panic("invalid blockheaderCacheSize")
}

blockCacheSizeS := "1gb" // ~640 blocks on mainnet
blockCacheSize, err := humanize.ParseBytes(blockCacheSizeS)
if err != nil {
panic(err)
Expand Down Expand Up @@ -1657,9 +1659,15 @@ func (l *ldb) BlockTxUpdate(ctx context.Context, direction int, txs map[tbcd.TxK
}

func (l *ldb) BlockHeaderCacheStats() tbcd.CacheStats {
if l.cfg.blockheaderCacheSize == 0 {
return noStats
}
return l.headerCache.Stats()
}

func (l *ldb) BlockCacheStats() tbcd.CacheStats {
if l.cfg.blockCacheSize == 0 {
return noStats
}
return l.blockCache.Stats()
}
5 changes: 2 additions & 3 deletions service/tbc/tbc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2211,9 +2211,8 @@ func (s *Server) DBOpen(ctx context.Context) error {

// Open db.
var err error
cfg := level.NewConfig(filepath.Join(s.cfg.LevelDBHome, s.cfg.Network))
cfg.BlockCacheSize = s.cfg.BlockCacheSize
cfg.BlockheaderCacheSize = s.cfg.BlockheaderCacheSize
cfg := level.NewConfig(filepath.Join(s.cfg.LevelDBHome, s.cfg.Network),
s.cfg.BlockheaderCacheSize, s.cfg.BlockCacheSize)
s.db, err = level.New(ctx, cfg)
if err != nil {
return fmt.Errorf("open level database: %w", err)
Expand Down

0 comments on commit dc7612a

Please sign in to comment.