Skip to content

Commit

Permalink
Adding more error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kellrott committed Dec 23, 2019
1 parent 0b6e5da commit 1e864d7
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 60 deletions.
83 changes: 44 additions & 39 deletions grids/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,11 @@ func (ggraph *Graph) DelVertex(id string) error {
ekey := EdgeKey(ggraph.graphKey, eid, sid, did, label)
delKeys = append(delKeys, skey, ekey)

edgeID := ggraph.kdb.keyMap.GetEdgeID(ggraph.graphKey, eid)
if err := ggraph.kdb.keyMap.DelEdgeKey(ggraph.graphKey, edgeID); err != nil {
bulkErr = multierror.Append(bulkErr, err)
edgeID, ok := ggraph.kdb.keyMap.GetEdgeID(ggraph.graphKey, eid)
if ok {
if err := ggraph.kdb.keyMap.DelEdgeKey(ggraph.graphKey, edgeID); err != nil {
bulkErr = multierror.Append(bulkErr, err)
}
}
}
for it.Seek(dkeyPrefix); it.Valid() && bytes.HasPrefix(it.Key(), dkeyPrefix); it.Next() {
Expand All @@ -288,9 +290,11 @@ func (ggraph *Graph) DelVertex(id string) error {
ekey := EdgeKey(ggraph.graphKey, eid, sid, did, label)
delKeys = append(delKeys, ekey)

edgeID := ggraph.kdb.keyMap.GetEdgeID(ggraph.graphKey, eid)
if err := ggraph.kdb.keyMap.DelEdgeKey(ggraph.graphKey, edgeID); err != nil {
bulkErr = multierror.Append(bulkErr, err)
edgeID, ok := ggraph.kdb.keyMap.GetEdgeID(ggraph.graphKey, eid)
if ok {
if err := ggraph.kdb.keyMap.DelEdgeKey(ggraph.graphKey, edgeID); err != nil {
bulkErr = multierror.Append(bulkErr, err)
}
}
}
return bulkErr.ErrorOrNil()
Expand All @@ -307,9 +311,6 @@ func (ggraph *Graph) DelVertex(id string) error {
if err := tx.Delete(vid); err != nil {
return err
}
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 Expand Up @@ -339,17 +340,17 @@ func (ggraph *Graph) GetEdgeList(ctx context.Context, loadProp bool) <-chan *gri
}
keyValue := it.Key()
_, ekey, skey, dkey, label := EdgeKeyParse(keyValue)
labelID := ggraph.kdb.keyMap.GetLabelID(ggraph.graphKey, label)
sid := ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, skey)
did := ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, dkey)
eid := ggraph.kdb.keyMap.GetEdgeID(ggraph.graphKey, ekey)
labelID, _ := ggraph.kdb.keyMap.GetLabelID(ggraph.graphKey, label)
sid, _ := ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, skey)
did, _ := ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, dkey)
eid, _ := ggraph.kdb.keyMap.GetEdgeID(ggraph.graphKey, ekey)
e := &gripql.Edge{Gid: eid, Label: labelID, From: sid, To: did}
if loadProp {
edgeData, _ := it.Value()
e.Data = protoutil.NewStruct()
err := proto.Unmarshal(edgeData, e.Data)
if err != nil {
log.Errorf("GetInChannel: unmarshal error: %v", err)
log.Errorf("GetEdgeList: unmarshal error: %v", err)
continue
}
}
Expand All @@ -372,7 +373,7 @@ func (ggraph *Graph) GetVertex(id string, loadProp bool) *gripql.Vertex {
var v *gripql.Vertex
err := ggraph.kdb.graphkv.View(func(it kvi.KVIterator) error {
lKey := ggraph.kdb.keyMap.GetVertexLabel(ggraph.graphKey, key)
lID := ggraph.kdb.keyMap.GetLabelID(ggraph.graphKey, lKey)
lID, _ := ggraph.kdb.keyMap.GetLabelID(ggraph.graphKey, lKey)
v = &gripql.Vertex{
Gid: id,
Label: lID,
Expand Down Expand Up @@ -427,13 +428,13 @@ func (ggraph *Graph) GetVertexChannel(ids chan gdbi.ElementLookup, load bool) ch
defer close(out)
for d := range data {
lKey := ggraph.kdb.keyMap.GetVertexLabel(ggraph.graphKey, d.key)
lID := ggraph.kdb.keyMap.GetLabelID(ggraph.graphKey, lKey)
lID, _ := ggraph.kdb.keyMap.GetLabelID(ggraph.graphKey, lKey)
v := gripql.Vertex{Gid: d.req.ID, Label: lID}
if load {
v.Data = protoutil.NewStruct()
err := proto.Unmarshal(d.data, v.Data)
if err != nil {
log.Errorf("GetInChannel: unmarshal error: %v", err)
log.Errorf("GetVertexChannel: unmarshal error: %v", err)
continue
}
}
Expand Down Expand Up @@ -485,9 +486,9 @@ func (ggraph *Graph) GetOutChannel(reqChan chan gdbi.ElementLookup, load bool, e
ggraph.kdb.graphkv.View(func(it kvi.KVIterator) error {
for req := range vertexChan {
_, vkey := VertexKeyParse(req.data)
gid := ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, vkey)
gid, _ := ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, vkey)
lkey := ggraph.kdb.keyMap.GetVertexLabel(ggraph.graphKey, vkey)
lid := ggraph.kdb.keyMap.GetLabelID(ggraph.graphKey, lkey)
lid, _ := ggraph.kdb.keyMap.GetLabelID(ggraph.graphKey, lkey)
v := &gripql.Vertex{Gid: gid, Label: lid}
if load {
dataValue, err := it.Get(req.data)
Expand Down Expand Up @@ -531,9 +532,9 @@ func (ggraph *Graph) GetInChannel(reqChan chan gdbi.ElementLookup, load bool, ed
_, _, src, _, label := DstEdgeKeyParse(keyValue)
if len(edgeLabelKeys) == 0 || setcmp.ContainsUint(edgeLabelKeys, label) {
vkey := VertexKey(ggraph.graphKey, src)
srcID := ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, src)
srcID, _ := ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, src)
lID := ggraph.kdb.keyMap.GetVertexLabel(ggraph.graphKey, src)
lKey := ggraph.kdb.keyMap.GetLabelID(ggraph.graphKey, lID)
lKey, _ := ggraph.kdb.keyMap.GetLabelID(ggraph.graphKey, lID)
v := &gripql.Vertex{Gid: srcID, Label: lKey}
if load {
dataValue, err := it.Get(vkey)
Expand Down Expand Up @@ -580,18 +581,18 @@ func (ggraph *Graph) GetOutEdgeChannel(reqChan chan gdbi.ElementLookup, load boo
_, eid, src, dst, label := SrcEdgeKeyParse(keyValue)
if len(edgeLabelKeys) == 0 || setcmp.ContainsUint(edgeLabelKeys, label) {
e := gripql.Edge{}
e.Gid = ggraph.kdb.keyMap.GetEdgeID(ggraph.graphKey, eid)
e.From = ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, src)
e.To = ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, dst)
e.Label = ggraph.kdb.keyMap.GetLabelID(ggraph.graphKey, label)
e.Gid, _ = ggraph.kdb.keyMap.GetEdgeID(ggraph.graphKey, eid)
e.From, _ = ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, src)
e.To, _ = ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, dst)
e.Label, _ = ggraph.kdb.keyMap.GetLabelID(ggraph.graphKey, label)
if load {
ekey := EdgeKey(ggraph.graphKey, eid, src, dst, label)
dataValue, err := it.Get(ekey)
if err == nil {
e.Data = protoutil.NewStruct()
err := proto.Unmarshal(dataValue, e.Data)
if err != nil {
log.Errorf("GetInChannel: unmarshal error: %v", err)
log.Errorf("GetOutEdgeChannel: unmarshal error: %v", err)
continue
}
}
Expand Down Expand Up @@ -631,18 +632,18 @@ func (ggraph *Graph) GetInEdgeChannel(reqChan chan gdbi.ElementLookup, load bool
_, eid, src, dst, label := DstEdgeKeyParse(keyValue)
if len(edgeLabelKeys) == 0 || setcmp.ContainsUint(edgeLabelKeys, label) {
e := gripql.Edge{}
e.Gid = ggraph.kdb.keyMap.GetEdgeID(ggraph.graphKey, eid)
e.From = ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, src)
e.To = ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, dst)
e.Label = ggraph.kdb.keyMap.GetLabelID(ggraph.graphKey, label)
e.Gid, _ = ggraph.kdb.keyMap.GetEdgeID(ggraph.graphKey, eid)
e.From, _ = ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, src)
e.To, _ = ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, dst)
e.Label, _ = ggraph.kdb.keyMap.GetLabelID(ggraph.graphKey, label)
if load {
ekey := EdgeKey(ggraph.graphKey, eid, src, dst, label)
dataValue, err := it.Get(ekey)
if err == nil {
e.Data = protoutil.NewStruct()
err := proto.Unmarshal(dataValue, e.Data)
if err != nil {
log.Errorf("GetInChannel: unmarshal error: %v", err)
log.Errorf("GetInEdgeChannel: unmarshal error: %v", err)
continue
}
}
Expand Down Expand Up @@ -671,12 +672,16 @@ func (ggraph *Graph) GetEdge(id string, loadProp bool) *gripql.Edge {
var e *gripql.Edge
err := ggraph.kdb.graphkv.View(func(it kvi.KVIterator) error {
for it.Seek(ekeyPrefix); it.Valid() && bytes.HasPrefix(it.Key(), ekeyPrefix); it.Next() {
_, eid, src, dst, label := EdgeKeyParse(it.Key())
_, eid, src, dst, labelKey := EdgeKeyParse(it.Key())
gid, _ := ggraph.kdb.keyMap.GetEdgeID(ggraph.graphKey, eid)
from, _ := ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, src)
to, _ := ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, dst)
label, _ := ggraph.kdb.keyMap.GetLabelID(ggraph.graphKey, labelKey)
e = &gripql.Edge{
Gid: ggraph.kdb.keyMap.GetEdgeID(ggraph.graphKey, eid),
From: ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, src),
To: ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, dst),
Label: ggraph.kdb.keyMap.GetLabelID(ggraph.graphKey, label),
Gid: gid,
From: from,
To: to,
Label: label,
}
if loadProp {
d, _ := it.Value()
Expand Down Expand Up @@ -713,14 +718,14 @@ func (ggraph *Graph) GetVertexList(ctx context.Context, loadProp bool) <-chan *g
keyValue := it.Key()
_, vKey := VertexKeyParse(keyValue)
lKey := ggraph.kdb.keyMap.GetVertexLabel(ggraph.graphKey, vKey)
v.Gid = ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, vKey)
v.Label = ggraph.kdb.keyMap.GetLabelID(ggraph.graphKey, lKey)
v.Gid, _ = ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, vKey)
v.Label, _ = ggraph.kdb.keyMap.GetLabelID(ggraph.graphKey, lKey)
if loadProp {
dataValue, _ := it.Value()
v.Data = protoutil.NewStruct()
err := proto.Unmarshal(dataValue, v.Data)
if err != nil {
log.Errorf("GetInChannel: unmarshal error: %v", err)
log.Errorf("GetVertexList: unmarshal error: %v", err)
continue
}
}
Expand Down
12 changes: 6 additions & 6 deletions grids/graph_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,16 +383,16 @@ func (r *PathLabelProc) Process(ctx context.Context, in chan *PathTraveler, out
}

func (rd *RawDataElement) VertexDataElement(ggraph *Graph) *gdbi.DataElement {
Gid := ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, rd.Gid)
Label := ggraph.kdb.keyMap.GetLabelID(ggraph.graphKey, rd.Label)
Gid, _ := ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, rd.Gid)
Label, _ := ggraph.kdb.keyMap.GetLabelID(ggraph.graphKey, rd.Label)
return &gdbi.DataElement{ID: Gid, Label: Label}
}

func (rd *RawDataElement) EdgeDataElement(ggraph *Graph) *gdbi.DataElement {
Gid := ggraph.kdb.keyMap.GetEdgeID(ggraph.graphKey, rd.Gid)
Label := ggraph.kdb.keyMap.GetLabelID(ggraph.graphKey, rd.Label)
To := ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, rd.To)
From := ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, rd.From)
Gid, _ := ggraph.kdb.keyMap.GetEdgeID(ggraph.graphKey, rd.Gid)
Label, _ := ggraph.kdb.keyMap.GetLabelID(ggraph.graphKey, rd.Label)
To, _ := ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, rd.To)
From, _ := ggraph.kdb.keyMap.GetVertexID(ggraph.graphKey, rd.From)
return &gdbi.DataElement{ID: Gid, To: To, From: From, Label: Label}
}

Expand Down
19 changes: 8 additions & 11 deletions grids/keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ func (km *KeyMap) GetVertexKey(graph uint64, id string) (uint64, bool) {
}

//GetVertexID
func (km *KeyMap) GetVertexID(graph uint64, key uint64) string {
k, _ := getKeyID(graph, vKeyPrefix, key, km.db)
return k
func (km *KeyMap) GetVertexID(graph uint64, key uint64) (string, bool) {
return getKeyID(graph, vKeyPrefix, key, km.db)
}

func (km *KeyMap) GetVertexLabel(graph uint64, key uint64) uint64 {
Expand Down Expand Up @@ -145,9 +144,8 @@ func (km *KeyMap) GetEdgeKey(graph uint64, id string) (uint64, bool) {
}

//GetEdgeID gets the GID string for a given edge id uint64
func (km *KeyMap) GetEdgeID(graph uint64, key uint64) string {
k, _ := getKeyID(graph, eKeyPrefix, key, km.db)
return k
func (km *KeyMap) GetEdgeID(graph uint64, key uint64) (string, bool) {
return getKeyID(graph, eKeyPrefix, key, km.db)
}

func (km *KeyMap) GetEdgeLabel(graph uint64, key uint64) uint64 {
Expand All @@ -159,7 +157,7 @@ func (km *KeyMap) GetEdgeLabel(graph uint64, key uint64) uint64 {
func (km *KeyMap) DelVertexKey(graph uint64, id string) error {
key, ok := km.GetVertexKey(graph, id)
if !ok {
return fmt.Errorf("%s not found", id)
return fmt.Errorf("%s vertexKey not found", id)
}
if err := delKeyID(graph, vKeyPrefix, key, km.db); err != nil {
return err
Expand All @@ -174,7 +172,7 @@ func (km *KeyMap) DelVertexKey(graph uint64, id string) error {
func (km *KeyMap) DelEdgeKey(graph uint64, id string) error {
key, ok := km.GetEdgeKey(graph, id)
if !ok {
return fmt.Errorf("%s not found", id)
return fmt.Errorf("%s edgeKey not found", id)
}
if err := delKeyID(graph, eKeyPrefix, key, km.db); err != nil {
return err
Expand Down Expand Up @@ -208,9 +206,8 @@ func (km *KeyMap) GetLabelKey(graph uint64, id string) (uint64, bool) {
}

//GetLabelID gets the GID for a given uint64 label key
func (km *KeyMap) GetLabelID(graph uint64, key uint64) string {
k, _ := getKeyID(graph, lKeyPrefix, key, km.db)
return k
func (km *KeyMap) GetLabelID(graph uint64, key uint64) (string, bool) {
return getKeyID(graph, lKeyPrefix, key, km.db)
}

func getIDKey(graph uint64, prefix []byte, id string, db *pogreb.DB) (uint64, bool) {
Expand Down
20 changes: 16 additions & 4 deletions test/keymap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,18 @@ func TestKeyInsert(t *testing.T) {
}
}
for i := range vertexKeys {
id := keymap.GetVertexID(graphKey, vertexKeys[i])
id, ok := keymap.GetVertexID(graphKey, vertexKeys[i])
if !ok {
t.Errorf("Vertex %d not found", vertexKeys[i])
}
if id != fmt.Sprintf("vertex_%d", i) {
t.Errorf("ID test_%d != %s", i, id)
}
lkey := keymap.GetVertexLabel(graphKey, vertexKeys[i])
lid := keymap.GetLabelID(graphKey, lkey)
lid, ok := keymap.GetLabelID(graphKey, lkey)
if !ok {
t.Errorf("Vertex label %d not found", lkey)
}
if i%2 == 1 {
if lid != "odd" {
t.Errorf("Wrong vertex label %s : %s != %s", id, lid, "odd")
Expand Down Expand Up @@ -100,7 +106,10 @@ func TestKeyInsert(t *testing.T) {
}
}
for i := range edgeKeys {
id := keymap.GetEdgeID(graphKey, edgeKeys[i])
id, ok := keymap.GetEdgeID(graphKey, edgeKeys[i])
if !ok {
t.Errorf("Edge %d not found", edgeKeys[i])
}
if id != fmt.Sprintf("edge_%d", i) {
t.Errorf("ID test_%d != %s", i, id)
}
Expand Down Expand Up @@ -142,7 +151,10 @@ func TestKeyInsert(t *testing.T) {
}
}
for i := range labelKeys {
id := keymap.GetLabelID(graphKey, labelKeys[i])
id, ok := keymap.GetLabelID(graphKey, labelKeys[i])
if !ok {
t.Errorf("Label %d not found", labelKeys[i])
}
if id != fmt.Sprintf("label_%d", i) {
t.Errorf("ID graph_%d != %s", i, id)
}
Expand Down

0 comments on commit 1e864d7

Please sign in to comment.