MCPcopy
hub / github.com/dgraph-io/dgraph / InitStorage

Method InitStorage

worker/server_state.go:95–140  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

93}
94
95func (s *ServerState) InitStorage() {
96 var err error
97
98 if x.WorkerConfig.EncryptionKey != nil {
99 glog.Infof("Encryption feature enabled.")
100 }
101
102 {
103 // Write Ahead Log directory
104 x.Checkf(os.MkdirAll(Config.WALDir, 0700), "Error while creating WAL dir.")
105 s.WALstore, err = raftwal.InitEncrypted(Config.WALDir, x.WorkerConfig.EncryptionKey)
106 x.Check(err)
107 }
108 {
109 // Postings directory
110 // All the writes to posting store should be synchronous. We use batched writers
111 // for posting lists, so the cost of sync writes is amortized.
112 x.Check(os.MkdirAll(Config.PostingDir, 0700))
113 opt := x.WorkerConfig.Badger.
114 WithDir(Config.PostingDir).WithValueDir(Config.PostingDir).
115 WithNumVersionsToKeep(math.MaxInt32).
116 WithNamespaceOffset(x.NamespaceOffset)
117 opt = setBadgerOptions(opt)
118
119 // Print the options w/o exposing key.
120 // TODO: Build a stringify interface in Badger options, which is used to print nicely here.
121 key := opt.EncryptionKey
122 opt.EncryptionKey = nil
123 glog.Infof("Opening postings BadgerDB with options: %+v\n", opt)
124 opt.EncryptionKey = key
125
126 s.Pstore, err = badger.OpenManaged(opt)
127 x.Checkf(err, "Error while creating badger KV posting store")
128
129 // zero out from memory
130 opt.EncryptionKey = nil
131 }
132 // Temp directory
133 x.Check(os.MkdirAll(x.WorkerConfig.TmpDir, 0700))
134
135 s.gcCloser = z.NewCloser(3)
136 go x.RunVlogGC(s.Pstore, s.gcCloser)
137 // Commenting this out because Badger is doing its own cache checks.
138 go x.MonitorCacheHealth(s.Pstore, s.gcCloser)
139 go x.MonitorDiskMetrics("postings_fs", Config.PostingDir, s.gcCloser)
140}
141
142// Dispose stops and closes all the resources inside the server state.
143func (s *ServerState) Dispose() {

Callers 1

InitServerStateFunction · 0.80

Calls 8

CheckfFunction · 0.92
InitEncryptedFunction · 0.92
CheckFunction · 0.92
RunVlogGCFunction · 0.92
MonitorCacheHealthFunction · 0.92
MonitorDiskMetricsFunction · 0.92
setBadgerOptionsFunction · 0.85
InfofMethod · 0.80

Tested by

no test coverage detected