2014-10-12 21:33
浏览 154


I have implemented the levigo wrapper in my project so I can use LevelDB. The declaration is fairly boilerplate, like so:

func NewLeveldbStorage(dbPath string) *leveldbStorage {
     opts := levigo.NewOptions()
     log.Debugf("Entering Open")
     db, err := levigo.Open(dbPath, opts); if err != nil {
         log.Fatal("BOOM %v", err)
     log.Debugf("Finished calling open")
     return &leveldbStorage{db:db}

Here is the struct returned:

type leveldbStorage struct {
     db *levigo.DB

I then made a few simple GET and STORE commands on the struct that essentially just use s.db.Get and s.db.Put. This works fine in my tests, but when I run the following benchmark:

 func BenchmarkLeviDbGet(b *testing.B) {
     s := storage.NewLeveldbStorage("/path/to/db")
     value := "value"
     uid,_ := s.Store(value)

     for i := 0; i < b.N; i++ {

This benchmark, when run, returns:

 2014/10/12 21:17:09 BOOM %vIO error: lock /path/to/db/LOCK: already held by process

Is there an appropriate way to use levigo/leveldb to enable multithreaded reading? What about writing? I would not be surprised if multithreaded writing is not possible, but multithreaded reading seems like it should be. What am I doing wrong here?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题