示例#1
0
文件: ldb.go 项目: vburenin/firempq
// NewLevelDBStorage is a constructor of DataStorage.
func NewLevelDBStorage(cfg *conf.Config) (*LevelDBStorage, error) {
	ds := LevelDBStorage{
		cfg:            cfg,
		dbName:         cfg.DatabasePath,
		itemCache:      make(ItemCache),
		tmpItemCache:   make(ItemCache),
		closed:         false,
		forceFlushChan: make(chan bool, 1),
		flushSync:      &sync.WaitGroup{},
	}

	// LevelDB write options.
	opts := new(opt.Options)
	opts.Compression = opt.NoCompression
	opts.BlockCacheCapacity = 8 * 1024 * 1024
	opts.WriteBuffer = 8 * 1024 * 1024

	db, err := leveldb.OpenFile(cfg.DatabasePath, opts)
	if err != nil {
		return nil, err
	}
	ds.db = db
	go ds.periodicCacheFlush()
	return &ds, nil
}
示例#2
0
func truno(t *testing.T, o *opt.Options, f func(h *dbHarness)) {
	for i := 0; i < 4; i++ {
		func() {
			switch i {
			case 0:
			case 1:
				if o == nil {
					o = &opt.Options{Filter: _bloom_filter}
				} else {
					old := o
					o = &opt.Options{}
					*o = *old
					o.Filter = _bloom_filter
				}
			case 2:
				if o == nil {
					o = &opt.Options{Compression: opt.NoCompression}
				} else {
					old := o
					o = &opt.Options{}
					*o = *old
					o.Compression = opt.NoCompression
				}
			}
			h := newDbHarnessWopt(t, o)
			defer h.close()
			switch i {
			case 3:
				h.reopenDB()
			}
			f(h)
		}()
	}
}