diff --git a/commit/log.go b/commit/log.go index 307255cf306cfc595ac262827c93cdb3e65b392a..410b2627d14f37c0c18b096ac567a6f0b5edc4fa 100644 --- a/commit/log.go +++ b/commit/log.go @@ -124,6 +124,7 @@ func (l *Logger) Close() { if err := l.curFile.Close(); err != nil { glog.WithError(err).Error("While closing current file.") } + l.curFile = nil } } @@ -162,6 +163,10 @@ func (l *Logger) handleFile(path string, info os.FileInfo, err error) error { lf.endTs = ts lf.path = path l.list = append(l.list, lf) + + if l.lastLogTs < lf.endTs { + l.lastLogTs = lf.endTs + } return nil } diff --git a/query/query.go b/query/query.go index 50fdda45c71d96b6e64779d54636c898b617ac65..fa1fa741abedbe11bb30273cb6c09897a963b430 100644 --- a/query/query.go +++ b/query/query.go @@ -116,6 +116,10 @@ func mergeInterfaces(i1 interface{}, i2 interface{}) interface{} { } func postTraverse(g *SubGraph) (result map[uint64]interface{}, rerr error) { + if len(g.query) == 0 { + return result, nil + } + result = make(map[uint64]interface{}) // Get results from all children first. cResult := make(map[uint64]interface{}) diff --git a/server/main_test.go b/server/main_test.go index 5cff1c5bf06310ba3e6d10a1fb6c4e920078fe2d..725dc40cc53a53f53f99919e992f503115604560 100644 --- a/server/main_test.go +++ b/server/main_test.go @@ -29,10 +29,6 @@ import ( "github.com/dgraph-io/dgraph/store" ) -func NewStore() (string, error) { - return ioutil.TempDir("", "storetest_") -} - var q0 = ` { user(_xid_:alice) { @@ -46,41 +42,49 @@ var q0 = ` } ` -func prepare() error { - dir, err := ioutil.TempDir("", "storetest_") +func prepare() (dir1, dir2 string, clog *commit.Logger, rerr error) { + var err error + dir1, err = ioutil.TempDir("", "storetest_") if err != nil { - return err + return "", "", nil, err } - - defer os.RemoveAll(dir) ps := new(store.Store) - ps.Init(dir) + ps.Init(dir1) - clog := commit.NewLogger(dir, "mutations", 50<<20) + dir2, err = ioutil.TempDir("", "storemuts_") + if err != nil { + return dir1, "", nil, err + } + clog = commit.NewLogger(dir2, "mutations", 50<<20) clog.Init() - defer clog.Close() posting.Init(ps, clog) f, err := os.Open("testdata.nq") if err != nil { - return err + return dir1, dir2, clog, err } defer f.Close() _, err = handleRdfReader(f) if err != nil { - return err + return dir1, dir2, clog, err } - return nil - // Even though all files would be closed and the directory deleted, - // postings would still be present in memory. + return dir1, dir2, clog, nil +} + +func closeAll(dir1, dir2 string, clog *commit.Logger) { + clog.Close() + os.RemoveAll(dir2) + os.RemoveAll(dir1) } func TestQuery(t *testing.T) { - if err := prepare(); err != nil { + dir1, dir2, clog, err := prepare() + if err != nil { t.Error(err) return } + defer closeAll(dir1, dir2, clog) // Parse GQL into internal query representation. g, err := gql.Parse(q0) @@ -163,10 +167,12 @@ var q1 = ` ` func BenchmarkQuery(b *testing.B) { - if err := prepare(); err != nil { + dir1, dir2, clog, err := prepare() + if err != nil { b.Error(err) return } + defer closeAll(dir1, dir2, clog) b.ResetTimer() for i := 0; i < b.N; i++ { diff --git a/store/store.go b/store/store.go index 37b197b4ff61d7edaf4f8ec01c8b60c16611b4f1..4656e3ec951c31be8cc4830d91846e6d61acdb27 100644 --- a/store/store.go +++ b/store/store.go @@ -17,6 +17,8 @@ package store import ( + "fmt" + "github.com/dgraph-io/dgraph/store/rocksdb" "github.com/dgraph-io/dgraph/x" ) @@ -47,14 +49,12 @@ func (s *Store) Init(filepath string) { } } -/* -func (s *Store) IsNew(id uint64) bool { - return false -} -*/ - func (s *Store) Get(key []byte) (val []byte, rerr error) { - return s.db.Get(s.ropt, key) + val, rerr = s.db.Get(s.ropt, key) + if rerr == nil && val == nil { + return []byte(""), fmt.Errorf("E_KEY_NOT_FOUND") + } + return val, rerr } func (s *Store) SetOne(k []byte, val []byte) error {