Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create option for low mem scenarios avoiding mmap #255

Merged
merged 3 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ api/pb/dart/lib
# vscode config folder
.vscode/

**/node_modules
**/node_modules
tags
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/alecthomas/jsonschema v0.0.0-20191017121752-4bb6e3fae4f2
github.com/c-bata/go-prompt v0.2.3
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/dgraph-io/badger v1.6.0
github.com/evanphx/json-patch v4.5.0+incompatible
github.com/fatih/color v1.7.0
github.com/gogo/googleapis v1.3.1 // indirect
Expand Down
2 changes: 1 addition & 1 deletion store/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewManager(ts service.Service, opts ...Option) (*Manager, error) {
}

if config.Datastore == nil {
datastore, err := newDefaultDatastore(config.RepoPath)
datastore, err := newDefaultDatastore(config.RepoPath, config.LowMem)
if err != nil {
return nil, err
}
Expand Down
17 changes: 15 additions & 2 deletions store/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os"
"path/filepath"

"github.com/dgraph-io/badger/options"
ds "github.com/ipfs/go-datastore"
badger "github.com/ipfs/go-ds-badger"
core "github.com/textileio/go-threads/core/store"
Expand All @@ -24,18 +25,30 @@ type Config struct {
EventCodec core.EventCodec
JsonMode bool
Debug bool
LowMem bool
}

func newDefaultEventCodec(jsonMode bool) core.EventCodec {
return jsonpatcher.New(jsonMode)
}

func newDefaultDatastore(repoPath string) (ds.TxnDatastore, error) {
func newDefaultDatastore(repoPath string, lowMem bool) (ds.TxnDatastore, error) {
path := filepath.Join(repoPath, defaultDatastorePath)
if err := os.MkdirAll(path, os.ModePerm); err != nil {
return nil, err
}
return badger.NewDatastore(path, &badger.DefaultOptions)
opts := badger.DefaultOptions
if lowMem {
opts.TableLoadingMode = options.FileIO
}
return badger.NewDatastore(path, &opts)
}

func WithLowMem(low bool) Option {
return func(sc *Config) error {
sc.LowMem = low
return nil
}
}

func WithJsonMode(enabled bool) Option {
Expand Down
2 changes: 1 addition & 1 deletion store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func NewStore(ts service.Service, opts ...Option) (*Store, error) {
// with the same config.
func newStore(ts service.Service, config *Config) (*Store, error) {
if config.Datastore == nil {
datastore, err := newDefaultDatastore(config.RepoPath)
datastore, err := newDefaultDatastore(config.RepoPath, config.LowMem)
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions store/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func DefaultService(repoPath string, opts ...ServiceOption) (ServiceBoostrapper,
// Build a logstore
logstorePath := filepath.Join(repoPath, defaultLogstorePath)
if err := os.MkdirAll(logstorePath, os.ModePerm); err != nil {
cancel()
return nil, err
}
logstore, err := badger.NewDatastore(logstorePath, &badger.DefaultOptions)
Expand Down