Stop calling glog.Fatal* in a bunch of places
This commit is contained in:
parent
cacdb74e41
commit
1990eba055
7 changed files with 44 additions and 25 deletions
|
|
@ -92,7 +92,10 @@ func newQuadStore(path string, options graph.Options) (graph.QuadStore, error) {
|
||||||
}
|
}
|
||||||
qs.db = db
|
qs.db = db
|
||||||
// BoolKey returns false on non-existence. IE, Sync by default.
|
// BoolKey returns false on non-existence. IE, Sync by default.
|
||||||
qs.db.NoSync, _ = options.BoolKey("nosync")
|
qs.db.NoSync, _, err = options.BoolKey("nosync")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
err = qs.getMetadata()
|
err = qs.getMetadata()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ package iterator
|
||||||
// In MQL terms, this is the [{"age>=": 21}] concept.
|
// In MQL terms, this is the [{"age>=": 21}] concept.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/google/cayley/graph"
|
"github.com/google/cayley/graph"
|
||||||
|
|
@ -107,8 +106,7 @@ func RunIntOp(a int64, op Operator, b int64) bool {
|
||||||
case compareGTE:
|
case compareGTE:
|
||||||
return a >= b
|
return a >= b
|
||||||
default:
|
default:
|
||||||
log.Fatal("Unknown operator type")
|
panic("Unknown operator type")
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,10 @@ func newQuadStore(path string, options graph.Options) (graph.QuadStore, error) {
|
||||||
var err error
|
var err error
|
||||||
qs.path = path
|
qs.path = path
|
||||||
cacheSize := DefaultCacheSize
|
cacheSize := DefaultCacheSize
|
||||||
if val, ok := options.IntKey("cache_size_mb"); ok {
|
val, ok, err := options.IntKey("cache_size_mb")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else if ok {
|
||||||
cacheSize = val
|
cacheSize = val
|
||||||
}
|
}
|
||||||
qs.dbOpts = &opt.Options{
|
qs.dbOpts = &opt.Options{
|
||||||
|
|
@ -99,7 +102,10 @@ func newQuadStore(path string, options graph.Options) (graph.QuadStore, error) {
|
||||||
qs.dbOpts.ErrorIfMissing = true
|
qs.dbOpts.ErrorIfMissing = true
|
||||||
|
|
||||||
writeBufferSize := DefaultWriteBufferSize
|
writeBufferSize := DefaultWriteBufferSize
|
||||||
if val, ok := options.IntKey("writeBufferSize"); ok {
|
val, ok, err = options.IntKey("writeBufferSize")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else if ok {
|
||||||
writeBufferSize = val
|
writeBufferSize = val
|
||||||
}
|
}
|
||||||
qs.dbOpts.WriteBuffer = writeBufferSize * opt.MiB
|
qs.dbOpts.WriteBuffer = writeBufferSize * opt.MiB
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,10 @@ func createNewMongoGraph(addr string, options graph.Options) error {
|
||||||
}
|
}
|
||||||
conn.SetSafe(&mgo.Safe{})
|
conn.SetSafe(&mgo.Safe{})
|
||||||
dbName := DefaultDBName
|
dbName := DefaultDBName
|
||||||
if val, ok := options.StringKey("database_name"); ok {
|
val, ok, err := options.StringKey("database_name")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if ok {
|
||||||
dbName = val
|
dbName = val
|
||||||
}
|
}
|
||||||
db := conn.DB(dbName)
|
db := conn.DB(dbName)
|
||||||
|
|
@ -94,7 +97,10 @@ func newQuadStore(addr string, options graph.Options) (graph.QuadStore, error) {
|
||||||
}
|
}
|
||||||
conn.SetSafe(&mgo.Safe{})
|
conn.SetSafe(&mgo.Safe{})
|
||||||
dbName := DefaultDBName
|
dbName := DefaultDBName
|
||||||
if val, ok := options.StringKey("database_name"); ok {
|
val, ok, err := options.StringKey("database_name")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else if ok {
|
||||||
dbName = val
|
dbName = val
|
||||||
}
|
}
|
||||||
qs.db = conn.DB(dbName)
|
qs.db = conn.DB(dbName)
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@ package graph
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/barakmich/glog"
|
|
||||||
"github.com/google/cayley/quad"
|
"github.com/google/cayley/quad"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -103,40 +103,40 @@ type QuadStore interface {
|
||||||
|
|
||||||
type Options map[string]interface{}
|
type Options map[string]interface{}
|
||||||
|
|
||||||
func (d Options) IntKey(key string) (int, bool) {
|
func (d Options) IntKey(key string) (int, bool, error) {
|
||||||
if val, ok := d[key]; ok {
|
if val, ok := d[key]; ok {
|
||||||
switch vv := val.(type) {
|
switch vv := val.(type) {
|
||||||
case float64:
|
case float64:
|
||||||
return int(vv), true
|
return int(vv), true, nil
|
||||||
default:
|
default:
|
||||||
glog.Fatalln("Invalid", key, "parameter type from config.")
|
return 0, false, fmt.Errorf("Invalid %s parameter type from config: %T", key, val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0, false
|
return 0, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d Options) StringKey(key string) (string, bool) {
|
func (d Options) StringKey(key string) (string, bool, error) {
|
||||||
if val, ok := d[key]; ok {
|
if val, ok := d[key]; ok {
|
||||||
switch vv := val.(type) {
|
switch vv := val.(type) {
|
||||||
case string:
|
case string:
|
||||||
return vv, true
|
return vv, true, nil
|
||||||
default:
|
default:
|
||||||
glog.Fatalln("Invalid", key, "parameter type from config.")
|
return "", false, fmt.Errorf("Invalid %s parameter type from config: %T", key, val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "", false
|
return "", false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d Options) BoolKey(key string) (bool, bool) {
|
func (d Options) BoolKey(key string) (bool, bool, error) {
|
||||||
if val, ok := d[key]; ok {
|
if val, ok := d[key]; ok {
|
||||||
switch vv := val.(type) {
|
switch vv := val.(type) {
|
||||||
case bool:
|
case bool:
|
||||||
return vv, true
|
return vv, true, nil
|
||||||
default:
|
default:
|
||||||
glog.Fatalln("Invalid", key, "parameter type from config.")
|
return false, false, fmt.Errorf("Invalid %s parameter type from config: %T", key, val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false, false
|
return false, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var ErrCannotBulkLoad = errors.New("quadstore: cannot bulk load")
|
var ErrCannotBulkLoad = errors.New("quadstore: cannot bulk load")
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ package mql
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"math"
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
|
@ -93,7 +92,7 @@ func (q *Query) buildIteratorTreeInternal(query interface{}, path Path) (it grap
|
||||||
it = q.buildResultIterator(path)
|
it = q.buildResultIterator(path)
|
||||||
optional = true
|
optional = true
|
||||||
default:
|
default:
|
||||||
log.Fatal("Unknown JSON type?", query)
|
err = fmt.Errorf("Unknown JSON type: %T")
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
|
|
|
||||||
|
|
@ -33,17 +33,24 @@ type Single struct {
|
||||||
|
|
||||||
func NewSingleReplication(qs graph.QuadStore, opts graph.Options) (graph.QuadWriter, error) {
|
func NewSingleReplication(qs graph.QuadStore, opts graph.Options) (graph.QuadWriter, error) {
|
||||||
var ignoreMissing, ignoreDuplicate bool
|
var ignoreMissing, ignoreDuplicate bool
|
||||||
|
var err error
|
||||||
|
|
||||||
if *graph.IgnoreMissing {
|
if *graph.IgnoreMissing {
|
||||||
ignoreMissing = true
|
ignoreMissing = true
|
||||||
} else {
|
} else {
|
||||||
ignoreMissing, _ = opts.BoolKey("ignore_missing")
|
ignoreMissing, _, err = opts.BoolKey("ignore_missing")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if *graph.IgnoreDup {
|
if *graph.IgnoreDup {
|
||||||
ignoreDuplicate = true
|
ignoreDuplicate = true
|
||||||
} else {
|
} else {
|
||||||
ignoreDuplicate, _ = opts.BoolKey("ignore_duplicate")
|
ignoreDuplicate, _, err = opts.BoolKey("ignore_duplicate")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Single{
|
return &Single{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue