forked from dgraph-io/dgraph
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
164 lines (141 loc) · 4.56 KB
/
config.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* Copyright (C) 2017 Dgraph Labs, Inc. and Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package dgraph
import (
"expvar"
"path/filepath"
"github.com/dgraph-io/dgraph/posting"
"github.com/dgraph-io/dgraph/worker"
"github.com/dgraph-io/dgraph/x"
)
type Options struct {
PostingDir string
PostingTables string
WALDir string
Nomutations bool
AllottedMemory float64
CommitFraction float64
BaseWorkerPort int
ExportPath string
NumPendingProposals int
Tracing float64
GroupIds string
MyAddr string
PeerAddr string
RaftId uint64
MaxPendingCount uint64
ExpandEdge bool
InMemoryComm bool
ConfigFile string
DebugMode bool
}
// TODO(tzdybal) - remove global
var Config Options
var DefaultConfig = Options{
PostingDir: "p",
PostingTables: "loadtoram",
WALDir: "w",
Nomutations: false,
// User must specify this.
AllottedMemory: -1.0,
CommitFraction: 0.10,
BaseWorkerPort: 12345,
ExportPath: "export",
NumPendingProposals: 2000,
Tracing: 0.0,
GroupIds: "0,1",
MyAddr: "",
PeerAddr: "",
RaftId: 1,
MaxPendingCount: 1000,
ExpandEdge: true,
InMemoryComm: false,
ConfigFile: "",
DebugMode: false,
}
// Sometimes users use config.yaml flag so /debug/vars doesn't have information about the
// value of the flags. Hence we dump conf options we care about to the conf map.
func setConfVar(conf Options) {
newStr := func(s string) *expvar.String {
v := new(expvar.String)
v.Set(s)
return v
}
newFloat := func(f float64) *expvar.Float {
v := new(expvar.Float)
v.Set(f)
return v
}
newInt := func(i int) *expvar.Int {
v := new(expvar.Int)
v.Set(int64(i))
return v
}
// Expvar doesn't have bool type so we use an int.
newIntFromBool := func(b bool) *expvar.Int {
v := new(expvar.Int)
if b {
v.Set(1)
} else {
v.Set(0)
}
return v
}
x.Conf.Set("posting_dir", newStr(conf.PostingDir))
x.Conf.Set("posting_tables", newStr(conf.PostingTables))
x.Conf.Set("wal_dir", newStr(conf.WALDir))
x.Conf.Set("allotted_memory", newFloat(conf.AllottedMemory))
x.Conf.Set("commit_fraction", newFloat(conf.CommitFraction))
x.Conf.Set("tracing", newFloat(conf.Tracing))
x.Conf.Set("max_pending_count", newInt(int(conf.MaxPendingCount)))
x.Conf.Set("num_pending_proposals", newInt(conf.NumPendingProposals))
x.Conf.Set("expand_edge", newIntFromBool(conf.ExpandEdge))
}
func SetConfiguration(newConfig Options) {
newConfig.validate()
setConfVar(newConfig)
Config = newConfig
posting.Config.Mu.Lock()
posting.Config.AllottedMemory = Config.AllottedMemory
posting.Config.Mu.Unlock()
posting.Config.CommitFraction = Config.CommitFraction
worker.Config.BaseWorkerPort = Config.BaseWorkerPort
worker.Config.ExportPath = Config.ExportPath
worker.Config.NumPendingProposals = Config.NumPendingProposals
worker.Config.Tracing = Config.Tracing
worker.Config.GroupIds = Config.GroupIds
worker.Config.MyAddr = Config.MyAddr
worker.Config.PeerAddr = Config.PeerAddr
worker.Config.RaftId = Config.RaftId
worker.Config.MaxPendingCount = Config.MaxPendingCount
worker.Config.ExpandEdge = Config.ExpandEdge
worker.Config.InMemoryComm = Config.InMemoryComm
x.Config.ConfigFile = Config.ConfigFile
x.Config.DebugMode = Config.DebugMode
}
const MinAllottedMemory = 1024.0
func (o *Options) validate() {
pd, err := filepath.Abs(o.PostingDir)
x.Check(err)
wd, err := filepath.Abs(o.WALDir)
x.Check(err)
x.AssertTruef(pd != wd, "Posting and WAL directory cannot be the same ('%s').", o.PostingDir)
x.AssertTruefNoTrace(o.AllottedMemory != DefaultConfig.AllottedMemory,
"Allotted memory (--memory_mb) must be specified, with value greater than 1024 MB")
x.AssertTruefNoTrace(o.AllottedMemory >= MinAllottedMemory,
"Allotted memory (--memory_mb) must be at least %.0f MB. Currently set to: %f", MinAllottedMemory, o.AllottedMemory)
}