mirror of https://github.com/etcd-io/bbolt.git
cleanup data and dataaz when unmapping db on Windows platform
Signed-off-by: Benjamin Wang <wachao@vmware.com>pull/362/head
parent
ad85400db2
commit
63d0cb428d
|
@ -107,8 +107,11 @@ func munmap(db *DB) error {
|
|||
}
|
||||
|
||||
addr := (uintptr)(unsafe.Pointer(&db.data[0]))
|
||||
var err1 error
|
||||
if err := syscall.UnmapViewOfFile(addr); err != nil {
|
||||
return os.NewSyscallError("UnmapViewOfFile", err)
|
||||
err1 = os.NewSyscallError("UnmapViewOfFile", err)
|
||||
}
|
||||
return nil
|
||||
db.data = nil
|
||||
db.datasz = 0
|
||||
return err1
|
||||
}
|
||||
|
|
25
db_test.go
25
db_test.go
|
@ -10,11 +10,13 @@ import (
|
|||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
bolt "go.etcd.io/bbolt"
|
||||
|
@ -1311,6 +1313,29 @@ func TestDB_BatchTime(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestDBUnmap verifes that `dataref`, `data` and `datasz` must be reset
|
||||
// to zero values respectively after unmapping the db.
|
||||
func TestDBUnmap(t *testing.T) {
|
||||
db := btesting.MustCreateDB(t)
|
||||
|
||||
require.NoError(t, db.DB.Close())
|
||||
|
||||
// Ignore the following error:
|
||||
// Error: copylocks: call of reflect.ValueOf copies lock value: go.etcd.io/bbolt.DB contains sync.Once contains sync.Mutex (govet)
|
||||
//nolint:govet
|
||||
v := reflect.ValueOf(*db.DB)
|
||||
dataref := v.FieldByName("dataref")
|
||||
data := v.FieldByName("data")
|
||||
datasz := v.FieldByName("datasz")
|
||||
assert.True(t, dataref.IsNil())
|
||||
assert.True(t, data.IsNil())
|
||||
assert.True(t, datasz.IsZero())
|
||||
|
||||
// We need to reopen the db, otherwise MustCheck may panic.
|
||||
db.DB = nil
|
||||
db.MustReopen()
|
||||
}
|
||||
|
||||
func ExampleDB_Update() {
|
||||
// Open the database.
|
||||
db, err := bolt.Open(tempfile(), 0666, nil)
|
||||
|
|
Loading…
Reference in New Issue