func NewSingleReplication(qs graph.QuadStore, opts graph.Options) (graph.QuadWriter, error) { var ( ignoreMissing bool ignoreDuplicate bool err error ) if *graph.IgnoreMissing { ignoreMissing = true } else { ignoreMissing, _, err = opts.BoolKey("ignore_missing") if err != nil { return nil, err } } if *graph.IgnoreDup { ignoreDuplicate = true } else { ignoreDuplicate, _, err = opts.BoolKey("ignore_duplicate") if err != nil { return nil, err } } return &Single{ currentID: qs.Horizon(), qs: qs, ignoreOpts: graph.IgnoreOpts{ IgnoreDup: ignoreDuplicate, IgnoreMissing: ignoreMissing, }, }, nil }
func newQuadStore(addr string, options graph.Options) (graph.QuadStore, error) { var qs QuadStore conn, err := mgo.Dial(addr) if err != nil { return nil, err } conn.SetSafe(&mgo.Safe{}) dbName := DefaultDBName val, ok, err := options.StringKey("database_name") if err != nil { return nil, err } else if ok { dbName = val } qs.db = conn.DB(dbName) qs.session = conn qs.ids = newCache(1 << 16) qs.sizes = newCache(1 << 16) return &qs, nil }
func newQuadStore(path string, options graph.Options) (graph.QuadStore, error) { var qs QuadStore var err error qs.path = path cacheSize := DefaultCacheSize val, ok, err := options.IntKey("cache_size_mb") if err != nil { return nil, err } else if ok { cacheSize = val } qs.dbOpts = &opt.Options{ BlockCacheCapacity: cacheSize * opt.MiB, } qs.dbOpts.ErrorIfMissing = true writeBufferSize := DefaultWriteBufferSize val, ok, err = options.IntKey("writeBufferSize") if err != nil { return nil, err } else if ok { writeBufferSize = val } qs.dbOpts.WriteBuffer = writeBufferSize * opt.MiB qs.writeopts = &opt.WriteOptions{ Sync: false, } qs.readopts = &opt.ReadOptions{} db, err := leveldb.OpenFile(qs.path, qs.dbOpts) if err != nil { glog.Errorln("Error, could not open! ", err) return nil, err } qs.db = db glog.Infoln(qs.GetStats()) err = qs.getMetadata() if err != nil { return nil, err } return &qs, nil }
func createNewMongoGraph(addr string, options graph.Options) error { conn, err := mgo.Dial(addr) if err != nil { return err } conn.SetSafe(&mgo.Safe{}) dbName := DefaultDBName val, ok, err := options.StringKey("database_name") if err != nil { return err } else if ok { dbName = val } db := conn.DB(dbName) indexOpts := mgo.Index{ Key: []string{"subject"}, Unique: false, DropDups: false, Background: true, Sparse: true, } db.C("quads").EnsureIndex(indexOpts) indexOpts.Key = []string{"predicate"} db.C("quads").EnsureIndex(indexOpts) indexOpts.Key = []string{"object"} db.C("quads").EnsureIndex(indexOpts) indexOpts.Key = []string{"label"} db.C("quads").EnsureIndex(indexOpts) logOpts := mgo.Index{ Key: []string{"LogID"}, Unique: true, DropDups: false, Background: true, Sparse: true, } db.C("log").EnsureIndex(logOpts) return nil }