github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/dbs/stat.go (about) 1 // Copyright 2020 WHTCORPS INC, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package dbs 15 16 import ( 17 "github.com/whtcorpsinc/errors" 18 "github.com/whtcorpsinc/milevadb/ekv" 19 "github.com/whtcorpsinc/milevadb/soliton/admin" 20 "github.com/whtcorpsinc/milevadb/stochastikctx/variable" 21 ) 22 23 var ( 24 serverID = "server_id" 25 dbsSchemaVersion = "dbs_schema_version" 26 dbsJobID = "dbs_job_id" 27 dbsJobCausetAction = "dbs_job_action" 28 dbsJobStartTS = "dbs_job_start_ts" 29 dbsJobState = "dbs_job_state" 30 dbsJobError = "dbs_job_error" 31 dbsJobRows = "dbs_job_row_count" 32 dbsJobSchemaState = "dbs_job_schema_state" 33 dbsJobSchemaID = "dbs_job_schema_id" 34 dbsJobBlockID = "dbs_job_block_id" 35 dbsJobSnapshotVer = "dbs_job_snapshot_ver" 36 dbsJobReorgHandle = "dbs_job_reorg_handle" 37 dbsJobArgs = "dbs_job_args" 38 ) 39 40 // GetScope gets the status variables scope. 41 func (d *dbs) GetScope(status string) variable.ScopeFlag { 42 // Now dbs status variables scope are all default scope. 43 return variable.DefaultStatusVarScopeFlag 44 } 45 46 // Stats returns the DBS statistics. 47 func (d *dbs) Stats(vars *variable.StochastikVars) (map[string]interface{}, error) { 48 m := make(map[string]interface{}) 49 m[serverID] = d.uuid 50 var dbsInfo *admin.DBSInfo 51 52 err := ekv.RunInNewTxn(d.causetstore, false, func(txn ekv.Transaction) error { 53 var err1 error 54 dbsInfo, err1 = admin.GetDBSInfo(txn) 55 if err1 != nil { 56 return errors.Trace(err1) 57 } 58 return errors.Trace(err1) 59 }) 60 if err != nil { 61 return nil, errors.Trace(err) 62 } 63 64 m[dbsSchemaVersion] = dbsInfo.SchemaVer 65 // TODO: Get the tenant information. 66 if len(dbsInfo.Jobs) == 0 { 67 return m, nil 68 } 69 // TODO: Add all job information if needed. 70 job := dbsInfo.Jobs[0] 71 m[dbsJobID] = job.ID 72 m[dbsJobCausetAction] = job.Type.String() 73 m[dbsJobStartTS] = job.StartTS / 1e9 // unit: second 74 m[dbsJobState] = job.State.String() 75 m[dbsJobRows] = job.RowCount 76 if job.Error == nil { 77 m[dbsJobError] = "" 78 } else { 79 m[dbsJobError] = job.Error.Error() 80 } 81 m[dbsJobSchemaState] = job.SchemaState.String() 82 m[dbsJobSchemaID] = job.SchemaID 83 m[dbsJobBlockID] = job.BlockID 84 m[dbsJobSnapshotVer] = job.SnapshotVer 85 m[dbsJobReorgHandle] = toString(dbsInfo.ReorgHandle) 86 m[dbsJobArgs] = job.Args 87 return m, nil 88 }