forked from linxGnu/grocksdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv.go
75 lines (62 loc) · 2.31 KB
/
env.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package grocksdb
// #include "rocksdb/c.h"
import "C"
// Env is a system call environment used by a database.
type Env struct {
c *C.rocksdb_env_t
}
// NewDefaultEnv creates a default environment.
func NewDefaultEnv() *Env {
return NewNativeEnv(C.rocksdb_create_default_env())
}
// NewMemEnv returns a new environment that stores its data in memory and delegates
// all non-file-storage tasks to base_env. The caller must delete the result
// when it is no longer needed.
// *base_env must remain live while the result is in use.
func NewMemEnv() *Env {
return NewNativeEnv(C.rocksdb_create_mem_env())
}
// NewNativeEnv creates a Environment object.
func NewNativeEnv(c *C.rocksdb_env_t) *Env {
return &Env{c}
}
// SetBackgroundThreads sets the number of background worker threads
// of a specific thread pool for this environment.
// 'LOW' is the default pool.
// Default: 1
func (env *Env) SetBackgroundThreads(n int) {
C.rocksdb_env_set_background_threads(env.c, C.int(n))
}
// SetHighPriorityBackgroundThreads sets the size of the high priority
// thread pool that can be used to prevent compactions from stalling
// memtable flushes.
func (env *Env) SetHighPriorityBackgroundThreads(n int) {
C.rocksdb_env_set_high_priority_background_threads(env.c, C.int(n))
}
// JoinAllThreads wait for all threads started by StartThread to terminate.
func (env *Env) JoinAllThreads() {
C.rocksdb_env_join_all_threads(env.c)
}
// LowerThreadPoolIOPriority lower IO priority for threads from the specified pool.
func (env *Env) LowerThreadPoolIOPriority() {
C.rocksdb_env_lower_thread_pool_io_priority(env.c)
}
// LowerHighPriorityThreadPoolIOPriority lower IO priority for high priority
// thread pool.
func (env *Env) LowerHighPriorityThreadPoolIOPriority() {
C.rocksdb_env_lower_high_priority_thread_pool_io_priority(env.c)
}
// LowerThreadPoolCPUPriority lower CPU priority for threads from the specified pool.
func (env *Env) LowerThreadPoolCPUPriority() {
C.rocksdb_env_lower_thread_pool_cpu_priority(env.c)
}
// LowerHighPriorityThreadPoolCPUPriority lower CPU priority for high priority
// thread pool.
func (env *Env) LowerHighPriorityThreadPoolCPUPriority() {
C.rocksdb_env_lower_high_priority_thread_pool_cpu_priority(env.c)
}
// Destroy deallocates the Env object.
func (env *Env) Destroy() {
C.rocksdb_env_destroy(env.c)
env.c = nil
}