Example #1
0
func InitAPI() error {
	Ip = "0.0.0.0"
	Port = setting.APIPort
	HttpsPort = setting.APIHttpsPort
	fids = chunkserver.NewFids()
	chunkServerGroups = nil
	connectionPools = nil
	getFidRetryCount = 0
	MetaDatabase = "metadb"
	err := GetChunkServerInfo()
	if err != nil {
		return fmt.Errorf("GetChunkServerInfo error: %v  \n", err)
	}

	err = GetFidRange(false)
	if err != nil {
		return fmt.Errorf("GetFidRange error: %v \n", err)
	}

	go GetFidRangeTicker()
	go GetChunkServerInfoTicker()

	err = mysqldriver.InitMeta(MetadbIp, MetadbPort, MetadbUser, MetadbPassword, MetaDatabase)
	if err != nil {
		return fmt.Errorf("Connect metadb error: %v \n", err)
	}

	metaDriver = new(mysqldriver.MysqlDriver)
	return nil
}
Example #2
0
func GetFidRange(mergeWait bool) error {
	if !fids.IsShortage() {
		return nil
	}

	byteData, statusCode, err := util.Call("GET", "http://"+MasterUrl+":"+MasterPort, "/cm/v1/chunkmaster/fid", nil, nil)
	if err != nil {
		fmt.Errorf("[OSS]GetChunkServerInfo response code: %d, err: %s \n", statusCode, err)
		return err
	}

	if statusCode != http.StatusOK {
		fmt.Errorf("[OSS]response code: %d \n", statusCode)
		return fmt.Errorf("statusCode error: %d \n", statusCode)
	}

	fmt.Printf("[OSS]GetFidRange data: %s \n \n", string(byteData))

	newFids := chunkserver.NewFids()
	err = json.Unmarshal(byteData, &newFids)
	if err != nil {
		fmt.Errorf("[OSS]GetFidRange json.Unmarshal response data error: %s \n", err)
		return err
	}

	fids.Merge(newFids.Start, newFids.End, mergeWait)
	return nil
}