update names per discussion at google/cayley#38
This commit is contained in:
parent
d808d9347c
commit
f9c60a5f30
5 changed files with 37 additions and 30 deletions
19
db/load.go
19
db/load.go
|
|
@ -24,20 +24,19 @@ import (
|
||||||
"github.com/google/cayley/nquads"
|
"github.com/google/cayley/nquads"
|
||||||
)
|
)
|
||||||
|
|
||||||
type bulkLoadable interface {
|
|
||||||
// BulkLoad loads Triples from a channel in bulk to the TripleStore. It
|
|
||||||
// returns false if bulk loading is not possible (i.e. if you cannot load
|
|
||||||
// in bulk to a non-empty database, and the current database is non-empty)
|
|
||||||
BulkLoad(chan *graph.Triple) bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func Load(ts graph.TripleStore, cfg *config.Config, triplePath string) {
|
func Load(ts graph.TripleStore, cfg *config.Config, triplePath string) {
|
||||||
tChan := make(chan *graph.Triple)
|
tChan := make(chan *graph.Triple)
|
||||||
go ReadTriplesFromFile(tChan, triplePath)
|
go ReadTriplesFromFile(tChan, triplePath)
|
||||||
|
|
||||||
bulker, canBulk := ts.(bulkLoadable)
|
bulker, canBulk := ts.(graph.BulkLoader)
|
||||||
if canBulk && bulker.BulkLoad(tChan) {
|
if canBulk {
|
||||||
return
|
err := bulker.BulkLoad(tChan)
|
||||||
|
if err == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err != graph.ErrCannotBulkLoad {
|
||||||
|
glog.Errorln("Error attempting to bulk load: ", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadTriplesInto(tChan, ts, cfg.LoadSize)
|
LoadTriplesInto(tChan, ts, cfg.LoadSize)
|
||||||
|
|
|
||||||
|
|
@ -445,7 +445,5 @@ func (ts *TripleStore) FixedIterator() graph.FixedIterator {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
graph.RegisterTripleStore("leveldb",
|
graph.RegisterTripleStore("leveldb", newTripleStore, createNewLevelDB)
|
||||||
graph.TripleStoreGetter(newTripleStore),
|
|
||||||
graph.TripleStoreInit(createNewLevelDB))
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -272,5 +272,5 @@ func (ts *TripleStore) Close() {}
|
||||||
func init() {
|
func init() {
|
||||||
graph.RegisterTripleStore("memstore", func(string, graph.Options) (graph.TripleStore, error) {
|
graph.RegisterTripleStore("memstore", func(string, graph.Options) (graph.TripleStore, error) {
|
||||||
return newTripleStore(), nil
|
return newTripleStore(), nil
|
||||||
})
|
}, nil)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -341,7 +341,5 @@ func (ts *TripleStore) BulkLoad(t_chan chan *graph.Triple) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
graph.RegisterTripleStore("mongo",
|
graph.RegisterTripleStore("mongo", newTripleStore, createNewMongoGraph)
|
||||||
graph.TripleStoreGetter(newTripleStore),
|
|
||||||
graph.TripleStoreInit(createNewMongoGraph))
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -119,34 +119,46 @@ func (d Options) StringKey(key string) (string, bool) {
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
type TripleStoreGetter func(string, Options) (TripleStore, error)
|
var ErrCannotBulkLoad = fmt.Errorf("cannot bulk load")
|
||||||
type TripleStoreInit func(string, Options) error
|
|
||||||
|
|
||||||
var storeRegistry = make(map[string]TripleStoreGetter)
|
type BulkLoader interface {
|
||||||
var storeInitRegistry = make(map[string]TripleStoreInit)
|
// BulkLoad loads Triples from a channel in bulk to the TripleStore. It
|
||||||
|
// returns ErrCannotBulkLoad if bulk loading is not possible (i.e. if you
|
||||||
|
// cannot load in bulk to a non-empty database, and the db is non-empty)
|
||||||
|
BulkLoad(chan *Triple) error
|
||||||
|
}
|
||||||
|
|
||||||
func RegisterTripleStore(name string, getter TripleStoreGetter, initer ...TripleStoreInit) {
|
type NewStoreFunc func(string, Options) (TripleStore, error)
|
||||||
|
type InitStoreFunc func(string, Options) error
|
||||||
|
|
||||||
|
var storeRegistry = make(map[string]NewStoreFunc)
|
||||||
|
var storeInitRegistry = make(map[string]InitStoreFunc)
|
||||||
|
|
||||||
|
func RegisterTripleStore(name string, newFunc NewStoreFunc, initFunc InitStoreFunc) {
|
||||||
if _, found := storeRegistry[name]; found {
|
if _, found := storeRegistry[name]; found {
|
||||||
panic("already registered TripleStore " + name)
|
panic("already registered TripleStore " + name)
|
||||||
}
|
}
|
||||||
storeRegistry[name] = getter
|
storeRegistry[name] = newFunc
|
||||||
if len(initer) > 0 {
|
if initFunc != nil {
|
||||||
storeInitRegistry[name] = initer[0]
|
storeInitRegistry[name] = initFunc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTripleStore(name, dbpath string, opts Options) (TripleStore, error) {
|
func NewTripleStore(name, dbpath string, opts Options) (TripleStore, error) {
|
||||||
getter, hasGetter := storeRegistry[name]
|
newFunc, hasNew := storeRegistry[name]
|
||||||
if !hasGetter {
|
if !hasNew {
|
||||||
return nil, fmt.Errorf("unknown triplestore '%s'", name)
|
return nil, fmt.Errorf("unknown triplestore '%s'", name)
|
||||||
}
|
}
|
||||||
return getter(dbpath, opts)
|
return newFunc(dbpath, opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitTripleStore(name, dbpath string, opts Options) error {
|
func InitTripleStore(name, dbpath string, opts Options) error {
|
||||||
initer, hasInit := storeInitRegistry[name]
|
initFunc, hasInit := storeInitRegistry[name]
|
||||||
if hasInit {
|
if hasInit {
|
||||||
return initer(dbpath, opts)
|
return initFunc(dbpath, opts)
|
||||||
|
}
|
||||||
|
if _, isRegistered := storeRegistry[name]; isRegistered {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("unknown triplestore '%s'", name)
|
return fmt.Errorf("unknown triplestore '%s'", name)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue