forked from yihuang/grocksdb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dbpath.go
51 lines (43 loc) · 1.22 KB
/
dbpath.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package grocksdb
// #include <stdlib.h>
// #include "rocksdb/c.h"
import "C"
import "unsafe"
// DBPath represents options for a dbpath.
type DBPath struct {
c *C.rocksdb_dbpath_t
}
// NewDBPath creates a DBPath object
// with the given path and target_size.
func NewDBPath(path string, targetSize uint64) (dbPath *DBPath) {
cpath := C.CString(path)
cDBPath := C.rocksdb_dbpath_create(cpath, C.uint64_t(targetSize))
dbPath = newNativeDBPath(cDBPath)
C.free(unsafe.Pointer(cpath))
return
}
// NewNativeDBPath creates a DBPath object.
func newNativeDBPath(c *C.rocksdb_dbpath_t) *DBPath {
return &DBPath{c: c}
}
// Destroy deallocates the DBPath object.
func (dbpath *DBPath) Destroy() {
C.rocksdb_dbpath_destroy(dbpath.c)
dbpath.c = nil
}
// NewDBPathsFromData creates a slice with allocated DBPath objects
// from paths and target_sizes.
func NewDBPathsFromData(paths []string, targetSizes []uint64) []*DBPath {
dbpaths := make([]*DBPath, len(paths))
for i, path := range paths {
targetSize := targetSizes[i]
dbpaths[i] = NewDBPath(path, targetSize)
}
return dbpaths
}
// DestroyDBPaths deallocates all DBPath objects in dbpaths.
func DestroyDBPaths(dbpaths []*DBPath) {
for _, dbpath := range dbpaths {
dbpath.Destroy()
}
}