Beispiel #1
0
func NewLeveldb() *Leveldb {
	env := levigo.NewDefaultEnv()
	options := levigo.NewOptions()

	// options.SetComparator(cmp)
	options.SetCreateIfMissing(true)
	options.SetErrorIfExists(false)
	// options.SetCache(cache)
	options.SetEnv(env)
	options.SetInfoLog(nil)
	options.SetWriteBufferSize(8 << 20)
	options.SetParanoidChecks(true)
	options.SetMaxOpenFiles(2000)
	options.SetBlockSize(4 * 1024)
	options.SetBlockRestartInterval(8)
	options.SetCompression(levigo.SnappyCompression)

	roptions := levigo.NewReadOptions()
	roptions.SetVerifyChecksums(true)
	roptions.SetFillCache(false)

	woptions := levigo.NewWriteOptions()
	woptions.SetSync(true)
	return &Leveldb{env,
		options,
		roptions,
		woptions,
		nil}
}
Beispiel #2
0
func NewLeveldb(name string) *Leveldb {
	options := levigo.NewOptions()

	// options.SetComparator(cmp)
	options.SetCreateIfMissing(true)
	options.SetErrorIfExists(false)

	// set env
	env := levigo.NewDefaultEnv()
	options.SetEnv(env)

	// set cache
	cache := levigo.NewLRUCache(16 << 20)
	options.SetCache(cache)

	options.SetInfoLog(nil)
	options.SetParanoidChecks(false)
	options.SetWriteBufferSize(128 << 20)
	options.SetMaxOpenFiles(2000)
	options.SetBlockSize(4 * 1024)
	options.SetBlockRestartInterval(16)
	options.SetCompression(levigo.SnappyCompression)

	// set filter
	filter := levigo.NewBloomFilter(10)
	options.SetFilterPolicy(filter)

	roptions := levigo.NewReadOptions()
	roptions.SetVerifyChecksums(false)
	roptions.SetFillCache(true)

	woptions := levigo.NewWriteOptions()
	// set sync false
	woptions.SetSync(false)

	db := &Leveldb{env,
		options,
		roptions,
		woptions,
		nil}
	if err := db.Open(name); err != nil {
		Panic("open db failed, err:%v", err)
	} else {
		Info("open db succeed, dbname:%v", name)
	}
	return db
}