Skip to content

Commit

Permalink
Adding error logging and moving some tests to the main package
Browse files Browse the repository at this point in the history
  • Loading branch information
kellrott committed Dec 22, 2019
1 parent 86c6ef2 commit 0b6e5da
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
4 changes: 3 additions & 1 deletion grids/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ func (ggraph *Graph) DelVertex(id string) error {
if err := tx.Delete(vid); err != nil {
return err
}
ggraph.kdb.keyMap.DelVertexKey(ggraph.graphKey, id)
if err := ggraph.kdb.keyMap.DelVertexKey(ggraph.graphKey, id); err != nil {
return err
}
for _, k := range delKeys {
if err := tx.Delete(k); err != nil {
return err
Expand Down
37 changes: 29 additions & 8 deletions grids/keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sync"

"github.com/akrylysov/pogreb"
"github.com/bmeg/grip/log"
)

type KeyMap struct {
Expand Down Expand Up @@ -82,10 +83,20 @@ func (km *KeyMap) GetsertVertexKey(graph uint64, id, label string) (uint64, uint
o, ok := getIDKey(graph, vIDPrefix, id, km.db)
if !ok {
km.vIncMut.Lock()
o, _ = dbInc(&km.vIncCur, vInc, km.db)
var err error
o, err = dbInc(&km.vIncCur, vInc, km.db)
if err != nil {
log.Errorf("%s", err)
}
km.vIncMut.Unlock()
setKeyID(graph, vKeyPrefix, id, o, km.db)
setIDKey(graph, vIDPrefix, id, o, km.db)
err = setKeyID(graph, vKeyPrefix, id, o, km.db)
if err != nil {
log.Errorf("%s", err)
}
err = setIDKey(graph, vIDPrefix, id, o, km.db)
if err != nil {
log.Errorf("%s", err)
}
}
lkey := km.GetsertLabelKey(graph, label)
setIDLabel(graph, vLabelPrefix, o, lkey, km.db)
Expand Down Expand Up @@ -114,11 +125,17 @@ func (km *KeyMap) GetsertEdgeKey(graph uint64, id, label string) (uint64, uint64
km.eIncMut.Lock()
o, _ = dbInc(&km.eIncCur, eInc, km.db)
km.eIncMut.Unlock()
setKeyID(graph, eKeyPrefix, id, o, km.db)
setIDKey(graph, eIDPrefix, id, o, km.db)
if err := setKeyID(graph, eKeyPrefix, id, o, km.db); err != nil {
log.Errorf("%s", err)
}
if err := setIDKey(graph, eIDPrefix, id, o, km.db); err != nil {
log.Errorf("%s", err)
}
}
lkey := km.GetsertLabelKey(graph, label)
setIDLabel(graph, eLabelPrefix, o, lkey, km.db)
if err := setIDLabel(graph, eLabelPrefix, o, lkey, km.db); err != nil {
log.Errorf("%s", err)
}
return o, lkey
}

Expand Down Expand Up @@ -177,8 +194,12 @@ func (km *KeyMap) GetsertLabelKey(graph uint64, id string) uint64 {
km.lIncMut.Lock()
o, _ := dbInc(&km.lIncCur, lInc, km.db)
km.lIncMut.Unlock()
setKeyID(graph, lKeyPrefix, id, o, km.db)
setIDKey(graph, lIDPrefix, id, o, km.db)
if err := setKeyID(graph, lKeyPrefix, id, o, km.db); err != nil {
log.Errorf("%s", err)
}
if err := setIDKey(graph, lIDPrefix, id, o, km.db); err != nil {
log.Errorf("%s", err)
}
return o
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package inspect
package test

import (
"fmt"
Expand Down

0 comments on commit 0b6e5da

Please sign in to comment.