diff --git a/go/common/persistent/persistent.go b/go/common/persistent/persistent.go index 10799f1a10f..388fe62bd10 100644 --- a/go/common/persistent/persistent.go +++ b/go/common/persistent/persistent.go @@ -11,7 +11,7 @@ import ( "github.com/dgraph-io/badger/v2" "github.com/dgraph-io/badger/v2/options" - ekbadger "github.com/oasislabs/oasis-core/go/common/badger" + cmnBadger "github.com/oasislabs/oasis-core/go/common/badger" "github.com/oasislabs/oasis-core/go/common/cbor" "github.com/oasislabs/oasis-core/go/common/logging" ) @@ -24,7 +24,7 @@ var ErrNotFound = errors.New("persistent: key not found in database") // CommonStore is the interface to the common storage for the node. type CommonStore struct { db *badger.DB - gc *ekbadger.GCWorker + gc *cmnBadger.GCWorker } // Close closes the database handle. @@ -47,9 +47,11 @@ func NewCommonStore(dataDir string) (*CommonStore, error) { logger := logging.GetLogger("common/persistent") opts := badger.DefaultOptions(filepath.Join(dataDir, dbName)) - opts = opts.WithLogger(ekbadger.NewLogAdapter(logger)) + opts = opts.WithLogger(cmnBadger.NewLogAdapter(logger)) opts = opts.WithSyncWrites(true) opts = opts.WithCompression(options.None) + // Reduce cache size to 128 KiB as the default is 1 GiB. + opts = opts.WithMaxCacheSize(128 * 1024) db, err := badger.Open(opts) if err != nil { @@ -58,7 +60,7 @@ func NewCommonStore(dataDir string) (*CommonStore, error) { cs := &CommonStore{ db: db, - gc: ekbadger.NewGCWorker(logger, db), + gc: cmnBadger.NewGCWorker(logger, db), } return cs, nil diff --git a/go/consensus/tendermint/db/badger/badger.go b/go/consensus/tendermint/db/badger/badger.go index 93458026ce2..7d6e9629098 100644 --- a/go/consensus/tendermint/db/badger/badger.go +++ b/go/consensus/tendermint/db/badger/badger.go @@ -14,7 +14,7 @@ import ( "github.com/tendermint/tendermint/node" dbm "github.com/tendermint/tm-db" - ekbadger "github.com/oasislabs/oasis-core/go/common/badger" + cmnBadger "github.com/oasislabs/oasis-core/go/common/badger" "github.com/oasislabs/oasis-core/go/common/logging" ) @@ -43,7 +43,7 @@ type badgerDBImpl struct { logger *logging.Logger db *badger.DB - gc *ekbadger.GCWorker + gc *cmnBadger.GCWorker closeOnce sync.Once } @@ -61,9 +61,11 @@ func New(fn string, noSuffix bool) (dbm.DB, error) { logger := baseLogger.With("path", fn) opts := badger.DefaultOptions(fn) // This may benefit from LSMOnlyOptions. - opts = opts.WithLogger(ekbadger.NewLogAdapter(logger)) + opts = opts.WithLogger(cmnBadger.NewLogAdapter(logger)) opts = opts.WithSyncWrites(false) opts = opts.WithCompression(options.Snappy) + // Reduce cache size to 64 MiB as the default is 1 GiB. + opts = opts.WithMaxCacheSize(64 * 1024 * 1024) db, err := badger.Open(opts) if err != nil { @@ -73,7 +75,7 @@ func New(fn string, noSuffix bool) (dbm.DB, error) { impl := &badgerDBImpl{ logger: logger, db: db, - gc: ekbadger.NewGCWorker(logger, db), + gc: cmnBadger.NewGCWorker(logger, db), } return impl, nil diff --git a/go/runtime/history/db.go b/go/runtime/history/db.go index e57c7da4579..ed14f752632 100644 --- a/go/runtime/history/db.go +++ b/go/runtime/history/db.go @@ -52,6 +52,8 @@ func newDB(fn string, runtimeID signature.PublicKey) (*DB, error) { opts = opts.WithLogger(cmnBadger.NewLogAdapter(logger)) opts = opts.WithSyncWrites(true) opts = opts.WithCompression(options.None) + // Reduce cache size to 10 MiB as the default is 1 GiB. + opts = opts.WithMaxCacheSize(10 * 1024 * 1024) db, err := badger.Open(opts) if err != nil { diff --git a/go/storage/mkvs/urkel/db/badger/badger.go b/go/storage/mkvs/urkel/db/badger/badger.go index 373ce293ffb..4b0abc23c82 100644 --- a/go/storage/mkvs/urkel/db/badger/badger.go +++ b/go/storage/mkvs/urkel/db/badger/badger.go @@ -10,7 +10,7 @@ import ( "github.com/pkg/errors" "github.com/oasislabs/oasis-core/go/common" - ekbadger "github.com/oasislabs/oasis-core/go/common/badger" + cmnBadger "github.com/oasislabs/oasis-core/go/common/badger" "github.com/oasislabs/oasis-core/go/common/cbor" "github.com/oasislabs/oasis-core/go/common/crypto/hash" "github.com/oasislabs/oasis-core/go/common/keyformat" @@ -106,9 +106,11 @@ func New(cfg *api.Config) (api.NodeDB, error) { db.CheckpointableDB = api.NewCheckpointableDB(db) opts := badger.DefaultOptions(cfg.DB) - opts = opts.WithLogger(ekbadger.NewLogAdapter(db.logger)) + opts = opts.WithLogger(cmnBadger.NewLogAdapter(db.logger)) opts = opts.WithSyncWrites(!cfg.DebugNoFsync) opts = opts.WithCompression(options.None) + // Reduce cache size to 64 MiB as the default is 1 GiB. + opts = opts.WithMaxCacheSize(64 * 1024 * 1024) var err error if db.db, err = badger.Open(opts); err != nil { @@ -121,7 +123,7 @@ func New(cfg *api.Config) (api.NodeDB, error) { return nil, errors.Wrap(err, "urkel/db/badger: failed to load metadata") } - db.gc = ekbadger.NewGCWorker(db.logger, db.db) + db.gc = cmnBadger.NewGCWorker(db.logger, db.db) return db, nil } @@ -132,7 +134,7 @@ type badgerNodeDB struct { logger *logging.Logger db *badger.DB - gc *ekbadger.GCWorker + gc *cmnBadger.GCWorker meta metadata closeOnce sync.Once diff --git a/go/worker/common/host/local_storage.go b/go/worker/common/host/local_storage.go index 93ec1fca159..9dd5d23723b 100644 --- a/go/worker/common/host/local_storage.go +++ b/go/worker/common/host/local_storage.go @@ -9,7 +9,7 @@ import ( "github.com/dgraph-io/badger/v2" "github.com/dgraph-io/badger/v2/options" - ekbadger "github.com/oasislabs/oasis-core/go/common/badger" + cmnBadger "github.com/oasislabs/oasis-core/go/common/badger" "github.com/oasislabs/oasis-core/go/common/cbor" "github.com/oasislabs/oasis-core/go/common/crypto/signature" "github.com/oasislabs/oasis-core/go/common/keyformat" @@ -26,7 +26,7 @@ type LocalStorage struct { logger *logging.Logger db *badger.DB - gc *ekbadger.GCWorker + gc *cmnBadger.GCWorker } func (s *LocalStorage) Get(id signature.PublicKey, key []byte) ([]byte, error) { @@ -97,15 +97,17 @@ func NewLocalStorage(dataDir, fn string) (*LocalStorage, error) { } opts := badger.DefaultOptions(filepath.Join(dataDir, fn)) - opts = opts.WithLogger(ekbadger.NewLogAdapter(s.logger)) + opts = opts.WithLogger(cmnBadger.NewLogAdapter(s.logger)) opts = opts.WithSyncWrites(true) opts = opts.WithCompression(options.None) + // Reduce cache size to 128 KiB as the default is 1 GiB. + opts = opts.WithMaxCacheSize(128 * 1024) var err error if s.db, err = badger.Open(opts); err != nil { return nil, fmt.Errorf("failed to open local storage database: %w", err) } - s.gc = ekbadger.NewGCWorker(s.logger, s.db) + s.gc = cmnBadger.NewGCWorker(s.logger, s.db) // TODO: The file format could be versioned, but it's not like this // really is subject to change.