-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathconfig.go
102 lines (90 loc) · 3.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
/*
* Copyright 2017-2018 Dgraph Labs, Inc. and Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edgraph
import (
"fmt"
"path/filepath"
"time"
"github.com/dgraph-io/dgraph/posting"
"github.com/dgraph-io/dgraph/x"
)
const (
// AllowMutations is the mode allowing all mutations.
AllowMutations int = iota
// DisallowMutations is the mode that disallows all mutations.
DisallowMutations
// StrictMutations is the mode that allows mutations if and only if they contain known preds.
StrictMutations
)
// Options contains options for the Dgraph server.
type Options struct {
// PostingDir is the path to the directory storing the postings..
PostingDir string
// BadgerTables is the name of the mode used to load the badger tables.
BadgerTables string
// BadgerVlog is the name of the mode used to load the badger value log.
BadgerVlog string
// WALDir is the path to the directory storing the write-ahead log.
WALDir string
// MutationsMode is the mode used to handle mutation requests.
MutationsMode int
// AuthToken is the token to be passed for Alter HTTP requests.
AuthToken string
// AllottedMemory is the estimated size taken by the LRU cache.
AllottedMemory float64
// HmacSecret stores the secret used to sign JSON Web Tokens (JWT).
HmacSecret []byte
// AccessJwtTtl is the TTL for the access JWT.
AccessJwtTtl time.Duration
// RefreshJwtTtl is the TTL of the refresh JWT.
RefreshJwtTtl time.Duration
// AclRefreshInterval is the interval used to refresh the ACL cache.
AclRefreshInterval time.Duration
}
// Config holds an instance of the server options..
var Config Options
// String will generate the string output an Options struct without including
// the HmacSecret field, which prevents revealing the secret during logging
func (opt Options) String() string {
//return fmt.Sprintf()
return fmt.Sprintf("{PostingDir:%s BadgerTables:%s BadgerVlog:%s WALDir:%s MutationsMode:%d "+
"AuthToken:%s AllottedMemory:%.1fMB AccessJwtTtl:%v RefreshJwtTtl:%v "+
"AclRefreshInterval:%v}", opt.PostingDir, opt.BadgerTables, opt.BadgerVlog, opt.WALDir,
opt.MutationsMode, opt.AuthToken, opt.AllottedMemory, opt.AccessJwtTtl, opt.RefreshJwtTtl,
opt.AclRefreshInterval)
}
// SetConfiguration sets the server configuration to the given config.
func SetConfiguration(newConfig Options) {
newConfig.validate()
Config = newConfig
posting.Config.Mu.Lock()
posting.Config.AllottedMemory = Config.AllottedMemory
posting.Config.Mu.Unlock()
}
// MinAllottedMemory is the minimum amount of memory needed for the LRU cache.
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 != -1,
"LRU memory (--lru_mb) must be specified. (At least 1024 MB)")
x.AssertTruefNoTrace(o.AllottedMemory >= MinAllottedMemory,
"LRU memory (--lru_mb) must be at least %.0f MB. Currently set to: %f",
MinAllottedMemory, o.AllottedMemory)
}