Clean up a little lint and some shadowed variables
This commit is contained in:
parent
969aa1a6c3
commit
67673b31f4
8 changed files with 26 additions and 20 deletions
|
|
@ -29,7 +29,7 @@ import (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
glog.SetToStderr(true)
|
glog.SetToStderr(true)
|
||||||
cfg := config.ParseConfigFromFile("cayley_appengine.cfg")
|
cfg, _ := config.Load("cayley_appengine.cfg")
|
||||||
qs, _ := graph.NewQuadStore("memstore", "", nil)
|
qs, _ := graph.NewQuadStore("memstore", "", nil)
|
||||||
glog.Errorln(cfg)
|
glog.Errorln(cfg)
|
||||||
db.Load(qs, cfg, cfg.DatabasePath)
|
db.Load(qs, cfg, cfg.DatabasePath)
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,6 @@ var (
|
||||||
}
|
}
|
||||||
hashSize = sha1.Size
|
hashSize = sha1.Size
|
||||||
localFillPercent = 0.7
|
localFillPercent = 0.7
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Token struct {
|
type Token struct {
|
||||||
|
|
@ -209,10 +208,10 @@ func (qs *QuadStore) ApplyDeltas(deltas []graph.Delta, ignoreOpts graph.IgnoreOp
|
||||||
for _, d := range deltas {
|
for _, d := range deltas {
|
||||||
err := qs.buildQuadWrite(tx, d.Quad, d.ID.Int(), d.Action == graph.Add)
|
err := qs.buildQuadWrite(tx, d.Quad, d.ID.Int(), d.Action == graph.Add)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == graph.ErrQuadExists && ignoreOpts.IgnoreDup{
|
if err == graph.ErrQuadExists && ignoreOpts.IgnoreDup {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err == graph.ErrQuadNotExist && ignoreOpts.IgnoreMissing{
|
if err == graph.ErrQuadNotExist && ignoreOpts.IgnoreMissing {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
|
@ -269,7 +268,7 @@ func (qs *QuadStore) buildQuadWrite(tx *bolt.Tx, q quad.Quad, id int64, isAdd bo
|
||||||
return graph.ErrQuadExists
|
return graph.ErrQuadExists
|
||||||
}
|
}
|
||||||
if !isAdd && len(entry.History)%2 == 0 {
|
if !isAdd && len(entry.History)%2 == 0 {
|
||||||
glog.Error("attempt to delete non-existent quad %v: %#c", entry, q)
|
glog.Errorf("attempt to delete non-existent quad %v: %#v", entry, q)
|
||||||
return graph.ErrQuadNotExist
|
return graph.ErrQuadNotExist
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ type Tagger struct {
|
||||||
fixedTags map[string]Value
|
fixedTags map[string]Value
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds a tag to the iterator.
|
// Add a tag to the iterator.
|
||||||
func (t *Tagger) Add(tag string) {
|
func (t *Tagger) Add(tag string) {
|
||||||
t.tags = append(t.tags, tag)
|
t.tags = append(t.tags, tag)
|
||||||
}
|
}
|
||||||
|
|
@ -42,12 +42,12 @@ func (t *Tagger) AddFixed(tag string, value Value) {
|
||||||
t.fixedTags[tag] = value
|
t.fixedTags[tag] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the tags. The returned value must not be mutated.
|
// Tags returns the tags held in the tagger. The returned value must not be mutated.
|
||||||
func (t *Tagger) Tags() []string {
|
func (t *Tagger) Tags() []string {
|
||||||
return t.tags
|
return t.tags
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the fixed tags. The returned value must not be mutated.
|
// Fixed returns the fixed tags held in the tagger. The returned value must not be mutated.
|
||||||
func (t *Tagger) Fixed() map[string]Value {
|
func (t *Tagger) Fixed() map[string]Value {
|
||||||
return t.fixedTags
|
return t.fixedTags
|
||||||
}
|
}
|
||||||
|
|
@ -206,6 +206,7 @@ type IteratorStats struct {
|
||||||
// Type enumerates the set of Iterator types.
|
// Type enumerates the set of Iterator types.
|
||||||
type Type int
|
type Type int
|
||||||
|
|
||||||
|
// These are the iterator types, defined as constants
|
||||||
const (
|
const (
|
||||||
Invalid Type = iota
|
Invalid Type = iota
|
||||||
All
|
All
|
||||||
|
|
@ -306,6 +307,7 @@ func DumpStats(it Iterator) StatsContainer {
|
||||||
|
|
||||||
// Utility logging functions for when an iterator gets called Next upon, or Contains upon, as
|
// Utility logging functions for when an iterator gets called Next upon, or Contains upon, as
|
||||||
// well as what they return. Highly useful for tracing the execution path of a query.
|
// well as what they return. Highly useful for tracing the execution path of a query.
|
||||||
|
|
||||||
func ContainsLogIn(it Iterator, val Value) {
|
func ContainsLogIn(it Iterator, val Value) {
|
||||||
if glog.V(4) {
|
if glog.V(4) {
|
||||||
glog.V(4).Infof("%s %d CHECK CONTAINS %d", strings.ToUpper(it.Type().String()), it.UID(), val)
|
glog.V(4).Infof("%s %d CHECK CONTAINS %d", strings.ToUpper(it.Type().String()), it.UID(), val)
|
||||||
|
|
|
||||||
|
|
@ -90,9 +90,9 @@ func TestShortCircuitingOrBasics(t *testing.T) {
|
||||||
or = NewShortCircuitOr()
|
or = NewShortCircuitOr()
|
||||||
or.AddSubIterator(f1)
|
or.AddSubIterator(f1)
|
||||||
or.AddSubIterator(f2)
|
or.AddSubIterator(f2)
|
||||||
v, exact := or.Size()
|
size, exact := or.Size()
|
||||||
if v != 4 {
|
if size != 4 {
|
||||||
t.Errorf("Unexpected iterator size, got:%d expected %d", v, 4)
|
t.Errorf("Unexpected iterator size, got:%d expected %d", size, 4)
|
||||||
}
|
}
|
||||||
if !exact {
|
if !exact {
|
||||||
t.Error("Size not exact.")
|
t.Error("Size not exact.")
|
||||||
|
|
|
||||||
|
|
@ -160,7 +160,7 @@ func (it *Iterator) NextPath() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// No subiterators.
|
// SubIterators returns no subiterators for a Mongo iterator.
|
||||||
func (it *Iterator) SubIterators() []graph.Iterator {
|
func (it *Iterator) SubIterators() []graph.Iterator {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@ package graph
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"time"
|
|
||||||
"flag"
|
"flag"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/google/cayley/quad"
|
"github.com/google/cayley/quad"
|
||||||
)
|
)
|
||||||
|
|
@ -64,7 +64,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
IgnoreDup = flag.Bool("ignoredup", false, "Don't stop loading on duplicated key on add")
|
IgnoreDup = flag.Bool("ignoredup", false, "Don't stop loading on duplicated key on add")
|
||||||
IgnoreMissing = flag.Bool("ignoremissing", false, "Don't stop loading on missing key on delete")
|
IgnoreMissing = flag.Bool("ignoremissing", false, "Don't stop loading on missing key on delete")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -140,10 +140,12 @@ func buildInOutIterator(obj *otto.Object, qs graph.QuadStore, base graph.Iterato
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildIteratorTreeHelper(obj *otto.Object, qs graph.QuadStore, base graph.Iterator) graph.Iterator {
|
func buildIteratorTreeHelper(obj *otto.Object, qs graph.QuadStore, base graph.Iterator) graph.Iterator {
|
||||||
it := base
|
|
||||||
|
|
||||||
// TODO: Better error handling
|
// TODO: Better error handling
|
||||||
var subIt graph.Iterator
|
var (
|
||||||
|
it graph.Iterator
|
||||||
|
subIt graph.Iterator
|
||||||
|
)
|
||||||
|
|
||||||
if prev, _ := obj.Get("_gremlin_prev"); !prev.IsObject() {
|
if prev, _ := obj.Get("_gremlin_prev"); !prev.IsObject() {
|
||||||
subIt = base
|
subIt = base
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -314,5 +316,8 @@ func buildIteratorTreeHelper(obj *otto.Object, qs graph.QuadStore, base graph.It
|
||||||
and.AddSubIterator(notIt)
|
and.AddSubIterator(notIt)
|
||||||
it = and
|
it = and
|
||||||
}
|
}
|
||||||
|
if it == nil {
|
||||||
|
panic("Iterator building does not catch the output iterator in some case.")
|
||||||
|
}
|
||||||
return it
|
return it
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,9 +57,9 @@ var testQueries = []struct {
|
||||||
func TestMemstoreBackedSexp(t *testing.T) {
|
func TestMemstoreBackedSexp(t *testing.T) {
|
||||||
qs, _ := graph.NewQuadStore("memstore", "", nil)
|
qs, _ := graph.NewQuadStore("memstore", "", nil)
|
||||||
w, _ := graph.NewQuadWriter("single", qs, nil)
|
w, _ := graph.NewQuadWriter("single", qs, nil)
|
||||||
it := BuildIteratorTreeForQuery(qs, "()")
|
emptyIt := BuildIteratorTreeForQuery(qs, "()")
|
||||||
if it.Type() != graph.Null {
|
if emptyIt.Type() != graph.Null {
|
||||||
t.Errorf(`Incorrect type for empty query, got:%q expect: "null"`, it.Type())
|
t.Errorf(`Incorrect type for empty query, got:%q expect: "null"`, emptyIt.Type())
|
||||||
}
|
}
|
||||||
for _, test := range testQueries {
|
for _, test := range testQueries {
|
||||||
if test.add.IsValid() {
|
if test.add.IsValid() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue