func generateSpliteKey()

in datahub/shard.go [21:44]


func generateSpliteKey(projectName, topicName, shardId string, datahub DataHubApi) (string, error) {
	ls, err := datahub.ListShard(projectName, topicName)
	if err != nil {
		return "", err
	}
	shards := ls.Shards
	splitKey := ""
	for _, shard := range shards {
		if strings.EqualFold(shardId, shard.ShardId) {
			if shard.State != ACTIVE {
				return "", fmt.Errorf("only active shard can be split,the shard %s state is %s", shard.ShardId, shard.State)
			}
			splitKey, err = getSplitKey(shard.BeginHashKey, shard.EndHashKey)
			splitKey = strings.ToUpper(splitKey)
			if err != nil {
				return "", err
			}
		}
	}
	if splitKey == "" {
		return "", fmt.Errorf("shard not exist")
	}
	return splitKey, nil
}