Permalink
Browse files

Fix the build (#2400)

* Fix the UID bug.
* If we find a deleted version, stop iteration.
* Rename dummyPostingList to emptyPostingList, which is what it is.
* Instead of adding a dummy key, remove a dummy key, so dummy predicate doesn't show up in our states.
* Use require for testing, instead of assert.
* Be able to pick up Facets as well, via json.Number.
  • Loading branch information...
manishrjain committed May 18, 2018
1 parent 9d0022e commit 7205275cc2f66a974febf78a812f9a1ef30243db
Showing with 46 additions and 26 deletions.
  1. +1 −1 contrib/integration/testtxn/main_test.go
  2. +33 −15 edgraph/nquads_from_json.go
  3. +10 −8 posting/lists.go
  4. +2 −2 posting/mvcc.go
@@ -467,7 +467,7 @@ func TestIgnoreIndexConflict(t *testing.T) {
log.Fatalf("Error while running query: %v\n", err)
}
expectedResp := []byte(fmt.Sprintf(`{"me":[{"uid":"%s"},{"uid":"%s"}]}`, uid1, uid2))
x.AssertTrue(bytes.Equal(resp.Json, expectedResp))
require.Equal(t, expectedResp, resp.Json)
}
func TestReadIndexKeySameTxn(t *testing.T) {
@@ -23,8 +23,6 @@ import (
"github.com/twpayne/go-geom/encoding/geojson"
)
// TODO(pawan) - Refactor code here to make it simpler.
func parseFacets(m map[string]interface{}, prefix string) ([]*api.Facet, error) {
// This happens at root.
if prefix == "" {
@@ -55,10 +53,23 @@ func parseFacets(m map[string]interface{}, prefix string) ([]*api.Facet, error)
f.ValType = api.Facet_STRING
fv = v
}
case float64:
// Could be int too, but we just store it as float.
fv = v
f.ValType = api.Facet_FLOAT
case json.Number:
valn := facetVal.(json.Number)
if strings.Index(valn.String(), ".") >= 0 {
if vf, err := valn.Float64(); err != nil {
return nil, err
} else {
fv = vf
f.ValType = api.Facet_FLOAT
}
} else {
if vi, err := valn.Int64(); err != nil {
return nil, err
} else {
fv = vi
f.ValType = api.Facet_INT
}
}
case bool:
fv = v
f.ValType = api.Facet_BOOL
@@ -176,24 +187,31 @@ func mapToNquads(m map[string]interface{}, idx *int, op int, parentPred string)
// Check field in map.
if uidVal, ok := m["uid"]; ok {
var uid uint64
if id, ok := uidVal.(float64); ok {
uid = uint64(id)
// We need to check for length of id as empty string would give an error while
// calling ParseUint. We should assign a new uid if len == 0.
} else if id, ok := uidVal.(string); ok && len(id) > 0 {
if ok := strings.HasPrefix(id, "_:"); ok {
switch uidVal.(type) {
case json.Number:
uidn := uidVal.(json.Number)
ui, err := uidn.Int64()
if err != nil {
return mr, err
}
uid = uint64(ui)
case string:
id := uidVal.(string)
if len(id) == 0 {
uid = 0
} else if ok := strings.HasPrefix(id, "_:"); ok {
mr.uid = id
} else if u, err := strconv.ParseUint(id, 0, 64); err != nil {
return mr, err
} else {
uid = u
}
}
if uid > 0 {
mr.uid = fmt.Sprintf("%d", uid)
}
}
if len(mr.uid) == 0 {
@@ -250,7 +268,7 @@ func mapToNquads(m map[string]interface{}, idx *int, op int, parentPred string)
}
switch v.(type) {
case string, float64, bool, json.Number:
case string, json.Number, bool:
if err := handleBasicType(pred, v, op, &nq); err != nil {
return mr, err
}
View
@@ -31,7 +31,7 @@ import (
)
var (
dummyPostingList []byte // Used for indexing.
emptyPostingList []byte // Used for indexing.
elog trace.EventLog
)
@@ -58,7 +58,7 @@ func init() {
Checksum: h.Sum(nil),
}
var err error
dummyPostingList, err = pl.Marshal()
emptyPostingList, err = pl.Marshal()
x.Check(err)
})
elog = trace.NewEventLog("Memory", "")
@@ -300,12 +300,14 @@ func CommitLists(commit func(key []byte) bool) {
close(workChan)
wg.Wait()
// Consider using sync in syncIfDirty instead of async.
// Hacky solution for now, ensures that everything is flushed to disk before we return.
// The following hack ensures that all the asynchrously run commits above would have been done
// before this completes. Badger now actually gets rid of keys, which are deleted. So, we can
// use the Delete function.
txn := pstore.NewTransactionAt(1, true)
defer txn.Discard()
// Code is written with assumption that nothing is deleted in dgraph, so don't
// use delete
txn.SetWithMeta(x.DataKey("dummy", 1), nil, BitEmptyPosting)
txn.CommitAt(1, nil)
x.Check(txn.Delete(x.DataKey("dummy", 1)))
// Nothing is being read, so there can't be an ErrConflict. This should go to disk.
if err := txn.CommitAt(1, nil); err != nil {
x.Printf("Commit unexpectedly failed with error: %v", err)
}
}
View
@@ -394,8 +394,8 @@ func ReadPostingList(key []byte, it *badger.Iterator) (*List, error) {
for it.Valid() {
item := it.Item()
if item.IsDeletedOrExpired() {
it.Next()
continue
// Don't consider any more versions.
break
}
if !bytes.Equal(item.Key(), l.key) {
break

0 comments on commit 7205275

Please sign in to comment.