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

Function New

pkg/topom/topom.go:82–124  ·  view source on GitHub ↗
(client models.Client, config *Config)

Source from the content-addressed store, hash-verified

80var ErrClosedTopom = errors.New("use of closed topom")
81
82func New(client models.Client, config *Config) (*Topom, error) {
83 if err := config.Validate(); err != nil {
84 return nil, errors.Trace(err)
85 }
86 if err := models.ValidateProduct(config.ProductName); err != nil {
87 return nil, errors.Trace(err)
88 }
89 s := &Topom{}
90 s.config = config
91 s.exit.C = make(chan struct{})
92 s.action.redisp = redis.NewPool(config.ProductAuth, config.MigrationTimeout.Duration())
93 s.action.progress.status.Store("")
94
95 s.ha.redisp = redis.NewPool("", time.Second*5)
96
97 s.model = &models.Topom{
98 StartTime: time.Now().String(),
99 }
100 s.model.ProductName = config.ProductName
101 s.model.Pid = os.Getpid()
102 s.model.Pwd, _ = os.Getwd()
103 if b, err := exec.Command("uname", "-a").Output(); err != nil {
104 log.WarnErrorf(err, "run command uname failed")
105 } else {
106 s.model.Sys = strings.TrimSpace(string(b))
107 }
108 s.store = models.NewStore(client, config.ProductName)
109
110 s.stats.redisp = redis.NewPool(config.ProductAuth, time.Second*5)
111 s.stats.servers = make(map[string]*RedisStats)
112 s.stats.proxies = make(map[string]*ProxyStats)
113
114 if err := s.setup(config); err != nil {
115 s.Close()
116 return nil, err
117 }
118
119 log.Warnf("create new topom:\n%s", s.model.Encode())
120
121 go s.serveAdmin()
122
123 return s, nil
124}
125
126func (s *Topom) setup(config *Config) error {
127 if l, err := net.Listen("tcp", config.AdminAddr); err != nil {

Callers 2

openTopomFunction · 0.70
TestTopomExclusiveFunction · 0.70

Calls 9

setupMethod · 0.95
CloseMethod · 0.95
serveAdminMethod · 0.95
DurationMethod · 0.80
WarnErrorfMethod · 0.80
WarnfMethod · 0.80
ValidateMethod · 0.45
StringMethod · 0.45
EncodeMethod · 0.45

Tested by 2

openTopomFunction · 0.56
TestTopomExclusiveFunction · 0.56