From aab662176679aaee1324e1d5beab4a394073424c Mon Sep 17 00:00:00 2001 From: Francesc Campoy Date: Tue, 3 Sep 2019 09:41:03 +0530 Subject: [PATCH 1/2] make lru_mb optional Fixes #3850 --- edgraph/config.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/edgraph/config.go b/edgraph/config.go index add909491c9..313d90fd0da 100644 --- a/edgraph/config.go +++ b/edgraph/config.go @@ -18,6 +18,7 @@ package edgraph import ( "fmt" + "os" "path/filepath" "time" @@ -25,6 +26,9 @@ import ( "github.com/dgraph-io/dgraph/x" ) +// #include +import "C" + const ( // AllowMutations is the mode allowing all mutations. AllowMutations int = iota @@ -94,9 +98,19 @@ func (opt *Options) validate() { wd, err := filepath.Abs(opt.WALDir) x.Check(err) x.AssertTruef(pd != wd, "Posting and WAL directory cannot be the same ('%s').", opt.PostingDir) - x.AssertTruefNoTrace(opt.AllottedMemory != -1, - "LRU memory (--lru_mb) must be specified. (At least 1024 MB)") + if opt.AllottedMemory < 0 { + bytes := C.sysconf(C._SC_PHYS_PAGES) * C.sysconf(C._SC_PAGE_SIZE) + mb := bytes / 1024 / 1024 + if mb > MinAllottedMemory { + opt.AllottedMemory = float64(mb / 2) + fmt.Fprintf(os.Stderr, + "LRU memory (--lru_mb) set to %vMB, 50%% of the total RAM found (%vMB)\n"+ + "For more information on --lru_mb please read https://docs.dgraph.io/deploy/#config\n", + opt.AllottedMemory, mb) + } + } x.AssertTruefNoTrace(opt.AllottedMemory >= MinAllottedMemory, - "LRU memory (--lru_mb) must be at least %.0f MB. Currently set to: %f", + "LRU memory (--lru_mb) must be at least %.0f MB. Currently set to: %f\n"+ + "For more information on --lru_mb please read https://docs.dgraph.io/deploy/#config", MinAllottedMemory, opt.AllottedMemory) } From a90ba00bfe1f95a998f07818e83a1f3388b39f6f Mon Sep 17 00:00:00 2001 From: Francesc Campoy Date: Tue, 3 Sep 2019 19:43:40 +0530 Subject: [PATCH 2/2] applied Manish's feedback --- edgraph/config.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/edgraph/config.go b/edgraph/config.go index 313d90fd0da..9f9b5bbbb9f 100644 --- a/edgraph/config.go +++ b/edgraph/config.go @@ -18,10 +18,11 @@ package edgraph import ( "fmt" - "os" "path/filepath" "time" + "github.com/golang/glog" + "github.com/dgraph-io/dgraph/posting" "github.com/dgraph-io/dgraph/x" ) @@ -102,10 +103,11 @@ func (opt *Options) validate() { bytes := C.sysconf(C._SC_PHYS_PAGES) * C.sysconf(C._SC_PAGE_SIZE) mb := bytes / 1024 / 1024 if mb > MinAllottedMemory { - opt.AllottedMemory = float64(mb / 2) - fmt.Fprintf(os.Stderr, - "LRU memory (--lru_mb) set to %vMB, 50%% of the total RAM found (%vMB)\n"+ - "For more information on --lru_mb please read https://docs.dgraph.io/deploy/#config\n", + opt.AllottedMemory = 0.25 * float64(mb) + glog.Infof( + "LRU memory (--lru_mb) set to %vMB, 25%% of the total RAM found (%vMB)\n"+ + "For more information on --lru_mb please read "+ + "https://docs.dgraph.io/deploy/#config\n", opt.AllottedMemory, mb) } }