Skip to content

Commit

Permalink
Merge branch 'master' into e35_mdbx_v0_13
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov committed Dec 21, 2024
2 parents 1fde822 + a7f8428 commit 2529582
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
13 changes: 10 additions & 3 deletions mdbx/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ var (
LoggerDoNotChange = C.MDBX_LOGGER_DONTCHANGE
)

// Label - will be added to error messages. For better understanding - which DB has problem.
type Label string

const Default Label = "default"

// DBI is a handle for a database in an Env.
//
// See MDBX_dbi
Expand All @@ -124,7 +129,8 @@ type DBI C.MDBX_dbi
//
// See MDBX_env.
type Env struct {
_env *C.MDBX_env
_env *C.MDBX_env
label Label

// closeLock is used to allow the Txn finalizer to check if the Env has
// been closed, so that it may know if it must abort.
Expand All @@ -134,8 +140,8 @@ type Env struct {
// NewEnv allocates and initializes a new Env.
//
// See mdbx_env_create.
func NewEnv() (*Env, error) {
env := new(Env)
func NewEnv(label Label) (*Env, error) {
env := &Env{label: label}
ret := C.mdbx_env_create(&env._env)
if ret != success {
return nil, operrno("mdbx_env_create", ret)
Expand All @@ -153,6 +159,7 @@ func (env *Env) Open(path string, flags uint, mode os.FileMode) error {
ret := C.mdbx_env_open(env._env, cpath, C.MDBX_env_flags_t(NoTLS|flags), C.mdbx_mode_t(mode))
return operrno("mdbx_env_open", ret)
}
func (env *Env) Label() Label { return env.label }

var errNotOpen = errors.New("enivornment is not open")

Expand Down
10 changes: 5 additions & 5 deletions mdbx/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import (
//}

func TestEnv_Open_notExist(t *testing.T) {
env, err := NewEnv()
env, err := NewEnv(Default)
if err != nil {
t.Fatalf("create: %s", err)
}
Expand All @@ -59,7 +59,7 @@ func TestEnv_Open_notExist(t *testing.T) {
}

func TestEnv_Open(t *testing.T) {
env, err1 := NewEnv()
env, err1 := NewEnv(Default)
if err1 != nil {
t.Error(err1)
return
Expand Down Expand Up @@ -179,7 +179,7 @@ func TestEnv_Flags(t *testing.T) {
func TestEnv_SetMaxReader(t *testing.T) {
dir := t.TempDir()

env, err := NewEnv()
env, err := NewEnv(Default)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -218,7 +218,7 @@ func TestEnv_SetMaxReader(t *testing.T) {
}

func TestEnv_SetDebug(t *testing.T) {
env, err := NewEnv()
env, err := NewEnv(Default)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -518,7 +518,7 @@ func setup(t testing.TB) (*Env, string) {
}

func setupFlags(t testing.TB, flags uint) (env *Env, path string) {
env, err := NewEnv()
env, err := NewEnv(Default)
if err != nil {
t.Fatalf("env: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions mdbx/mdbx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func TestEmptyKeysAndValues(t *testing.T) {
env, err1 := NewEnv()
env, err1 := NewEnv(Default)
if err1 != nil {
t.Fatalf("Cannot create environment: %s", err1)
}
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestEmptyKeysAndValues(t *testing.T) {
}

func TestTest1(t *testing.T) {
env, err1 := NewEnv()
env, err1 := NewEnv(Default)
if err1 != nil {
t.Fatalf("Cannot create environment: %s", err1)
}
Expand Down
2 changes: 1 addition & 1 deletion mdbx/txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ func TestTxn_Flags(t *testing.T) {
env.Close()

// opening the database after it is created inherits the original flags.
env, err = NewEnv()
env, err = NewEnv(Default)
if err != nil {
t.Error(err)
return
Expand Down

0 comments on commit 2529582

Please sign in to comment.