예제 #1
0
func newQuadStore(addr string, options graph.Options) (graph.QuadStore, error) {
	var qs QuadStore
	conn, err := connectSQLTables(addr, options)
	if err != nil {
		return nil, err
	}
	localOpt, localOptOk, err := options.BoolKey("local_optimize")
	if err != nil {
		return nil, err
	}
	qs.db = conn
	qs.sqlFlavor = "postgres"
	qs.size = -1
	qs.lru = newCache(1024)

	// Skip size checking by default.
	qs.noSizes = true
	if localOptOk {
		if localOpt {
			qs.noSizes = false
		}
	}
	qs.useEstimates, _, err = options.BoolKey("use_estimates")
	if err != nil {
		return nil, err
	}

	return &qs, nil
}
예제 #2
0
파일: quadstore.go 프로젝트: dennwc/cayley
func newQuadStore(path string, options graph.Options) (graph.QuadStore, error) {
	var qs QuadStore
	var err error
	db, err := bolt.Open(path, 0600, nil)
	if err != nil {
		glog.Errorln("Error, couldn't open! ", err)
		return nil, err
	}
	qs.db = db
	// BoolKey returns false on non-existence. IE, Sync by default.
	qs.db.NoSync, _, err = options.BoolKey("nosync")
	if err != nil {
		return nil, err
	}
	err = qs.getMetadata()
	if err == errNoBucket {
		return nil, errors.New("bolt: quadstore has not been initialised")
	} else if err != nil {
		return nil, err
	}
	if qs.version != latestDataVersion {
		return nil, errors.New("bolt: data version is out of date. Run cayleyupgrade for your config to update the data.")
	}
	return &qs, nil
}
예제 #3
0
파일: single.go 프로젝트: e4x/cayley
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
}
예제 #4
0
func newQuadStore(path string, options graph.Options) (graph.QuadStore, error) {
	var qs QuadStore
	var err error
	db, err := bolt.Open(path, 0600, nil)
	if err != nil {
		glog.Errorln("Error, couldn't open! ", err)
		return nil, err
	}
	qs.db = db
	// BoolKey returns false on non-existence. IE, Sync by default.
	qs.db.NoSync, _ = options.BoolKey("nosync")
	err = qs.getMetadata()
	if err != nil {
		return nil, err
	}
	return &qs, nil
}
예제 #5
0
func newQuadStore(path string, options graph.Options) (graph.QuadStore, error) {
	var qs QuadStore
	var err error
	db, err := bolt.Open(path, 0600, nil)
	if err != nil {
		glog.Errorln("Error, couldn't open! ", err)
		return nil, err
	}
	qs.db = db
	// BoolKey returns false on non-existence. IE, Sync by default.
	qs.db.NoSync, _, err = options.BoolKey("nosync")
	if err != nil {
		return nil, err
	}
	err = qs.getMetadata()
	if err == errNoBucket {
		panic("bolt: quadstore has not been initialised")
	} else if err != nil {
		return nil, err
	}
	return &qs, nil
}
예제 #6
0
파일: quadstore.go 프로젝트: bmatsuo/cayley
func createLMDB(path string, opt graph.Options) (env *lmdb.Env, err error) {
	err = os.Mkdir(path, 0700)
	if err != nil && !os.IsExist(err) {
		return nil, err
	}

	env, err = lmdb.NewEnv()
	if err != nil {
		return env, err
	}
	defer func() {
		if err != nil {
			env.Close()
			env = nil
		}
	}()

	maxreaders, _, err := opt.IntKey("maxreaders")
	if err != nil {
		return nil, err
	}
	if maxreaders > 0 {
		err = env.SetMaxReaders(maxreaders)
		if err != nil {
			return nil, err
		}
	}

	maxdbs, _, err := opt.IntKey("maxdbs")
	if err != nil {
		return nil, err
	}
	if maxdbs == 0 {
		maxdbs = 7
	}
	err = env.SetMaxDBs(maxdbs)
	if err != nil {
		return nil, err
	}

	mapsize, _, err := opt.IntKey("mapsize")
	if err != nil {
		return nil, err
	}
	err = env.SetMapSize(int64(mapsize))
	if err != nil {
		return nil, err
	}

	var flags uint
	dbnosync, _, err := opt.BoolKey("nosync")
	if err != nil {
		return nil, err
	}
	if dbnosync {
		flags |= lmdb.NoSync
	}
	err = env.Open(path, flags, 0600)
	if err != nil {
		return nil, err
	}

	return env, nil
}