Skip to content

Commit

Permalink
Fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Zdybał committed Jul 13, 2017
1 parent 0d67f20 commit 0fcff13
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 28 deletions.
10 changes: 5 additions & 5 deletions cmd/dgraph/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func setupConfigOpts() {
flag.BoolVar(&config.ExpandEdge, "expand_edge", defaults.ExpandEdge,
"Don't store predicates per node.")

flag.Float64Var(&config.MaxMemory, "max_memory_mb", defaults.MaxMemory,
flag.Float64Var(&config.AllottedMemory, "max_memory_mb", defaults.AllottedMemory,
"Estimated max memory the process can take")
flag.Float64Var(&config.CommitFraction, "gentlecommit",
defaults.CommitFraction,
Expand Down Expand Up @@ -673,10 +673,10 @@ func main() {

// Posting will initialize index which requires schema. Hence, initialize
// schema before calling posting.Init().
schema.Init(dgraph.State.PStore)
posting.Init(dgraph.State.PStore)
schema.Init(dgraph.State.Pstore)
posting.Init(dgraph.State.Pstore)
worker.Config.InMemoryComm = false
worker.Init(dgraph.State.PStore)
worker.Init(dgraph.State.Pstore)

// setup shutdown os signal handler
sdCh := make(chan os.Signal, 1)
Expand All @@ -693,7 +693,7 @@ func main() {
// Setup external communication.
che := make(chan error, 1)
go setupServer(che)
go worker.StartRaftNodes(dgraph.State.WALStore)
go worker.StartRaftNodes(dgraph.State.WALstore)

if err := <-che; !strings.Contains(err.Error(),
"use of closed network connection") {
Expand Down
15 changes: 7 additions & 8 deletions cmd/dgraph/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ func prepare() (dir1, dir2 string, ps *badger.KV, rerr error) {
dgraph.Config.WALDir = dir2
dgraph.State = dgraph.NewServerState()

posting.Init(dgraph.State.PStore)
posting.Init(dgraph.State.Pstore)
group.ParseGroupConfig("groups.conf")
schema.Init(dgraph.State.PStore)
worker.Init(dgraph.State.PStore)
worker.StartRaftNodes(dgraph.State.WALStore)
schema.Init(dgraph.State.Pstore)
worker.Init(dgraph.State.Pstore)
worker.StartRaftNodes(dgraph.State.WALstore)

return dir1, dir2, ps, nil
}
Expand Down Expand Up @@ -1291,10 +1291,9 @@ func TestSchemaMutation5Error(t *testing.T) {

func TestMain(m *testing.M) {
x.Init()
worker.Config.GroupIds = "0,1"
worker.Config.RaftId = 1
posting.Config.MaxMemory = 1024.0
posting.Config.CommitFraction = 0.10

dgraph.SetConfiguration(dgraph.DefaultConfig)

dir1, dir2, ps, _ := prepare()
defer ps.Close()
defer closeAll(dir1, dir2)
Expand Down
6 changes: 3 additions & 3 deletions dgraph/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Options struct {
Nomutations bool
NumPending int

MaxMemory float64
AllottedMemory float64
CommitFraction float64

BaseWorkerPort int
Expand Down Expand Up @@ -57,7 +57,7 @@ var DefaultConfig = Options{
Nomutations: false,
NumPending: 1000,

MaxMemory: 1024.0,
AllottedMemory: 1024.0,
CommitFraction: 0.10,

BaseWorkerPort: 12345,
Expand All @@ -81,7 +81,7 @@ func SetConfiguration(newConfig Options) {

Config = newConfig

posting.Config.MaxMemory = Config.MaxMemory
posting.Config.AllottedMemory = Config.AllottedMemory
posting.Config.CommitFraction = Config.CommitFraction

worker.Config.BaseWorkerPort = Config.BaseWorkerPort
Expand Down
12 changes: 6 additions & 6 deletions dgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type ServerState struct {
FinishCh chan struct{} // channel to wait for all pending reqs to finish.
ShutdownCh chan struct{} // channel to signal shutdown.

PStore *badger.KV
WALStore *badger.KV
Pstore *badger.KV
WALstore *badger.KV
}

// TODO(tzdybal) - remove global
Expand All @@ -66,7 +66,7 @@ func (s *ServerState) initStorage() {
kvOpt.MapTablesTo = table.Nothing

var err error
s.WALStore, err = badger.NewKV(&kvOpt)
s.WALstore, err = badger.NewKV(&kvOpt)
x.Checkf(err, "Error while creating badger KV WAL store")

// Postings directory
Expand All @@ -78,13 +78,13 @@ func (s *ServerState) initStorage() {
opt.Dir = Config.PostingDir
opt.ValueDir = Config.PostingDir
opt.MapTablesTo = table.MemoryMap
s.PStore, err = badger.NewKV(&opt)
s.Pstore, err = badger.NewKV(&opt)
x.Checkf(err, "Error while creating badger KV posting store")
}

func (s *ServerState) Dispose() {
s.PStore.Close()
s.WALStore.Close()
s.Pstore.Close()
s.WALstore.Close()
}

// Server implements protos.DgraphServer
Expand Down
2 changes: 1 addition & 1 deletion posting/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package posting

type Options struct {
MaxMemory float64
AllottedMemory float64
CommitFraction float64
}

Expand Down
2 changes: 1 addition & 1 deletion posting/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ var ps *badger.KV
func TestMain(m *testing.M) {
x.SetTestRun()
x.Init()
Config.MaxMemory = 1024.0
Config.AllottedMemory = 1024.0
Config.CommitFraction = 0.10

dir, err := ioutil.TempDir("", "storetest_")
Expand Down
4 changes: 2 additions & 2 deletions posting/lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ func periodicCommit() {
// Okay, we exceed the max memory threshold.
// Stop the world, and deal with this first.
x.NumGoRoutines.Set(int64(runtime.NumGoroutine()))
if setLruMemory && inUse > 0.75*(Config.MaxMemory) {
go lcache.UpdateMaxSize()
if setLruMemory && inUse > 0.75*(Config.AllottedMemory) {
lcache.UpdateMaxSize()
setLruMemory = false
}
}
Expand Down
2 changes: 1 addition & 1 deletion query/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6596,7 +6596,7 @@ func TestMain(m *testing.M) {

worker.Config.GroupIds = "0,1"
worker.Config.RaftId = 1
posting.Config.MaxMemory = 1024.0
posting.Config.AllottedMemory = 1024.0
posting.Config.CommitFraction = 0.10
group.ParseGroupConfig("")
schema.Init(ps)
Expand Down
2 changes: 1 addition & 1 deletion worker/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ func TestProcessSortOffsetCount(t *testing.T) {

func TestMain(m *testing.M) {
x.Init()
posting.Config.MaxMemory = 1024.0
posting.Config.AllottedMemory = 1024.0
posting.Config.CommitFraction = 0.10
x.AssertTruef(!x.IsTestRun(), "We use watermarks for syncing.")
os.Exit(m.Run())
Expand Down

0 comments on commit 0fcff13

Please sign in to comment.