Пример #1
0
func (top *Topology) Close(proxyName string) {
	// delete fence znode
	pi, err := models.GetProxyInfo(top.coordConn, top.ProductName, proxyName)
	if err != nil {
		log.Error("killing fence error, proxy %s is not exists", proxyName)
	} else {
		zkhelper.DeleteRecursive(top.coordConn, path.Join(models.GetProxyFencePath(top.ProductName), pi.Addr), -1)
	}
	// delete ephemeral znode
	zkhelper.DeleteRecursive(top.coordConn, path.Join(models.GetProxyPath(top.ProductName), proxyName), -1)
	top.coordConn.Close()
}
Пример #2
0
func (s *testAgentSuite) SetUpSuite(c *C) {
	// initial whole test environment
	configFile = "config.ini"
	resetAbsPath(&configFile)
	cfg, err := utils.InitConfigFromFile(configFile)
	c.Assert(err, IsNil)

	globalEnv = env.LoadRebornEnv(cfg)
	globalConn, err = globalEnv.NewCoordConn()
	c.Assert(err, IsNil)

	s.testSetExecPath(c)

	// remove all infos in coordinator first
	err = zkhelper.DeleteRecursive(globalConn, fmt.Sprintf("/zk/reborn/db_%s", globalEnv.ProductName()), -1)
	if err != nil && !zkhelper.ZkErrorEqual(err, zk.ErrNoNode) {
		c.Assert(err, IsNil)
	}

	s.agentDashboard = s.testStartAgent(c, "127.0.0.1:39001", false)
	s.agentProxy = s.testStartAgent(c, "127.0.0.1:39002", false)
	s.agentStoreMaster = s.testStartAgent(c, "127.0.0.1:39003", false)
	s.agentStoreSlave = s.testStartAgent(c, "127.0.0.1:39004", false)

	s.testDashboard(c)

	s.testInitGroup(c)
	s.testInitSlots(c)
	s.testStoreAddServer(c)
}
Пример #3
0
func ForceRemoveDeadFence(zkConn zkhelper.Conn, productName string) error {
	proxies, err := ProxyList(zkConn, productName, func(p *ProxyInfo) bool {
		return p.State == PROXY_STATE_ONLINE
	})
	if err != nil {
		return errors.Trace(err)
	}
	fenceProxies, err := GetFenceProxyMap(zkConn, productName)
	if err != nil {
		return errors.Trace(err)
	}
	// remove online proxies's fence
	for _, proxy := range proxies {
		delete(fenceProxies, proxy.Addr)
	}

	// delete dead fence in zookeeper
	path := GetProxyFencePath(productName)
	for remainFence, _ := range fenceProxies {
		fencePath := filepath.Join(path, remainFence)
		log.Info("removing fence: ", fencePath)
		if err := zkhelper.DeleteRecursive(zkConn, fencePath, -1); err != nil {
			return errors.Trace(err)
		}
	}
	return nil
}
Пример #4
0
func (s *testUtilSuite) TearDownSuite(c *C) {
	if s.zkConn != nil {
		err := zkhelper.DeleteRecursive(s.zkConn, s.rootPath, -1)
		c.Assert(err, IsNil)

		s.zkConn.Close()
	}
}
Пример #5
0
func ActionGC(zkConn zkhelper.Conn, productName string, gcType int, keep int) error {
	prefix := GetWatchActionPath(productName)
	exists, err := zkhelper.NodeExists(zkConn, prefix)
	if err != nil {
		return errors.Trace(err)
	}
	if !exists {
		// if action path not exists just return nil
		return nil
	}

	actions, _, err := zkConn.Children(prefix)
	if err != nil {
		return errors.Trace(err)
	}

	var act Action
	currentTs := time.Now().Unix()

	if gcType == GC_TYPE_N {
		sort.Strings(actions)
		if len(actions) <= keep {
			return nil
		}

		for _, action := range actions[:len(actions)-keep] {
			if err := zkhelper.DeleteRecursive(zkConn, path.Join(prefix, action), -1); err != nil {
				return errors.Trace(err)
			}
		}
	} else if gcType == GC_TYPE_SEC {
		secs := keep
		for _, action := range actions {
			b, _, err := zkConn.Get(path.Join(prefix, action))
			if err != nil {
				return errors.Trace(err)
			}
			if err := json.Unmarshal(b, &act); err != nil {
				return errors.Trace(err)
			}
			log.Info(action, act.Ts)
			ts, _ := strconv.ParseInt(act.Ts, 10, 64)

			if currentTs-ts > int64(secs) {
				if err := zkConn.Delete(path.Join(prefix, action), -1); err != nil {
					return errors.Trace(err)
				}
			}
		}
	}

	return nil
}
Пример #6
0
func (s *testMultiServerSuite) TearDownSuite(c *C) {
	for _, tso := range s.servers {
		tso.Close()
	}

	if s.zkConn != nil {
		err := zkhelper.DeleteRecursive(s.zkConn, s.rootPath, -1)
		c.Assert(err, IsNil)

		s.zkConn.Close()
	}
}
Пример #7
0
func (s *testServerSuite) TearDownSuite(c *C) {
	if s.tso != nil {
		s.tso.Close()
	}

	if s.zkConn != nil {
		err := zkhelper.DeleteRecursive(s.zkConn, "/zk/tso_test", -1)
		c.Assert(err, IsNil)

		s.zkConn.Close()
	}
}
Пример #8
0
func (self *ServerGroup) Remove(zkConn zkhelper.Conn) error {
	// check if this group is not used by any slot
	slots, err := Slots(zkConn, self.ProductName)
	if err != nil {
		return errors.Trace(err)
	}

	for _, slot := range slots {
		if slot.GroupId == self.Id {
			return errors.AlreadyExistsf("group %d is using by slot %d", slot.GroupId, slot.Id)
		}
	}

	// do delte
	zkPath := fmt.Sprintf("/zk/codis/db_%s/servers/group_%d", self.ProductName, self.Id)
	err = zkhelper.DeleteRecursive(zkConn, zkPath, -1)

	err = NewAction(zkConn, self.ProductName, ACTION_TYPE_SERVER_GROUP_REMOVE, self, "", false)
	return errors.Trace(err)
}
Пример #9
0
func (sg *ServerGroup) Remove(coordConn zkhelper.Conn) error {
	// check if this group is not used by any slot
	slots, err := Slots(coordConn, sg.ProductName)
	if err != nil {
		return errors.Trace(err)
	}

	for _, slot := range slots {
		if slot.GroupId == sg.Id {
			return errors.AlreadyExistsf("group %d is using by slot %d", slot.GroupId, slot.Id)
		}
	}

	// do delete
	coordPath := fmt.Sprintf("/zk/reborn/db_%s/servers/group_%d", sg.ProductName, sg.Id)
	err = zkhelper.DeleteRecursive(coordConn, coordPath, -1)

	// we know that there's no slots affected, so this action doesn't need proxy confirm
	err = NewAction(coordConn, sg.ProductName, ACTION_TYPE_SERVER_GROUP_REMOVE, sg, "", false)
	return errors.Trace(err)
}
Пример #10
0
func (top *Topology) Close(proxyName string) {
	zkhelper.DeleteRecursive(top.zkConn, path.Join(models.GetProxyPath(top.ProductName), proxyName), -1)
	top.zkConn.Close()
}
Пример #11
0
func (m *MigrateManager) removeNode() error {
	return zkhelper.DeleteRecursive(m.zkConn, getManagerPath(m.productName), 0)
}