-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: imporve task query speed (#21921)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
- Loading branch information
Showing
10 changed files
with
488 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright 2019 Yunion | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package taskman | ||
|
||
import ( | ||
"context" | ||
|
||
"yunion.io/x/jsonutils" | ||
"yunion.io/x/pkg/errors" | ||
"yunion.io/x/pkg/util/rbacscope" | ||
"yunion.io/x/sqlchemy" | ||
|
||
"yunion.io/x/onecloud/pkg/cloudcommon/consts" | ||
"yunion.io/x/onecloud/pkg/cloudcommon/db" | ||
"yunion.io/x/onecloud/pkg/mcclient" | ||
) | ||
|
||
type SArchivedTaskManager struct { | ||
db.SLogBaseManager | ||
db.SStatusResourceBaseManager | ||
} | ||
|
||
var ArchivedTaskManager *SArchivedTaskManager | ||
|
||
func InitArchivedTaskManager() { | ||
ArchivedTaskManager = &SArchivedTaskManager{ | ||
SLogBaseManager: db.NewLogBaseManager( | ||
SArchivedTask{}, | ||
"archived_tasks_tbl", | ||
"achivedtask", | ||
"achivedtasks", | ||
"start_at", | ||
consts.OpsLogWithClickhouse, | ||
), | ||
} | ||
ArchivedTaskManager.SetVirtualObject(ArchivedTaskManager) | ||
} | ||
|
||
type SArchivedTask struct { | ||
db.SLogBase | ||
|
||
TaskId string `width:"36" charset:"ascii" index:"true" list:"user"` | ||
|
||
STaskBase | ||
|
||
ObjIds []string `charset:"ascii" list:"user"` | ||
ObjNames []string `charset:"utf8" list:"user"` | ||
ProjectIds []string `charset:"ascii" list:"user"` | ||
DomainIds []string `charset:"ascii" list:"user"` | ||
|
||
SubTaskCount int `json:"sub_task_count" list:"user"` | ||
FailSubTaskCnt int `json:"fail_sub_task_cnt" list:"user"` | ||
SuccSubTaskCnt int `json:"succ_sub_task_cnt" list:"user"` | ||
} | ||
|
||
func (manager *SArchivedTaskManager) NamespaceScope() rbacscope.TRbacScope { | ||
return rbacscope.ScopeProject | ||
} | ||
|
||
func (manager *SArchivedTaskManager) Insert(ctx context.Context, task *STask) error { | ||
archivedTask := SArchivedTask{} | ||
archivedTask.TaskId = task.Id | ||
archivedTask.STaskBase = task.STaskBase | ||
archivedTask.ObjIds = TaskObjectManager.GetObjectIds(task) | ||
archivedTask.ObjNames = TaskObjectManager.GetObjectNames(task) | ||
archivedTask.FailSubTaskCnt, _ = SubTaskManager.GetSubtasksCount(task.Id, "", SUBTASK_FAIL) | ||
archivedTask.SuccSubTaskCnt, _ = SubTaskManager.GetSubtasksCount(task.Id, "", SUBTASK_SUCC) | ||
archivedTask.SubTaskCount = archivedTask.FailSubTaskCnt + archivedTask.SuccSubTaskCnt | ||
archivedTask.ProjectIds = TaskObjectManager.GetProjectIds(task) | ||
archivedTask.DomainIds = TaskObjectManager.GetDomainIds(task) | ||
|
||
err := manager.TableSpec().Insert(ctx, &archivedTask) | ||
if err != nil { | ||
return errors.Wrap(err, "Insert") | ||
} | ||
return nil | ||
} | ||
|
||
func (task *SArchivedTask) GetOwnerId() mcclient.IIdentityProvider { | ||
return nil | ||
} | ||
|
||
func (manager *SArchivedTaskManager) FilterByOwner(ctx context.Context, q *sqlchemy.SQuery, man db.FilterByOwnerProvider, userCred mcclient.TokenCredential, owner mcclient.IIdentityProvider, scope rbacscope.TRbacScope) *sqlchemy.SQuery { | ||
return q | ||
} | ||
|
||
func (manager *SArchivedTaskManager) FetchOwnerId(ctx context.Context, data jsonutils.JSONObject) (mcclient.IIdentityProvider, error) { | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2019 Yunion | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package taskman | ||
|
||
import ( | ||
"time" | ||
|
||
"yunion.io/x/jsonutils" | ||
|
||
"yunion.io/x/onecloud/pkg/cloudcommon/db" | ||
"yunion.io/x/onecloud/pkg/mcclient" | ||
) | ||
|
||
type STaskBase struct { | ||
db.SStatusResourceBase | ||
|
||
// 开始任务时间 | ||
StartAt time.Time `nullable:"true" list:"user" json:"start_at"` | ||
// 完成任务时间 | ||
EndAt time.Time `nullable:"true" list:"user" json:"end_at"` | ||
|
||
ObjType string `old_name:"obj_name" json:"obj_type" width:"128" charset:"utf8" nullable:"true" list:"user"` | ||
Object string `json:"object" width:"128" charset:"utf8" nullable:"true" list:"user"` // Column(VARCHAR(128, charset='utf8'), nullable=False) | ||
ObjId string `width:"128" charset:"ascii" nullable:"false" list:"user" index:"true"` // Column(VARCHAR(ID_LENGTH, charset='ascii'), nullable=False) | ||
TaskName string `width:"64" charset:"ascii" nullable:"false" list:"user" index:"true"` // Column(VARCHAR(64, charset='ascii'), nullable=False) | ||
|
||
UserCred mcclient.TokenCredential `width:"1024" charset:"utf8" nullable:"false" get:"user"` // Column(VARCHAR(1024, charset='ascii'), nullable=False) | ||
// OwnerCred string `width:"512" charset:"ascii" nullable:"true"` // Column(VARCHAR(512, charset='ascii'), nullable=True) | ||
Params *jsonutils.JSONDict `charset:"utf8" length:"medium" nullable:"false" get:"user"` // Column(MEDIUMTEXT(charset='ascii'), nullable=False) | ||
|
||
Stage string `width:"64" charset:"ascii" nullable:"false" default:"on_init" list:"user" index:"true"` // Column(VARCHAR(64, charset='ascii'), nullable=False, default='on_init') | ||
|
||
// 父任务Id | ||
ParentTaskId string `width:"36" charset:"ascii" list:"user" index:"true" json:"parent_task_id"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.