本文整理汇总了Golang中github.com/cznic/exp/lldb.Filer类的典型用法代码示例。如果您正苦于以下问题:Golang Filer类的具体用法?Golang Filer怎么用?Golang Filer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Filer类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: acidFiler
func (o *Options) acidFiler(db *DB, f lldb.Filer) (r lldb.Filer, err error) {
switch o._ACID {
default:
panic("internal error")
case _ACIDTransactions:
if r, err = lldb.NewRollbackFiler(
f,
func(sz int64) error {
return f.Truncate(sz)
},
f,
); err != nil {
return nil, err
}
return r, nil
case _ACIDFull:
if r, err = lldb.NewACIDFiler(f, o.wal); err != nil {
return nil, err
}
db.acidState = stIdle
db.gracePeriod = o._GracePeriod
if o._GracePeriod == 0 {
panic("internal error")
}
return r, nil
}
}
开发者ID:miffa,项目名称:kv,代码行数:29,代码来源:options.go
示例2: acidFiler
func (o *Options) acidFiler(db *DB, f lldb.Filer) (r lldb.Filer, err error) {
switch o.ACID {
default:
panic("internal error")
case ACIDNone:
r = f
case ACIDTransactions:
var rf *lldb.RollbackFiler
if rf, err = lldb.NewRollbackFiler(
f,
func(sz int64) error {
return f.Truncate(sz)
},
f,
); err != nil {
return
}
db.xact = true
r = rf
case ACIDFull:
if r, err = lldb.NewACIDFiler(f, o.wal); err != nil {
return
}
db.acidState = stIdle
db.gracePeriod = o.GracePeriod
db.xact = true
if o.GracePeriod == 0 {
db.acidState = stDisabled
break
}
// Ensure GOMAXPROCS > 1, required for ACID FSM
if n := runtime.GOMAXPROCS(0); n > 1 {
return
}
runtime.GOMAXPROCS(2)
}
return
}
开发者ID:pmezard,项目名称:exp,代码行数:42,代码来源:options.go
示例3: create
func create(f *os.File, filer lldb.Filer, opts *Options, isMem bool) (db *DB, err error) {
defer func() {
lock := opts.lock
if err != nil && lock != nil {
n := lock.Name()
lock.Close()
os.Remove(n)
db = nil
}
}()
if err = opts.check(filer.Name(), true, !isMem); err != nil {
return
}
b := [16]byte{byte(magic[0]), byte(magic[1]), byte(magic[2]), byte(magic[3]), 0x00} // ver 0x00
if n, err := filer.WriteAt(b[:], 0); n != 16 {
return nil, &os.PathError{Op: "dbm.Create.WriteAt", Path: filer.Name(), Err: err}
}
db = &DB{emptySize: 128, f: f, lock: opts.lock, closed: make(chan bool)}
if filer, err = opts.acidFiler(db, filer); err != nil {
return nil, err
}
db.filer = filer
if err = filer.BeginUpdate(); err != nil {
return
}
defer func() {
if e := filer.EndUpdate(); e != nil {
if err == nil {
err = e
}
}
}()
if db.alloc, err = lldb.NewAllocator(lldb.NewInnerFiler(filer, 16), &lldb.Options{}); err != nil {
return nil, &os.PathError{Op: "dbm.Create", Path: filer.Name(), Err: err}
}
db.alloc.Compress = compress
db.isMem = isMem
return db, db.boot()
}
开发者ID:pmezard,项目名称:exp,代码行数:47,代码来源:dbm.go
示例4: create
func create(f *os.File, filer lldb.Filer, opts *Options, isMem bool) (db *DB, err error) {
defer func() {
if db != nil {
db.opts = opts
}
}()
defer func() {
lock := opts.lock
if err != nil && lock != nil {
lock.Close()
db = nil
}
}()
if err = opts.check(filer.Name(), true, !isMem); err != nil {
return
}
b := [16]byte{byte(magic[0]), byte(magic[1]), byte(magic[2]), byte(magic[3]), 0x00} // ver 0x00
if n, err := filer.WriteAt(b[:], 0); n != 16 {
return nil, &os.PathError{Op: "kv.create.WriteAt", Path: filer.Name(), Err: err}
}
db = &DB{f: f, lock: opts.lock}
if filer, err = opts.acidFiler(db, filer); err != nil {
return nil, err
}
db.filer = filer
if err = filer.BeginUpdate(); err != nil {
return
}
defer func() {
if e := filer.EndUpdate(); e != nil {
if err == nil {
err = e
}
}
}()
if db.alloc, err = lldb.NewAllocator(lldb.NewInnerFiler(filer, 16), &lldb.Options{}); err != nil {
return nil, &os.PathError{Op: "kv.create", Path: filer.Name(), Err: err}
}
db.alloc.Compress = true
db.isMem = isMem
var h int64
if db.root, h, err = lldb.CreateBTree(db.alloc, opts.Compare); err != nil {
return
}
if h != 1 {
panic("internal error")
}
db.wal = opts.wal
return
}
开发者ID:mervin0502,项目名称:kv,代码行数:60,代码来源:kv.go
示例5: OpenFromFiler
// OpenFromFiler is like Open but it accepts an arbitrary backing storage
// provided by filer.
func OpenFromFiler(filer lldb.Filer, opts *Options) (db *DB, err error) {
opts = opts.clone()
opts._ACID = _ACIDFull
defer func() {
if db != nil {
db.opts = opts
}
}()
defer func() {
lock := opts.lock
if err != nil && lock != nil {
lock.Close()
db = nil
}
if err != nil {
if db != nil {
db.Close()
db = nil
}
}
}()
name := filer.Name()
if err = opts.check(name, false, true); err != nil {
return
}
sz, err := filer.Size()
if err != nil {
return
}
if sz%16 != 0 {
return nil, &os.PathError{Op: "kv.Open:", Path: name, Err: fmt.Errorf("file size %d(%#x) is not 0 (mod 16)", sz, sz)}
}
var b [16]byte
if n, err := filer.ReadAt(b[:], 0); n != 16 || err != nil {
return nil, &os.PathError{Op: "kv.Open.ReadAt", Path: name, Err: err}
}
var h header
if err = h.rd(b[:]); err != nil {
return nil, &os.PathError{Op: "kv.Open:validate header", Path: name, Err: err}
}
db = &DB{lock: opts.lock}
if filer, err = opts.acidFiler(db, filer); err != nil {
return nil, err
}
db.filer = filer
switch h.ver {
default:
return nil, &os.PathError{Op: "kv.Open", Path: name, Err: fmt.Errorf("unknown/unsupported kv file format version %#x", h.ver)}
case 0x00:
if _, err = open00(name, db); err != nil {
return nil, err
}
}
db.root, err = lldb.OpenBTree(db.alloc, opts.Compare, 1)
db.wal = opts.wal
if opts.VerifyDbAfterOpen {
err = verifyAllocator(db.alloc)
}
return
}
开发者ID:miffa,项目名称:kv,代码行数:70,代码来源:kv.go
注:本文中的github.com/cznic/exp/lldb.Filer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论