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
2 changes: 1 addition & 1 deletion server/controller/db/metadb/migrator/schema/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ const (
RAW_SQL_ROOT_DIR = "/etc/metadb/schema/rawsql"

DB_VERSION_TABLE = "db_version"
DB_VERSION_EXPECTED = "6.6.1.72"
DB_VERSION_EXPECTED = "6.6.1.73"
)
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,8 @@ CREATE TABLE IF NOT EXISTS vm (
INDEX epc_id_index(epc_id),
INDEX az_index(az),
INDEX region_index(region),
INDEX id_index(`id`)
INDEX id_index(`id`),
INDEX created_at_index(created_at)
)ENGINE=innodb AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
TRUNCATE TABLE vm;

Expand Down Expand Up @@ -800,7 +801,8 @@ CREATE TABLE IF NOT EXISTS lb (
lcuuid CHAR(64) DEFAULT '',
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
deleted_at DATETIME DEFAULT NULL
deleted_at DATETIME DEFAULT NULL,
INDEX created_at_index(created_at)
) ENGINE=innodb AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
TRUNCATE TABLE lb;

Expand Down Expand Up @@ -1124,7 +1126,8 @@ CREATE TABLE IF NOT EXISTS pod_group (
deleted_at DATETIME DEFAULT NULL,
INDEX pod_namespace_id_index(pod_namespace_id),
INDEX pod_cluster_id_index(pod_cluster_id),
INDEX lcuuid_index(lcuuid)
INDEX lcuuid_index(lcuuid),
INDEX created_at_index(created_at)
) ENGINE=innodb AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
TRUNCATE TABLE pod_group;

Expand Down Expand Up @@ -1162,7 +1165,8 @@ CREATE TABLE IF NOT EXISTS pod_rs (
updated_at DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
deleted_at DATETIME DEFAULT NULL,
INDEX pod_group_id_index(pod_group_id),
INDEX pod_namespace_id_index(pod_namespace_id)
INDEX pod_namespace_id_index(pod_namespace_id),
INDEX created_at_index(created_at)
) ENGINE=innodb AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
TRUNCATE TABLE pod_rs;

Expand Down Expand Up @@ -1201,7 +1205,8 @@ CREATE TABLE IF NOT EXISTS pod (
INDEX az_index(az),
INDEX region_index(region),
INDEX domain_index(domain),
INDEX lcuuid_index(lcuuid)
INDEX lcuuid_index(lcuuid),
INDEX created_at_index(created_at)
) ENGINE=innodb AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
TRUNCATE TABLE pod;

Expand Down Expand Up @@ -1268,7 +1273,8 @@ CREATE TABLE IF NOT EXISTS process (
deleted_at DATETIME DEFAULT NULL,
INDEX domain_sub_domain_gid_updated_at_index(domain, sub_domain, gid, updated_at),
INDEX deleted_at_index(deleted_at),
INDEX lcuuid_index(lcuuid)
INDEX lcuuid_index(lcuuid),
INDEX created_at_index(created_at)
) ENGINE=innodb DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
TRUNCATE TABLE process;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
DROP PROCEDURE IF EXISTS AddIndexIfNotExists;

CREATE PROCEDURE AddIndexIfNotExists(
IN tableName VARCHAR(255),
IN indexName VARCHAR(255),
IN indexCol VARCHAR(255)
)
BEGIN
DECLARE index_count INT;

SELECT COUNT(*)
INTO index_count
FROM information_schema.statistics
WHERE table_schema = DATABASE()
AND table_name = tableName
AND column_name = indexCol;

IF index_count = 0 THEN
SET @sql = CONCAT('ALTER TABLE ', tableName, ' ADD INDEX ', indexName, ' (', indexCol, ') USING BTREE');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
END;

CALL AddIndexIfNotExists('vm', 'created_at_index', 'created_at');
CALL AddIndexIfNotExists('lb', 'created_at_index', 'created_at');
CALL AddIndexIfNotExists('pod_group', 'created_at_index', 'created_at');
CALL AddIndexIfNotExists('pod_rs', 'created_at_index', 'created_at');
CALL AddIndexIfNotExists('pod', 'created_at_index', 'created_at');
CALL AddIndexIfNotExists('process', 'created_at_index', 'created_at');

DROP PROCEDURE IF EXISTS AddIndexIfNotExists;

UPDATE db_version SET version="6.6.1.73";
4 changes: 2 additions & 2 deletions server/controller/db/metadb/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func FindInBatches[T any](query *gorm.DB) ([]*T, error) {
pageCount := int(metadb.GetConfig().BatchSize0)
pageData := make([]*T, 0)
for pageIndex == 0 || len(pageData) == pageCount {
err := query.Find(&pageData).Limit(pageCount).Offset(pageIndex * pageCount).Error
err := query.Limit(pageCount).Offset(pageIndex * pageCount).Find(&pageData).Error
if err != nil {
return []*T{}, err
}
Expand All @@ -45,7 +45,7 @@ func FindInBatchesObj[T any](query *gorm.DB) ([]T, error) { // TODO unify return
pageCount := int(metadb.GetConfig().BatchSize0)
pageData := make([]T, 0)
for pageIndex == 0 || len(pageData) == pageCount {
err := query.Find(&pageData).Limit(pageCount).Offset(pageIndex * pageCount).Error
err := query.Limit(pageCount).Offset(pageIndex * pageCount).Find(&pageData).Error
if err != nil {
return []T{}, err
}
Expand Down
1 change: 0 additions & 1 deletion server/controller/recorder/db/idmng/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func newIDManager(cfg RecorderConfig, orgID int) (*IDManager, error) {
ctrlrcommon.RESOURCE_TYPE_POD_INGRESS_EN: newIDPool[mysqlmodel.PodIngress](mng.org, ctrlrcommon.RESOURCE_TYPE_POD_INGRESS_EN, cfg.ResourceMaxID1),
ctrlrcommon.RESOURCE_TYPE_POD_GROUP_EN: newIDPool[mysqlmodel.PodGroup](mng.org, ctrlrcommon.RESOURCE_TYPE_POD_GROUP_EN, cfg.ResourceMaxID1),
ctrlrcommon.RESOURCE_TYPE_POD_REPLICA_SET_EN: newIDPool[mysqlmodel.PodReplicaSet](mng.org, ctrlrcommon.RESOURCE_TYPE_POD_REPLICA_SET_EN, cfg.ResourceMaxID1),
ctrlrcommon.RESOURCE_TYPE_PROCESS_EN: newIDPool[mysqlmodel.Process](mng.org, ctrlrcommon.RESOURCE_TYPE_PROCESS_EN, cfg.ResourceMaxID1),
ctrlrcommon.RESOURCE_TYPE_GPROCESS_EN: newProcessGIDPool(mng.org, ctrlrcommon.RESOURCE_TYPE_GPROCESS_EN, cfg.ResourceMaxID1),
ctrlrcommon.RESOURCE_TYPE_VTAP_EN: newIDPool[mysqlmodel.VTap](mng.org, ctrlrcommon.RESOURCE_TYPE_VTAP_EN, cfg.ResourceMaxID0),
}
Expand Down
2 changes: 1 addition & 1 deletion server/controller/recorder/db/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewProcess() *Process {
newOperatorBase[*mysqlmodel.Process](
ctrlrcommon.RESOURCE_TYPE_PROCESS_EN,
true,
true,
false,
),
}
return operator
Expand Down
1 change: 1 addition & 0 deletions server/controller/recorder/updater/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ func (p *Process) beforeAddPage(dbData []*metadbmodel.Process) ([]*metadbmodel.P
identifierToNewGID[identifier] = item.GID
}
}
log.Infof("%s identifier generation completed", p.resourceType, p.metadata.LogPrefixes)
var createdGIDs []uint32
if len(identifierToNewGID) > 0 {
// TODO combine with operator module
Expand Down
Loading