Skip to content

Commit

Permalink
Don't build rocksdb_property_int/rocksdb_property_int_cf on windo…
Browse files Browse the repository at this point in the history
…ws (#105)
  • Loading branch information
yihuang authored Feb 22, 2023
1 parent c84f5c7 commit b61261a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 21 deletions.
18 changes: 0 additions & 18 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -1235,24 +1235,6 @@ func (db *DB) GetPropertyCF(propName string, cf *ColumnFamilyHandle) (value stri
return
}

// GetIntProperty similar to `GetProperty`, but only works for a subset of properties whose
// return value is an integer. Return the value by integer.
func (db *DB) GetIntProperty(propName string) (value uint64, success bool) {
cProp := C.CString(propName)
success = C.rocksdb_property_int(db.c, cProp, (*C.uint64_t)(&value)) == 0
C.free(unsafe.Pointer(cProp))
return
}

// GetIntPropertyCF similar to `GetProperty`, but only works for a subset of properties whose
// return value is an integer. Return the value by integer.
func (db *DB) GetIntPropertyCF(propName string, cf *ColumnFamilyHandle) (value uint64, success bool) {
cProp := C.CString(propName)
success = C.rocksdb_property_int_cf(db.c, cf.c, cProp, (*C.uint64_t)(&value)) == 0
C.free(unsafe.Pointer(cProp))
return
}

// CreateColumnFamily create a new column family.
func (db *DB) CreateColumnFamily(opts *Options, name string) (handle *ColumnFamilyHandle, err error) {
var (
Expand Down
3 changes: 0 additions & 3 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ func TestOpenDb(t *testing.T) {
db := newTestDB(t, nil)
defer db.Close()
require.EqualValues(t, "0", db.GetProperty("rocksdb.num-immutable-mem-table"))
v, success := db.GetIntProperty("rocksdb.num-immutable-mem-table")
require.EqualValues(t, uint64(0), v)
require.True(t, success)
}

func TestDBCRUD(t *testing.T) {
Expand Down
28 changes: 28 additions & 0 deletions db_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//go:build !windows
// +build !windows

package grocksdb

// #include <stdlib.h>
// #include "rocksdb/c.h"
import "C"

import "unsafe"

// GetIntProperty similar to `GetProperty`, but only works for a subset of properties whose
// return value is an integer. Return the value by integer.
func (db *DB) GetIntProperty(propName string) (value uint64, success bool) {
cProp := C.CString(propName)
success = C.rocksdb_property_int(db.c, cProp, (*C.uint64_t)(&value)) == 0
C.free(unsafe.Pointer(cProp))
return
}

// GetIntPropertyCF similar to `GetProperty`, but only works for a subset of properties whose
// return value is an integer. Return the value by integer.
func (db *DB) GetIntPropertyCF(propName string, cf *ColumnFamilyHandle) (value uint64, success bool) {
cProp := C.CString(propName)
success = C.rocksdb_property_int_cf(db.c, cf.c, cProp, (*C.uint64_t)(&value)) == 0
C.free(unsafe.Pointer(cProp))
return
}
19 changes: 19 additions & 0 deletions db_unix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//go:build !windows
// +build !windows

package grocksdb

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestOpenDbUnix(t *testing.T) {
db := newTestDB(t, nil)
defer db.Close()
require.EqualValues(t, "0", db.GetProperty("rocksdb.num-immutable-mem-table"))
v, success := db.GetIntProperty("rocksdb.num-immutable-mem-table")
require.EqualValues(t, uint64(0), v)
require.True(t, success)
}

0 comments on commit b61261a

Please sign in to comment.