Skip to content

Commit 1f1ef74

Browse files
ZhengYa-0110SongZhen0704
authored andcommitted
fix: enable ID allocation for lb_listener and clean up out-of-range data
1 parent ac66119 commit 1f1ef74

6 files changed

Lines changed: 22 additions & 5 deletions

File tree

server/controller/db/metadb/migrator/common/init.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ func InitCETables(dc *DBConfig) error {
5050
func InitTables(dc *DBConfig, rawSqlDir string) error {
5151
log.Info(LogDBName(dc.Config.Database, "initialize %s tables", rawSqlDir))
5252

53-
for _, sqlFile := range GetSortedSQLFiles(rawSqlDir, false) {
53+
sortedFiles := GetSortedSQLFiles(rawSqlDir, false)
54+
log.Info(LogDBName(dc.Config.Database, "files to executed: %v", sortedFiles))
55+
for _, sqlFile := range sortedFiles {
5456
err := ReadAndExecuteSqlFile(dc, sqlFile)
5557
if err != nil {
5658
return err
@@ -59,7 +61,9 @@ func InitTables(dc *DBConfig, rawSqlDir string) error {
5961

6062
// 通过判断数据库名称后缀,判断数据库是否是 default 组织。
6163
if !strings.HasSuffix(dc.Config.Database, common.NON_DEFAULT_ORG_DATABASE_SUFFIX) {
62-
for _, sqlFile := range GetSortedSQLFiles(rawSqlDir, true) {
64+
sortedFiles := GetSortedSQLFiles(rawSqlDir, true)
65+
log.Info(LogDBName(dc.Config.Database, "files to be executed: %v", sortedFiles))
66+
for _, sqlFile := range sortedFiles {
6367
err := ReadAndExecuteSqlFile(dc, sqlFile)
6468
if err != nil {
6569
return err

server/controller/db/metadb/migrator/schema/const.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ const (
2020
RAW_SQL_ROOT_DIR = "/etc/metadb/schema/rawsql"
2121

2222
DB_VERSION_TABLE = "db_version"
23-
DB_VERSION_EXPECTED = "6.6.1.70"
23+
DB_VERSION_EXPECTED = "6.6.1.71"
2424
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
-- Clean up lb_listener rows whose id exceeds the ID pool upper bound (ResourceMaxID1 default 499999).
3+
-- These IDs cannot be managed by the allocator and must be removed before enabling ID allocation.
4+
DELETE FROM lb_listener WHERE id > 499999;
5+
6+
-- Clean up lb_target_server rows that reference a non-existent lb_listener.
7+
-- This covers both pre-existing orphans and rows whose lb_listener was just removed above.
8+
DELETE FROM lb_target_server
9+
WHERE lb_listener_id NOT IN (SELECT id FROM lb_listener);
10+
11+
-- Update DB version
12+
UPDATE db_version SET version='6.6.1.71';

server/controller/db/metadb/model/constraint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type AssetResourceConstraint interface {
5353
type ResourceNeedBeAllocatedIDConstraint interface {
5454
Region | AZ | SubDomain | Host | VM |
5555
VPC | Network | VRouter | DHCPPort |
56-
NATGateway | LB | CEN |
56+
NATGateway | LB | LBListener | CEN |
5757
PeerConnection | RDSInstance | RedisInstance | PodCluster |
5858
PodNode | VMPodNodeConnection | PodNamespace | PodIngress |
5959
PodService | PodGroup | PodReplicaSet |

server/controller/recorder/db/idmng/manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func newIDManager(cfg RecorderConfig, orgID int) (*IDManager, error) {
6565
ctrlrcommon.RESOURCE_TYPE_REDIS_INSTANCE_EN: newIDPool[mysqlmodel.RedisInstance](mng.org, ctrlrcommon.RESOURCE_TYPE_REDIS_INSTANCE_EN, cfg.ResourceMaxID1),
6666
ctrlrcommon.RESOURCE_TYPE_NAT_GATEWAY_EN: newIDPool[mysqlmodel.NATGateway](mng.org, ctrlrcommon.RESOURCE_TYPE_NAT_GATEWAY_EN, cfg.ResourceMaxID1),
6767
ctrlrcommon.RESOURCE_TYPE_LB_EN: newIDPool[mysqlmodel.LB](mng.org, ctrlrcommon.RESOURCE_TYPE_LB_EN, cfg.ResourceMaxID1),
68+
ctrlrcommon.RESOURCE_TYPE_LB_LISTENER_EN: newIDPool[mysqlmodel.LBListener](mng.org, ctrlrcommon.RESOURCE_TYPE_LB_LISTENER_EN, cfg.ResourceMaxID1),
6869
ctrlrcommon.RESOURCE_TYPE_POD_NODE_EN: newIDPool[mysqlmodel.PodNode](mng.org, ctrlrcommon.RESOURCE_TYPE_POD_NODE_EN, cfg.ResourceMaxID1),
6970
ctrlrcommon.RESOURCE_TYPE_POD_SERVICE_EN: newIDPool[mysqlmodel.PodService](mng.org, ctrlrcommon.RESOURCE_TYPE_POD_SERVICE_EN, cfg.ResourceMaxID1),
7071
ctrlrcommon.RESOURCE_TYPE_POD_EN: newIDPool[mysqlmodel.Pod](mng.org, ctrlrcommon.RESOURCE_TYPE_POD_EN, cfg.ResourceMaxID1),

server/controller/recorder/db/lb_listener.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func NewLBListener() *LBListener {
3030
newOperatorBase[*mysqlmodel.LBListener](
3131
ctrlrcommon.RESOURCE_TYPE_LB_LISTENER_EN,
3232
true,
33-
false,
33+
true,
3434
),
3535
}
3636
operater.setFieldsNeededAfterCreate([]string{"id", "lcuuid", "name", "ips", "snat_ips", "port", "protocol"})

0 commit comments

Comments
 (0)