Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion api/disaggregated/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,12 @@ type ComputeGroupStatus struct {
// the service that can access the compute group pods.
ServiceName string `json:"serviceName,omitempty"`

//
//the unique id of compute group in kubernetes, this field is part of compute group statefulset.
UniqueId string `json:"uniqueId,omitempty"`

//the compute group id in doris meta, this response to the backend's tag "compute_group_id";
ComputeGroupId string `json:"computeGroupId,omitempty"`

//AvailableStatus represents the compute group available or not.
AvailableStatus AvailableStatus `json:"availableStatus,omitempty"`

Expand Down
7 changes: 4 additions & 3 deletions api/disaggregated/v1/unique_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
package v1

import (
"crypto/sha256"
"math/big"
"strings"
"crypto/sha256"
"math/big"
"strings"
)

/*
Expand Down Expand Up @@ -80,6 +80,7 @@ func (ddc *DorisDisaggregatedCluster) GetMSServiceName() string {
return ddc.Name + "-" + "ms"
}

//the first deployed used computegroup name, when user rename the compute group name by sql command `ALTER SYSTEM RENAME COMPUTE GROUP <old_name> <new_name>`, this function will not right.
func (ddc *DorisDisaggregatedCluster) GetCGName(cg *ComputeGroup) string {
// use uniqueId as compute group name, the uniqueId restrict not empty, and the computegroup's name should use "_" not "-"
return strings.ReplaceAll(cg.UniqueId, "-", "_")
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15953,6 +15953,10 @@ spec:
description: AvailableStatus represents the compute group available
or not.
type: string
computeGroupId:
description: the compute group id in doris meta, this response
to the backend's tag "compute_group_id";
type: string
phase:
description: Phase represent the stage of reconciling.
type: string
Expand All @@ -15973,6 +15977,8 @@ spec:
format: int32
type: integer
uniqueId:
description: the unique id of compute group in kubernetes, this
field is part of compute group statefulset.
type: string
type: object
type: array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6826,6 +6826,10 @@ spec:
description: AvailableStatus represents the compute group available
or not.
type: string
computeGroupId:
description: the compute group id in doris meta, this response
to the backend's tag "compute_group_id";
type: string
phase:
description: Phase represent the stage of reconciling.
type: string
Expand All @@ -6846,6 +6850,8 @@ spec:
format: int32
type: integer
uniqueId:
description: the unique id of compute group in kubernetes, this
field is part of compute group statefulset.
type: string
type: object
type: array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6826,6 +6826,10 @@ spec:
description: AvailableStatus represents the compute group available
or not.
type: string
computeGroupId:
description: the compute group id in doris meta, this response
to the backend's tag "compute_group_id";
type: string
phase:
description: Phase represent the stage of reconciling.
type: string
Expand All @@ -6846,6 +6850,8 @@ spec:
format: int32
type: integer
uniqueId:
description: the unique id of compute group in kubernetes, this
field is part of compute group statefulset.
type: string
type: object
type: array
Expand Down
41 changes: 28 additions & 13 deletions pkg/common/utils/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@
package mysql

import (
"database/sql"
"encoding/json"
"fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
"k8s.io/klog/v2"
"database/sql"
"encoding/json"
"fmt"
"os"

_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
"k8s.io/klog/v2"
)

const (
COMPUTE_GROUP_ID = "compute_group_id"
)

type DBConfig struct {
Expand All @@ -34,11 +40,20 @@ type DBConfig struct {
Database string
}

func NewDBConfig() DBConfig {
return DBConfig{
Database: "mysql",
}
}

type DB struct {
*sqlx.DB
}

func NewDorisSqlDB(cfg DBConfig) (*DB, error) {
if os.Getenv("DEBUG") == "true" {
cfg.Host = "10.152.183.86"
}
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s", cfg.User, cfg.Password, cfg.Host, cfg.Port, cfg.Database)
db, err := sqlx.Open("mysql", dsn)
if err != nil {
Expand Down Expand Up @@ -168,27 +183,27 @@ func (db *DB) GetObservers() ([]*Frontend, error) {
return res, nil
}

func (db *DB) GetBackendsByCGName(cgName string) ([]*Backend, error) {
func (db *DB) GetBackendsByComputeGroupId(cgid string) ([]*Backend, error) {
backends, err := db.ShowBackends()
if err != nil {
klog.Errorf("GetBackendsByCGName show backends failed, err: %s\n", err.Error())
klog.Errorf("GetBackendsByComputeGroupId show backends failed, err: %s\n", err.Error())
return nil, err
}
var res []*Backend
for _, be := range backends {
var m map[string]interface{}
err := json.Unmarshal([]byte(be.Tag), &m)
if err != nil {
klog.Errorf("GetBackendsByCGName backends tag stirng to map failed, tag: %s, err: %s\n", be.Tag, err.Error())
klog.Errorf("GetBackendsByComputeGroupId backends tag stirng to map failed, tag: %s, err: %s\n", be.Tag, err.Error())
return nil, err
}
if _, ok := m["compute_group_name"]; !ok {
klog.Errorf("GetBackendsByCGName backends tag get compute_group_name failed, tag: %s, err: %s\n", be.Tag, err.Error())
if _, ok := m[COMPUTE_GROUP_ID]; !ok {
klog.Errorf("GetBackendsByComputeGroupId backends tag get compute_group_name failed, tag: %s, err: %s\n", be.Tag, err.Error())
return nil, err
}

cgNameFromTag := fmt.Sprintf("%s", m["compute_group_name"])
if cgNameFromTag == cgName {
computegroupId := fmt.Sprintf("%s", m[COMPUTE_GROUP_ID])
if computegroupId == cgid {
res = append(res, be)
}
}
Expand Down
Loading