github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/process/types.go (about) 1 // Copyright 2021 Matrix Origin 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 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package process 16 17 import ( 18 "context" 19 "io" 20 "time" 21 22 "github.com/google/uuid" 23 "github.com/matrixorigin/matrixone/pkg/container/types" 24 "github.com/matrixorigin/matrixone/pkg/defines" 25 26 "github.com/matrixorigin/matrixone/pkg/common/morpc" 27 "github.com/matrixorigin/matrixone/pkg/common/mpool" 28 "github.com/matrixorigin/matrixone/pkg/container/batch" 29 "github.com/matrixorigin/matrixone/pkg/fileservice" 30 "github.com/matrixorigin/matrixone/pkg/txn/client" 31 "github.com/matrixorigin/matrixone/pkg/vm/engine" 32 ) 33 34 // Analyze analyzes information for operator 35 type Analyze interface { 36 Stop() 37 Start() 38 Alloc(int64) 39 Input(*batch.Batch, bool) 40 Output(*batch.Batch, bool) 41 WaitStop(time.Time) 42 DiskIO(*batch.Batch) 43 S3IOByte(*batch.Batch) 44 S3IOCount(int) 45 Network(*batch.Batch) 46 AddScanTime(t time.Time) 47 AddInsertTime(t time.Time) 48 } 49 50 // WaitRegister channel 51 type WaitRegister struct { 52 Ctx context.Context 53 Ch chan *batch.Batch 54 } 55 56 // Register used in execution pipeline and shared with all operators of the same pipeline. 57 type Register struct { 58 // Ss, temporarily stores the row number list in the execution of operators, 59 // and it can be reused in the future execution. 60 Ss [][]int64 61 // InputBatch, stores the result of the previous operator. 62 InputBatch *batch.Batch 63 // MergeReceivers, receives result of multi previous operators from other pipelines 64 // e.g. merge operator. 65 MergeReceivers []*WaitRegister 66 } 67 68 // Limitation specifies the maximum resources that can be used in one query. 69 type Limitation struct { 70 // Size, memory threshold for operator. 71 Size int64 72 // BatchRows, max rows for batch. 73 BatchRows int64 74 // BatchSize, max size for batch. 75 BatchSize int64 76 // PartitionRows, max rows for partition. 77 PartitionRows int64 78 // ReaderSize, memory threshold for storage's reader 79 ReaderSize int64 80 // MaxMessageSize max size for read messages from dn 81 MaxMsgSize uint64 82 } 83 84 // SessionInfo session information 85 type SessionInfo struct { 86 Account string 87 User string 88 Host string 89 Role string 90 ConnectionID uint64 91 AccountId uint32 92 RoleId uint32 93 UserId uint32 94 LastInsertID uint64 95 Database string 96 Version string 97 TimeZone *time.Location 98 StorageEngine engine.Engine 99 QueryId []string 100 ResultColTypes []types.Type 101 AutoIncrCaches defines.AutoIncrCaches 102 AutoIncrCacheSize uint64 103 } 104 105 // AnalyzeInfo analyze information for query 106 type AnalyzeInfo struct { 107 // NodeId, index of query's node list 108 NodeId int32 109 // InputRows, number of rows accepted by node 110 InputRows int64 111 // OutputRows, number of rows output by node 112 OutputRows int64 113 // TimeConsumed, time taken by the node in milliseconds 114 TimeConsumed int64 115 // WaitTimeConsumed, time taken by the node waiting for channel in milliseconds 116 WaitTimeConsumed int64 117 // InputSize, data size accepted by node 118 InputSize int64 119 // OutputSize, data size output by node 120 OutputSize int64 121 // MemorySize, memory alloc by node 122 MemorySize int64 123 // DiskIO, data size read from disk 124 DiskIO int64 125 // S3IOByte, data size read from s3 126 S3IOByte int64 127 // S3IOCount, query count that read from s3 128 S3IOCount int64 129 // NetworkIO, message size send between CN node 130 NetworkIO int64 131 // ScanTime, scan cost time in external scan 132 ScanTime int64 133 // InsertTime, insert cost time in load flow 134 InsertTime int64 135 } 136 137 // Process contains context used in query execution 138 // one or more pipeline will be generated for one query, 139 // and one pipeline has one process instance. 140 type Process struct { 141 // Id, query id. 142 Id string 143 Reg Register 144 Lim Limitation 145 146 mp *mpool.MPool 147 148 // unix timestamp 149 UnixTime int64 150 151 TxnClient client.TxnClient 152 153 TxnOperator client.TxnOperator 154 155 AnalInfos []*AnalyzeInfo 156 157 SessionInfo SessionInfo 158 159 Ctx context.Context 160 161 Cancel context.CancelFunc 162 163 FileService fileservice.FileService 164 165 GetClusterDetails engine.GetClusterDetailsFunc 166 167 LoadTag bool 168 169 LastInsertID *uint64 170 171 LoadLocalReader *io.PipeReader 172 173 DispatchNotifyCh chan WrapCs 174 } 175 176 type WrapCs struct { 177 MsgId uint64 178 Uid uuid.UUID 179 Cs morpc.ClientSession 180 DoneCh chan struct{} 181 } 182 183 func (proc *Process) SetLastInsertID(num uint64) { 184 if proc.LastInsertID != nil { 185 *proc.LastInsertID = num 186 } 187 } 188 189 func (proc *Process) GetLastInsertID() uint64 { 190 if proc.LastInsertID != nil { 191 return *proc.LastInsertID 192 } 193 return 0 194 } 195 196 type analyze struct { 197 start time.Time 198 wait time.Duration 199 analInfo *AnalyzeInfo 200 } 201 202 func (si *SessionInfo) GetUser() string { 203 return si.User 204 } 205 206 func (si *SessionInfo) GetHost() string { 207 return si.Host 208 } 209 210 func (si *SessionInfo) GetUserHost() string { 211 return si.User + "@" + si.Host 212 } 213 214 func (si *SessionInfo) GetRole() string { 215 return si.Role 216 } 217 218 func (si *SessionInfo) GetCharset() string { 219 return "utf8mb4" 220 } 221 222 func (si *SessionInfo) GetCollation() string { 223 return "utf8mb4_general_ci" 224 } 225 226 func (si *SessionInfo) GetConnectionID() uint64 { 227 return si.ConnectionID 228 } 229 230 func (si *SessionInfo) GetDatabase() string { 231 return si.Database 232 } 233 234 func (si *SessionInfo) GetVersion() string { 235 return si.Version 236 }