Added functionality so quadstore is generated per request (if needed) for the new appengine backend \n CR : nobody \n Tests run: unit tests
This commit is contained in:
parent
2c74cb1657
commit
35ccfe7677
8 changed files with 130 additions and 51 deletions
|
|
@ -33,7 +33,7 @@ import (
|
|||
)
|
||||
|
||||
func init() {
|
||||
graph.RegisterQuadStore("bolt", true, newQuadStore, createNewBolt)
|
||||
graph.RegisterQuadStore("bolt", true, newQuadStore, createNewBolt, nil)
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
@ -44,6 +44,10 @@ var (
|
|||
localFillPercent = 0.7
|
||||
)
|
||||
|
||||
const (
|
||||
QuadStoreType = "bolt"
|
||||
)
|
||||
|
||||
type Token struct {
|
||||
bucket []byte
|
||||
key []byte
|
||||
|
|
@ -515,3 +519,7 @@ func compareTokens(a, b graph.Value) bool {
|
|||
func (qs *QuadStore) FixedIterator() graph.FixedIterator {
|
||||
return iterator.NewFixed(compareTokens)
|
||||
}
|
||||
|
||||
func (qs *QuadStore) GetType() string {
|
||||
return QuadStoreType
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,12 +35,13 @@ import (
|
|||
)
|
||||
|
||||
func init() {
|
||||
graph.RegisterQuadStore("leveldb", true, newQuadStore, createNewLevelDB)
|
||||
graph.RegisterQuadStore(QuadStoreType, true, newQuadStore, createNewLevelDB, nil)
|
||||
}
|
||||
|
||||
const (
|
||||
DefaultCacheSize = 2
|
||||
DefaultWriteBufferSize = 20
|
||||
QuadStoreType = "leveldb"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -495,3 +496,7 @@ func compareBytes(a, b graph.Value) bool {
|
|||
func (qs *QuadStore) FixedIterator() graph.FixedIterator {
|
||||
return iterator.NewFixed(compareBytes)
|
||||
}
|
||||
|
||||
func (qs *QuadStore) GetType() string {
|
||||
return QuadStoreType
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,10 +27,12 @@ import (
|
|||
"github.com/google/cayley/quad"
|
||||
)
|
||||
|
||||
const QuadStoreType = "memstore"
|
||||
|
||||
func init() {
|
||||
graph.RegisterQuadStore("memstore", false, func(string, graph.Options) (graph.QuadStore, error) {
|
||||
graph.RegisterQuadStore(QuadStoreType, false, func(string, graph.Options) (graph.QuadStore, error) {
|
||||
return newQuadStore(), nil
|
||||
}, nil)
|
||||
}, nil, nil)
|
||||
}
|
||||
|
||||
type QuadDirectionIndex struct {
|
||||
|
|
@ -270,3 +272,7 @@ func (qs *QuadStore) NodesAllIterator() graph.Iterator {
|
|||
}
|
||||
|
||||
func (qs *QuadStore) Close() {}
|
||||
|
||||
func (qs *QuadStore) GetType() string {
|
||||
return QuadStoreType
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,11 +30,12 @@ import (
|
|||
"github.com/google/cayley/quad"
|
||||
)
|
||||
|
||||
func init() {
|
||||
graph.RegisterQuadStore("mongo", true, newQuadStore, createNewMongoGraph)
|
||||
}
|
||||
|
||||
const DefaultDBName = "cayley"
|
||||
const QuadStoreType = "mongo"
|
||||
|
||||
func init() {
|
||||
graph.RegisterQuadStore(QuadStoreType, true, newQuadStore, createNewMongoGraph, nil)
|
||||
}
|
||||
|
||||
var (
|
||||
hashPool = sync.Pool{
|
||||
|
|
@ -366,3 +367,7 @@ func (qs *QuadStore) QuadDirection(in graph.Value, d quad.Direction) graph.Value
|
|||
}
|
||||
|
||||
// TODO(barakmich): Rewrite bulk loader. For now, iterating around blocks is the way we'll go about it.
|
||||
|
||||
func (qs *QuadStore) GetType() string {
|
||||
return QuadStoreType
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,6 +95,10 @@ type QuadStore interface {
|
|||
// qs.ValueOf(qs.Quad(id).Get(dir))
|
||||
//
|
||||
QuadDirection(id Value, d quad.Direction) Value
|
||||
|
||||
// Get the type of QuadStore
|
||||
//TODO replace this using reflection
|
||||
GetType() string
|
||||
}
|
||||
|
||||
type Options map[string]interface{}
|
||||
|
|
@ -146,23 +150,26 @@ type BulkLoader interface {
|
|||
|
||||
type NewStoreFunc func(string, Options) (QuadStore, error)
|
||||
type InitStoreFunc func(string, Options) error
|
||||
type NewStoreForRequestFunc func(QuadStore, Options) (QuadStore, error)
|
||||
|
||||
type register struct {
|
||||
newFunc NewStoreFunc
|
||||
initFunc InitStoreFunc
|
||||
isPersistent bool
|
||||
newFunc NewStoreFunc
|
||||
newForRequestFunc NewStoreForRequestFunc
|
||||
initFunc InitStoreFunc
|
||||
isPersistent bool
|
||||
}
|
||||
|
||||
var storeRegistry = make(map[string]register)
|
||||
|
||||
func RegisterQuadStore(name string, persists bool, newFunc NewStoreFunc, initFunc InitStoreFunc) {
|
||||
func RegisterQuadStore(name string, persists bool, newFunc NewStoreFunc, initFunc InitStoreFunc, newForRequestFunc NewStoreForRequestFunc) {
|
||||
if _, found := storeRegistry[name]; found {
|
||||
panic("already registered QuadStore " + name)
|
||||
}
|
||||
storeRegistry[name] = register{
|
||||
newFunc: newFunc,
|
||||
initFunc: initFunc,
|
||||
isPersistent: persists,
|
||||
newFunc: newFunc,
|
||||
initFunc: initFunc,
|
||||
newForRequestFunc: newForRequestFunc,
|
||||
isPersistent: persists,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -182,6 +189,14 @@ func InitQuadStore(name, dbpath string, opts Options) error {
|
|||
return errors.New("quadstore: name '" + name + "' is not registered")
|
||||
}
|
||||
|
||||
func NewQuadStoreForRequest(qs QuadStore, opts Options) (QuadStore, error) {
|
||||
r, registered := storeRegistry[qs.GetType()]
|
||||
if registered {
|
||||
return r.newForRequestFunc(qs, opts)
|
||||
}
|
||||
return nil, errors.New("QuadStore does not support Per Request construction, check config")
|
||||
}
|
||||
|
||||
func IsPersistent(name string) bool {
|
||||
return storeRegistry[name].isPersistent
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue