Esempio n. 1
0
func (db *DB) initOptions(cfg *config.LevelDBConfig) {
	opts := NewOptions()

	opts.SetCreateIfMissing(true)

	cfg.Adjust()

	db.cache = NewLRUCache(cfg.CacheSize)
	opts.SetCache(db.cache)

	//we must use bloomfilter
	db.filter = NewBloomFilter(defaultFilterBits)
	opts.SetFilterPolicy(db.filter)

	if !cfg.Compression {
		opts.SetCompression(NoCompression)
	} else {
		opts.SetCompression(SnappyCompression)
	}

	opts.SetBlockSize(cfg.BlockSize)

	opts.SetWriteBufferSize(cfg.WriteBufferSize)

	opts.SetMaxOpenFiles(cfg.MaxOpenFiles)

	db.opts = opts

	db.readOpts = NewReadOptions()
	db.writeOpts = NewWriteOptions()

	db.iteratorOpts = NewReadOptions()
	db.iteratorOpts.SetFillCache(false)
}
Esempio n. 2
0
File: db.go Progetto: Abioy/ledisdb
func (db *DB) initOptions(cfg *config.LevelDBConfig) {
	opts := NewOptions()
	blockOpts := NewBlockBasedTableOptions()

	opts.SetCreateIfMissing(true)

	cfg.Adjust()

	db.env = NewDefaultEnv()
	db.env.SetBackgroundThreads(runtime.NumCPU() * 2)
	db.env.SetHighPriorityBackgroundThreads(1)
	opts.SetEnv(db.env)

	db.cache = NewLRUCache(cfg.CacheSize)
	blockOpts.SetCache(db.cache)

	//we must use bloomfilter
	db.filter = NewBloomFilter(defaultFilterBits)
	blockOpts.SetFilterPolicy(db.filter)

	if !cfg.Compression {
		opts.SetCompression(NoCompression)
	} else {
		opts.SetCompression(SnappyCompression)
	}

	blockOpts.SetBlockSize(cfg.BlockSize)

	opts.SetWriteBufferSize(cfg.WriteBufferSize)

	opts.SetMaxOpenFiles(cfg.MaxOpenFiles)

	opts.SetMaxBackgroundCompactions(runtime.NumCPU()*2 - 1)
	opts.SetMaxBackgroundFlushes(1)

	opts.SetLevel0SlowdownWritesTrigger(16)
	opts.SetLevel0StopWritesTrigger(64)
	opts.SetTargetFileSizeBase(32 * 1024 * 1024)

	opts.SetBlockBasedTableFactory(blockOpts)

	db.opts = opts
	db.blockOpts = blockOpts

	db.readOpts = NewReadOptions()
	db.writeOpts = NewWriteOptions()

	db.iteratorOpts = NewReadOptions()
	db.iteratorOpts.SetFillCache(false)
}
Esempio n. 3
0
func newOptions(cfg *config.LevelDBConfig) *opt.Options {
	opts := &opt.Options{}
	opts.ErrorIfMissing = false

	cfg.Adjust()

	opts.BlockCache = cache.NewLRUCache(cfg.CacheSize)

	//we must use bloomfilter
	opts.Filter = filter.NewBloomFilter(defaultFilterBits)

	if !cfg.Compression {
		opts.Compression = opt.NoCompression
	} else {
		opts.Compression = opt.SnappyCompression
	}

	opts.BlockSize = cfg.BlockSize
	opts.WriteBuffer = cfg.WriteBufferSize

	return opts
}