MCPcopy Index your code
hub / github.com/CodisLabs/codis / loadJsonConfigV3

Method loadJsonConfigV3

cmd/admin/admin.go:293–352  ·  view source on GitHub ↗
(file string)

Source from the content-addressed store, hash-verified

291}
292
293func (t *cmdAdmin) loadJsonConfigV3(file string) *ConfigV3 {
294 b, err := ioutil.ReadFile(file)
295 if err != nil {
296 log.PanicErrorf(err, "read file '%s' failed", file)
297 }
298
299 config := &ConfigV3{}
300 if err := json.Unmarshal(b, config); err != nil {
301 log.PanicErrorf(err, "json unmarshal failed")
302 }
303
304 var proxy = make(map[string]*models.Proxy)
305 for _, p := range config.Proxy {
306 if proxy[p.Token] != nil {
307 log.Panicf("proxy-%s already exists", p.Token)
308 }
309 proxy[p.Token] = p
310 }
311
312 var group = make(map[int]*models.Group)
313 var maddr = make(map[string]bool)
314 for _, g := range config.Group {
315 if g.Id <= 0 || g.Id > models.MaxGroupId {
316 log.Panicf("invalid group id = %d", g.Id)
317 }
318 if group[g.Id] != nil {
319 log.Panicf("group-%04d already exists", g.Id)
320 }
321 if g.Promoting.State != models.ActionNothing {
322 log.Panicf("gorup-%04d is promoting", g.Id)
323 }
324 for _, x := range g.Servers {
325 addr := x.Addr
326 if maddr[addr] {
327 log.Panicf("server %s already exists", addr)
328 }
329 maddr[addr] = true
330 }
331 group[g.Id] = g
332 }
333
334 var slots = make(map[int]*models.SlotMapping)
335 for _, s := range config.Slots {
336 if s.Id < 0 || s.Id >= models.MaxSlotNum {
337 log.Panicf("invalid slot id = %d", s.Id)
338 }
339 if slots[s.Id] != nil {
340 log.Panicf("slot-%04d already exists", s.Id)
341 }
342 if s.Action.State != models.ActionNothing {
343 log.Panicf("slot-%04d action is not empty", s.Id)
344 }
345 if g := group[s.GroupId]; g == nil || len(g.Servers) == 0 {
346 log.Panicf("slot-%04d with group-%04d doesn't exist or empty", s.Id, s.GroupId)
347 }
348 slots[s.Id] = s
349 }
350

Callers 1

handleConfigRestoreMethod · 0.95

Calls 2

PanicErrorfMethod · 0.80
PanicfMethod · 0.80

Tested by

no test coverage detected