本文整理汇总了Golang中github.com/syndtr/goleveldb/leveldb/opt.Options类的典型用法代码示例。如果您正苦于以下问题:Golang Options类的具体用法?Golang Options怎么用?Golang Options使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Options类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewLevelDBStorage
// 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: truno
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)
}()
}
}
示例3: setOptions
func (s *session) setOptions(o *opt.Options) {
no := dupOptions(o)
// Alternative filters.
if filters := o.GetAltFilters(); len(filters) > 0 {
no.AltFilters = make([]filter.Filter, len(filters))
for i, filter := range filters {
no.AltFilters[i] = &iFilter{filter}
}
}
// Block cache.
switch o.GetBlockCache() {
case nil:
no.BlockCache = cache.NewLRUCache(o.GetBlockCacheSize())
case opt.NoCache:
no.BlockCache = nil
}
// Comparer.
s.icmp = &iComparer{o.GetComparer()}
no.Comparer = s.icmp
// Filter.
if filter := o.GetFilter(); filter != nil {
no.Filter = &iFilter{filter}
}
s.o = &cachedOptions{Options: no}
s.o.cache()
}
示例4: newSession
func newSession(d storage.Storage, o *opt.Options) *session {
s := new(session)
s.stor = d
s.cmp = &iComparer{o.GetComparer()}
s.o = newIOptions(s, *o)
s.tops = newTableOps(s, s.o.GetMaxOpenFiles())
s.setVersion(&version{s: s})
return s
}
示例5: createLevelDbOptions
func (self *leveldbProvider) createLevelDbOptions(typeName string) *opt.Options {
comparer := self.typeName2Comparer[typeName]
if comparer == nil {
return nil
} else {
options := new(opt.Options)
options.Comparer = comparer
return options
}
}
示例6: OpenFile
// OpenFile opens or creates a DB for the given path.
// The DB will be created if not exist, unless ErrorIfMissing is true.
// Also, if ErrorIfExist is true and the DB exist OpenFile will returns
// os.ErrExist error.
//
// OpenFile uses standard file-system backed storage implementation as
// desribed in the leveldb/storage package.
//
// OpenFile will return an error with type of ErrCorrupted if corruption
// detected in the DB. Corrupted DB can be recovered with Recover
// function.
//
// The returned DB instance is goroutine-safe.
// The DB must be closed after use, by calling Close method.
func OpenFile(path string, o *opt.Options) (db *DB, err error) {
stor, err := storage.OpenFile(path, o.GetReadOnly())
if err != nil {
return
}
db, err = Open(stor, o)
if err != nil {
stor.Close()
} else {
db.closer = stor
}
return
}
示例7: newSession
func newSession(d desc.Desc, o *opt.Options) *session {
s := new(session)
s.desc = d
s.o = &iOptions{s, o}
s.cmp = &iComparer{o.GetComparer()}
filter := o.GetFilter()
if filter != nil {
s.filter = &iFilter{filter}
}
s.tops = newTableOps(s, s.o.GetMaxOpenFiles())
s.setVersion(&version{s: s})
return s
}
示例8: setOptions
func (s *session) setOptions(o *opt.Options) {
s.o = &opt.Options{}
if o != nil {
*s.o = *o
}
// Alternative filters.
if filters := o.GetAltFilters(); len(filters) > 0 {
s.o.AltFilters = make([]filter.Filter, len(filters))
for i, filter := range filters {
s.o.AltFilters[i] = &iFilter{filter}
}
}
// Block cache.
switch o.GetBlockCache() {
case nil:
s.o.BlockCache = cache.NewLRUCache(opt.DefaultBlockCacheSize)
case opt.NoCache:
s.o.BlockCache = nil
}
// Comparer.
s.cmp = &iComparer{o.GetComparer()}
s.o.Comparer = s.cmp
// Filter.
if filter := o.GetFilter(); filter != nil {
s.o.Filter = &iFilter{filter}
}
}
示例9: Open
// Open open or create database from given desc.
func Open(d desc.Desc, o *opt.Options) (db *DB, err error) {
s := newSession(d, o)
err = s.recover()
if os.IsNotExist(err) && o.HasFlag(opt.OFCreateIfMissing) {
err = s.create()
} else if err == nil && o.HasFlag(opt.OFErrorIfExist) {
err = os.ErrExist
}
if err != nil {
return
}
return open(s)
}
示例10: openSession
func openSession(stor storage.Storage, o *opt.Options) (s *session, err error) {
if stor == nil || o == nil {
return nil, os.ErrInvalid
}
storLock, err := stor.Lock()
if err != nil {
return
}
s = new(session)
s.stor = stor
s.storLock = storLock
s.cmp = &iComparer{o.GetComparer()}
s.o = newIOptions(s, *o)
s.tops = newTableOps(s, s.o.GetMaxOpenFiles())
s.setVersion(&version{s: s})
return
}
示例11: newSession
// Creates new initialized session instance.
func newSession(stor storage.Storage, o *opt.Options) (s *session, err error) {
if stor == nil {
return nil, os.ErrInvalid
}
storLock, err := stor.Lock()
if err != nil {
return
}
s = &session{
stor: stor,
storLock: storLock,
stCompPtrs: make([]iKey, o.GetNumLevel()),
}
s.setOptions(o)
s.tops = newTableOps(s, s.o.GetCachedOpenFiles())
s.setVersion(newVersion(s))
s.log("[email protected] F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed")
return
}
示例12: open
func (self *Queue) open() error {
self.Lock()
defer self.Unlock()
if regexp.MustCompile(`[^a-zA-Z0-9_]+`).MatchString(self.Name) {
return errors.New("Queue name is not alphanumeric")
}
if len(self.Name) > 100 {
return errors.New("Queue name is too long")
}
var options opt.Options
options.BlockCacher = opt.NoCacher
var err error
self.db, err = leveldb.OpenFile(self.Path(), &options)
if err != nil {
return err
}
self.isOpened = true
return self.initialize()
}
示例13: NewWriter
// NewWriter creates a new initialized table writer for the file.
//
// Table writer is not safe for concurrent use.
func NewWriter(f io.Writer, o *opt.Options) *Writer {
w := &Writer{
writer: f,
cmp: o.GetComparer(),
filter: o.GetFilter(),
compression: o.GetCompression(),
blockSize: o.GetBlockSize(),
comparerScratch: make([]byte, 0),
}
// data block
w.dataBlock.restartInterval = o.GetBlockRestartInterval()
// The first 20-bytes are used for encoding block handle.
w.dataBlock.scratch = w.scratch[20:]
// index block
w.indexBlock.restartInterval = 1
w.indexBlock.scratch = w.scratch[20:]
// filter block
if w.filter != nil {
w.filterBlock.generator = w.filter.NewGenerator()
w.filterBlock.flush(0)
}
return w
}
示例14: applyConfig
func applyConfig(o *opt.Options, config map[string]interface{}) (
*opt.Options, error) {
ro, ok := config["read_only"].(bool)
if ok {
o.ReadOnly = ro
}
cim, ok := config["create_if_missing"].(bool)
if ok {
o.ErrorIfMissing = !cim
}
eie, ok := config["error_if_exists"].(bool)
if ok {
o.ErrorIfExist = eie
}
wbs, ok := config["write_buffer_size"].(float64)
if ok {
o.WriteBuffer = int(wbs)
}
bs, ok := config["block_size"].(float64)
if ok {
o.BlockSize = int(bs)
}
bri, ok := config["block_restart_interval"].(float64)
if ok {
o.BlockRestartInterval = int(bri)
}
lcc, ok := config["lru_cache_capacity"].(float64)
if ok {
o.BlockCacheCapacity = int(lcc)
}
bfbpk, ok := config["bloom_filter_bits_per_key"].(float64)
if ok {
bf := filter.NewBloomFilter(int(bfbpk))
o.Filter = bf
}
return o, nil
}
示例15: setOptions
func (s *session) setOptions(o *opt.Options) {
no := dupOptions(o)
// Alternative filters.
if filters := o.GetAltFilters(); len(filters) > 0 {
no.AltFilters = make([]filter.Filter, len(filters))
for i, filter := range filters {
no.AltFilters[i] = &iFilter{filter}
}
}
// Comparer.
s.icmp = &iComparer{o.GetComparer()}
no.Comparer = s.icmp
// Filter.
if filter := o.GetFilter(); filter != nil {
no.Filter = &iFilter{filter}
}
s.o = &cachedOptions{Options: no}
s.o.cache()
}