Code Monkey home page Code Monkey logo

gomdb's Introduction

Archiveing

This project is not actively maintianed anymore. Please look for its forks or alternative implementations for better supported version.

gomdb

Go wrapper for OpenLDAP Lightning Memory-Mapped Database (LMDB). Read more about LMDB here: http://symas.com/mdb/

GoDoc available here: http://godoc.org/github.com/szferi/gomdb

Build

go get github.com/szferi/gomdb

There is no dependency on LMDB dynamic library.

On FreeBSD 10, you must explicitly set CC (otherwise it will fail with a cryptic error), for example:

CC=clang go test -v

TODO

  • write more documentation
  • write more unit test
  • benchmark
  • figure out how can you write go binding for MDB_comp_func and MDB_rel_func
  • Handle go *Cursor close with txn.Commit and txn.Abort transparently

gomdb's People

Contributors

a-kr avatar benbjohnson avatar bmatsuo avatar burke avatar dinedal avatar docsavage avatar hyc avatar jvshahid avatar maximelenoir avatar mdennebaum avatar szferi avatar thehydroimpulse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

gomdb's Issues

Is it possible to use embedding of mdb C files rather than using shared library?

I forked your repo to DocSavage/gomdb and put what I think are the necessary mdb files in a src/ directory. Since the code base is fairly small and pure C, I thought it would allow static linking and a simple exe.

Unfortunately, I'm getting the following:

# github.com/DocSavage/gomdb
In file included from ./env.go:10:
./src/mdb.c:8404:46: warning: data argument not used by format string [-Wformat-extra-args]
/usr/include/secure/_stdio.h:47:56: note: expanded from macro 'sprintf'
# github.com/DocSavage/gomdb
./txn.go:58: cannot use env._env (type *_Ctype_MDB_env) as type *[0]byte in function argument

The issue with txn.go doesn't make sense but this is my first time doing cgo bindings. It looks like it's properly declared. Not sure where the *[0]byte signature is coming from. Any suggestions?

Fails to compile on freebsd

Hi,

gomd is a dependency of influxdb and I was unable to compile it on freebsd 10.

./gomdb/mdb.c:4300:39: error: use of undeclared identifier 'O_DSYNC'
../gomdb/mdb.c:282:20: note: expanded from macro 'MDB_DSYNC'
../gomdb/mdb.c:8584:46: warning: data argument not used by format string [-Wformat-extra-args]

O_DSYNC is not defined under FreeBSD according to my friend Google. I am not familar with C/C++ code, hence I didn't submit a pull request, but the following snippet seems to fix it for me.

#ifndef MDB_DSYNC
#ifdef O_DSYNC
# define MDB_DSYNC  O_DSYNC
#else
# define MDB_DSYNC      O_SYNC
#endif

Again, I have no idea what I'm doing - but this worked for me. Was that the right thing to do?

Clang Error: '-fno-eliminate-unused-debug-types'

After building LMDB from openldap/libraries/liblmdb and settingd LD path LD_LIBRARY_PATH=/usr/local/lib I get a compilation error on Mac OSX 10.9 (Mavericks).

A simple go get github.com/szferi/gomdb will yield

# github.com/szferi/gomdb
clang: error: argument unused during compilation: '-fno-eliminate-unused-debug-types'

GCC Version

gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
gcc-42 --version                                                                                                         
i686-apple-darwin11-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)

Tests broken by #206e1af

Commit #206e1af broke the tests:

# github.com/szferi/gomdb
./bench_test.go:159: not enough arguments in call to cur.Get
./bench_test.go:210: not enough arguments in call to cur.GetVal
./example_test.go:46: not enough arguments in call to cursor.Get
./mdb_test.go:85: not enough arguments in call to cursor.Get
FAIL    github.com/szferi/gomdb [build failed]

Update lmdb to 0.9.17

Are there any plans to upgrade the lmdb implementation to 0.9.17 or is this project essentially frozen?

Usage example

Hi, I'd be very interested in using this implementation of lmdb, and I was wondering if you could paste a usage example in the README at least.

panic: runtime error: cgo argument has Go pointer to Go pointer

[root@localhost gomdb]# go version
go version go1.8 linux/amd64

[root@localhost gomdb]# go test -bench .
--- FAIL: TestTest1 (0.00s)
panic: runtime error: cgo argument has Go pointer to Go pointer [recovered]
	panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 23 [running, locked to thread]:
testing.tRunner.func1(0xc4200789c0)
	/usr/local/go/src/testing/testing.go:622 +0x29d
panic(0x543e00, 0xc420070f80)
	/usr/local/go/src/runtime/panic.go:489 +0x2cf
github.com/szferi/gomdb.(*Txn).Put.func1(0x217ce960, 0xc400000001, 0xc420070f60, 0xc420070f70, 0xc400000010, 0x5)
	/home/go-project/src/github.com/szferi/gomdb/txn.go:149 +0x8b
github.com/szferi/gomdb.(*Txn).Put(0xc4200820d8, 0x1, 0xc420070f50, 0x5, 0x8, 0xc420070f58, 0x5, 0x8, 0x10, 0x0, ...)
	/home/go-project/src/github.com/szferi/gomdb/txn.go:149 +0xf7
github.com/szferi/gomdb.TestTest1(0xc4200789c0)
	/home/go-project/src/github.com/szferi/gomdb/mdb_test.go:52 +0x7ec
testing.tRunner(0xc4200789c0, 0x572d90)
	/usr/local/go/src/testing/testing.go:657 +0x96
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:697 +0x2ca
exit status 2
FAIL	github.com/szferi/gomdb	0.006s

mdb_env_info has no error cases

The MDB library does not define errors for mdb_env_info, but Env.Info() returns an error. This is overly pedantic. Env.Info() should return just the Info type.

edit: I see that the function can return EINVAL when either pointer passed is nil. But that's be an acceptable place to panic in these binding, imo. The *Info pointer will never be nil. And calling methods on nil values is not a common practice in Go. Though it does work... I don't call things on nil values unless the documentation says it's ok.

GetGo and PutGo should be removed

these functions don't really seem to fit in the package. they are somewhat high-level for an otherwise low-level api. and, really, no one uses gob in practice (afaik).

would you mind if i opened a pull request to remove them?

go build errors - android

root@aa685bdc1a0f:/gopath/src/github.com/szferi/gomdb# go build

github.com/szferi/gomdb

./mdb.c: In function 'mdb_env_open':
./mdb.c:4481:39: error: 'O_DSYNC' undeclared (first use in this function)
./mdb.c:4481:39: note: each undeclared identifier is reported only once for each
./mdb.c: In function 'mdb_env_copyfd1':
./mdb.c:8497:2: warning: implicit declaration of function 'posix_memalign' [-Wim
root@aa685bdc1a0f:/gopath/src/github.com/szferi/gomdb#

GOARCH =arm
GOOS=android

Build Warnings - Mac OS X

FYI, I'm getting these build warnings on Mac OS 10.9.4, go version 1.3.1:

github.com/szferi/gomdb/mdb.c:5862:9: warning: variable 'rc' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
github.com/szferi/gomdb/mdb.c:5888:9: note: uninitialized use occurs here
github.com/szferi/gomdb/mdb.c:5862:5: note: remove the 'if' if its condition is always true
github.com/szferi/gomdb/mdb.c:5721:10: note: initialize the variable 'rc' to silence this warning
github.com/szferi/gomdb/mdb.c:9260:46: warning: data argument not used by format string [-Wformat-extra-args]

The warnings don't seem serious, but is this something we should consider fixing in mdb.c and pushing upstream to MDB's maintainer?

Ineffective thread locking.

The usage of runtime.LockOSThread() and runtime.UnlockOSThread() seems incorrect to me.

Child transactions will unlock their parents on Commit or Abort. Dealing with this is fairly trivial except maybe in the case of Cursor.Txn, where it seem to get only slightly more tricky.

The bigger problem in my opinion seems to be that there's nothing preventing usage of the transaction, or its cursors, inside another goroutine which, due to thread locking, is guaranteed by the Go runtime to execute on another OS thread.

I see two ways to deal with these problems.

  • Fix the problem with child transactions and place warning in godoc stating that write transactions (those without mdb.RDONLY) absolutely must not be used in any goroutine other than the one that created it. (edit: pull request #31)
  • Abstract this problem away by creating a new, locked goroutine in Env.BeginTxn and serialize all operations through it via channels. This would include serializing cursor creation and use through the same goroutine. Because MDB_NOTLS is used this would only be required for write transactions.

The latter option will introduce some overhead into write transactions. But I'm starting to think it's the only sane way to use MDB in Go.

Do you have any thoughts on this @szferi? I've spent a good amount of time looking into this but wouldn't be surprised if I've misinterpreted the rather spartan C docs. So please validate my conclusions yourself.

MDB_NOTFOUND error

Hello, in my PoC trying to using the gomdb as system of persistence in memory, it's generated a error "MDB_NOTFOUND: No matching key/data pair found"

  1. The data are loading in memory through gomdb
  2. in the main.go is created the instance the "env *mdb.Env", other component(package) is invoked to load data through method with param "env"
  3. the load data is successful.
  4. when the service REST is invoked, try to search the information in memory through the instance "env (gomdb)" and generates the error.
  5. In the service is created a TRX and DBI instance, open one Cursor and use the method Get " _, bval, err := cursor.Get([]byte("H0"), mdb.SET_KEY)) "

//
txn, err := env.BeginTxn(nil, 0)
if err != nil {
fmt.Printf("Cannot begin transaction: %s", err)
}
var dbi mdb.DBI
dbi, err = txn.DBIOpen(nil, 0)
defer env.DBIClose(dbi)

Can you tell me about is generated this error or one example to use different to the test_case in the project

Build error

[gnewton@chekov]$ go get github.com/szferi/gomdb

github.com/szferi/gomdb

txn.go:146[/tmp/go-build877661856/github.com/szferi/gomdb/_obj/txn.cgo1.go:166]: val redeclared in this block
previous declaration at txn.go:138[/tmp/go-build877661856/github.com/szferi/gomdb/_obj/txn.cgo1.go:158]
[gnewton@chekov]$

Fixed doing the following (changed 'val' to 'bval' from line that was previously: var val []byte:

func (txn *Txn) GetGo(dbi DBI, key, val interface{}) error {
var key_buffer bytes.Buffer
encoder := gob.NewEncoder(&key_buffer)
err := encoder.Encode(key)
if err != nil {
return err
}
gkey := key_buffer.Bytes()
var bval []byte
bval, err = txn.Get(dbi, gkey)
if err != nil {
return err
}
val_buffer := bytes.NewReader(bval)
decoder := gob.NewDecoder(val_buffer)
err = decoder.Decode(bval)
if err != nil {
return err
}
return nil
}

Builds and all tests pass with this change.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.