Example #1
0
func node2metaserver(nodecon node) metadata.Chunkserver {
	metaserver := new(metadata.Chunkserver)
	metaserver.Ip = nodecon.ip
	metaserver.Port = nodecon.port
	metaserver.DataDir = nodecon.datadir
	metaserver.GroupId = uint16(nodecon.groupid)
	return *metaserver
}
Example #2
0
func reportChunkserverInfo(key string, chunkserver *metadata.Chunkserver, oldChunkserver *metadata.Chunkserver) error {
	if oldChunkserver.Status == INIT_STATUS {
		err := mdDriver.UpdateChunkserverInfo(chunkserver, INIT_STATUS, RW_STATUS)
		if err != nil {
			return err
		}
		chunkserver.Status = RW_STATUS
	}

	if RW_STATUS == oldChunkserver.Status {
		err := mdDriver.UpdateChunkserverInfo(chunkserver, RW_STATUS, RW_STATUS)
		if err != nil {
			return err
		}
		chunkserver.Status = RW_STATUS
	}

	if RO_STATUS == oldChunkserver.Status {
		err := mdDriver.UpdateChunkserverInfo(chunkserver, RO_STATUS, RW_STATUS)
		if err != nil {
			return err
		}
		log.Infof("[reportChunkserverInfo] update RO_STATUS to RW_STATUS chunkserver: %v", key)
		chunkserver.Status = RW_STATUS
	}

	chunkserver.UpdateTime = time.Now()

	lock.Lock()
	_, ok := serverInfo[key]
	if !ok {
		lock.Unlock()
		return fmt.Errorf("do not exist: %v", chunkserver)
	}
	serverInfo[key] = chunkserver
	lock.Unlock()
	return nil
}
Example #3
0
func AddChunkserver(chunkserver *metadata.Chunkserver) error {
	chunkserver.Status = INIT_STATUS
	chunkserver.TotalFreeSpace = 0
	chunkserver.MaxFreeSpace = 0
	chunkserver.PendingWrites = 0
	chunkserver.WritingCount = 0
	chunkserver.DataDir = ""
	chunkserver.ReadingCount = 0
	chunkserver.TotalChunks = 0
	chunkserver.ConnectionsCount = 0

	err := mdDriver.AddChunkserver(chunkserver)
	if err != nil {
		return err
	}
	lock.Lock()
	defer lock.Unlock()

	key := fmt.Sprintf("%d:%s:%d", chunkserver.GroupId, chunkserver.Ip, chunkserver.Port)
	chunkserver.UpdateTime = time.Now()
	serverInfo[key] = chunkserver
	return nil
}
Example #4
0
func TestUpdateChunkserver(t *testing.T) {
	conn, err := getConn()
	chunkserver := new(metadata.Chunkserver)

	chunkserver.GroupId = uint16(1)
	chunkserver.Ip = "127.0.0.1"
	chunkserver.Port = 5444
	chunkserver.Status = 0
	chunkserver.TotalFreeSpace = int64(65)
	chunkserver.MaxFreeSpace = int64(1231231231231234534)

	err = conn.UpdateChunkserver(chunkserver)
	if err != nil {
		t.Fatal(err)
	}
}
Example #5
0
func TestNotExistChunkserver(t *testing.T) {
	conn, err := getConn()
	chunkserver := new(metadata.Chunkserver)

	chunkserver.GroupId = uint16(3)
	chunkserver.Ip = "127.0.0.1"
	chunkserver.Port = 5444
	chunkserver.Status = 0
	chunkserver.TotalFreeSpace = int64(45465465)
	chunkserver.MaxFreeSpace = int64(123123123123123)

	exist, err := conn.IsExistChunkserver(chunkserver)
	if err != nil {
		t.Fatal(err)
	}
	t.Log("exist:", exist)
}
Example #6
0
func initChunkserverHandler(resp http.ResponseWriter, req *http.Request) {
	reqData, err := ioutil.ReadAll(req.Body)
	defer req.Body.Close()
	if err != nil {
		util.HandleError(resp, "", err, http.StatusBadRequest)
		return
	}
	log.Infof("[initserverHandler] read reqData %v", string(reqData))

	var jsonMap map[string]interface{}
	err = json.Unmarshal(reqData, &jsonMap)
	if err != nil {
		util.HandleError(resp, "", err, http.StatusBadRequest)
		return
	}
	log.Infof("[initserverHandler] change json to map %v", jsonMap)

	groupId := uint16((jsonMap["GroupId"]).(float64))
	ip := jsonMap["Ip"].(string)
	port := int((jsonMap["Port"]).(float64))
	chunkserver := new(metadata.Chunkserver)
	chunkserver.GroupId = groupId
	chunkserver.Ip = ip
	chunkserver.Port = port
	chunkserver.Status = INIT_STATUS
	chunkserver.TotalFreeSpace = 0
	chunkserver.MaxFreeSpace = 0
	chunkserver.PendingWrites = 0
	chunkserver.WritingCount = 0
	chunkserver.DataDir = ""
	chunkserver.ReadingCount = 0
	chunkserver.TotalChunks = 0
	chunkserver.ConnectionsCount = 0

	err = AddChunkserver(chunkserver)
	if err != nil {
		util.HandleError(resp, "", err, http.StatusInternalServerError)
		return
	}

	util.Response(nil, http.StatusOK, resp)
}
Example #7
0
func TestAddChunkserver(t *testing.T) {
	conn, err := getConn()

	chunkserver := new(metadata.Chunkserver)
	chunkserver.GroupId = uint16(65535)
	chunkserver.Ip = "127.0.0.1"
	chunkserver.Port = 5444
	chunkserver.Status = 0
	chunkserver.TotalFreeSpace = int64(45465465)
	chunkserver.MaxFreeSpace = int64(123123123123123)
	chunkserver.PendingWrites = 1
	chunkserver.WritingCount = 1
	chunkserver.DataDir = "/export/"
	chunkserver.ReadingCount = 1
	chunkserver.TotalChunks = 1
	chunkserver.ConnectionsCount = 1

	err = conn.AddChunkserver(chunkserver)
	if err != nil {
		t.Fatal(err)
	}
}
Example #8
0
func (this *oss) Loadconfig() error {
	var err error
	confpath := "oss/oss.conf"
	conf, err := config.NewConfig("ini", confpath)
	if err != nil {
		return fmt.Errorf("Read OSS config file %s error: %v", confpath, err.Error())
	}
	// load chunkmaster configs
	if ossmode := conf.String("ossmode"); ossmode != "" {
		this.OssMode = ossmode
	} else {
		this.OssMode = "allinone"
	}
	if masterhost := conf.String("masterhost"); masterhost != "" {
		this.cm.serverHost = masterhost
		apiserver.MasterUrl = masterhost
	} else {
		err = fmt.Errorf("masterhost value is null")
	}
	this.cm.serverPort, err = conf.Int("masterport")
	apiserver.MasterPort = strconv.Itoa(this.cm.serverPort)

	if metahost := conf.String("metahost"); metahost != "" {
		this.cm.metaHost = metahost
		apiserver.MetadbIp = metahost
	} else {
		err = fmt.Errorf("metaHost  value is null")
	}
	if metaport := conf.String("metaport"); metaport != "" {
		this.cm.metaPort = metaport
		apiserver.MetadbPort, err = strconv.Atoi(metaport)
	} else {
		err = fmt.Errorf("metaport  value is null")
	}

	if dbuser := conf.String("dbuser"); dbuser != "" {
		this.cm.user = dbuser
		apiserver.MetadbUser = dbuser
	} else {
		err = fmt.Errorf("dbuser value is null")
	}
	if dbpasswd := conf.String("dbpasswd"); dbpasswd != "" {
		this.cm.passwd = dbpasswd
		apiserver.MetadbPassword = dbpasswd
	} else {
		err = fmt.Errorf("dbpasswd value is null")
	}
	if db := conf.String("db"); db != "" {
		this.cm.db = db
	} else {
		err = fmt.Errorf("db value is null")
	}
	this.cm.limitCSNum, err = conf.Int("limitcsnum")
	apiserver.LimitNum = this.cm.limitCSNum
	this.cm.connPoolCapacity, err = conf.Int("connpoolcapacity")
	apiserver.ConnPoolCapacity = this.cm.connPoolCapacity

	if errlogpath := conf.String("errlogpath"); errlogpath != "" {
		this.ErrLogPath = errlogpath
	} else {
		this.ErrLogPath = "/usr/local/oss/errlog"
	}
	if datapath := conf.String("datapath"); datapath != "" {
		this.DataPath = datapath
	} else {
		this.DataPath = "/usr/local/oss/data"
	}
	if servers := conf.String("servers"); servers != "" {
		this.Servers = servers
	} else {
		err = fmt.Errorf("servers value is null")
	}

	this.ChunkNum, err = conf.Int("chunknum")

	// Load chunkserver configs and convert chunkserver string to  to objs
	for _, server := range strings.Split(this.Servers, ";") {
		if isMatch, _ := regexp.MatchString("^\\d_((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\:\\d{0,5}$", server); !isMatch {
			return fmt.Errorf("chunkserver config format error : %s", server)
		}
		groupid := strings.Split(server, "_")[0]
		ip := strings.Split(strings.Split(server, "_")[1], ":")[0]
		port := strings.Split(strings.Split(server, "_")[1], ":")[1]
		chunkserver := metadata.Chunkserver{}
		chunkserver.Ip = ip
		groupiduint, _ := strconv.ParseUint(groupid, 10, 16)
		chunkserver.GroupId = uint16(groupiduint)
		portint, _ := strconv.Atoi(port)
		chunkserver.Port = portint
		chunkserver.DataDir = fmt.Sprintf("%v/server_%v_%v", this.DataPath, chunkserver.Ip, chunkserver.Port)
		this.cs = append(this.cs, chunkserver)
	}
	return nil
}