github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/db/operations.go (about) 1 // Copyright 2021 - 2022 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 db 16 17 import ( 18 "context" 19 "encoding/gob" 20 "time" 21 22 catalog2 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/catalog" 23 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/tasks" 24 25 "github.com/matrixorigin/matrixone/pkg/container/batch" 26 "github.com/matrixorigin/matrixone/pkg/container/types" 27 apipb "github.com/matrixorigin/matrixone/pkg/pb/api" 28 "github.com/matrixorigin/matrixone/pkg/vm/engine" 29 ) 30 31 const ( 32 OpPreCommit = uint32(apipb.OpCode_OpPreCommit) 33 OpGetLogTail = uint32(apipb.OpCode_OpGetLogTail) 34 ) 35 36 func init() { 37 38 // register TableDef types 39 gob.Register(new(engine.ViewDef)) 40 gob.Register(new(engine.CommentDef)) 41 gob.Register(new(engine.PartitionDef)) 42 gob.Register(new(engine.AttributeDef)) 43 gob.Register(new(engine.IndexTableDef)) 44 gob.Register(new(engine.PropertiesDef)) 45 gob.Register(new(engine.ConstraintDef)) 46 47 // register vector column types 48 gob.Register([]bool{}) 49 gob.Register([]int8{}) 50 gob.Register([]int16{}) 51 gob.Register([]int32{}) 52 gob.Register([]int64{}) 53 gob.Register([]uint8{}) 54 gob.Register([]uint16{}) 55 gob.Register([]uint32{}) 56 gob.Register([]uint64{}) 57 gob.Register([]float32{}) 58 gob.Register([]float64{}) 59 gob.Register([]string{}) 60 gob.Register([][]any{}) 61 gob.Register([]types.Date{}) 62 gob.Register([]types.Datetime{}) 63 gob.Register([]types.Timestamp{}) 64 gob.Register([]types.Decimal64{}) 65 gob.Register([]types.Decimal128{}) 66 67 //plan types 68 69 } 70 71 type Request interface { 72 CreateDatabaseReq | 73 DropDatabaseReq | 74 CreateRelationReq | 75 DropOrTruncateRelationReq | 76 UpdateConstraintReq | 77 WriteReq | 78 apipb.SyncLogTailReq 79 } 80 81 type Response interface { 82 CreateDatabaseResp | 83 DropDatabaseResp | 84 CreateRelationResp | 85 DropOrTruncateRelationResp | 86 UpdateConstraintResp | 87 WriteResp | 88 apipb.SyncLogTailResp 89 } 90 91 type RelationType uint8 92 93 const ( 94 RelationTable RelationType = iota + 1 95 RelationView 96 ) 97 98 type AccessInfo struct { 99 AccountID uint32 100 UserID uint32 101 RoleID uint32 102 } 103 104 type CreateDatabaseReq struct { 105 AccessInfo AccessInfo 106 Name string 107 CreateSql string 108 //Global unique, allocated by CN . 109 DatabaseId uint64 110 } 111 112 type FlushTable struct { 113 AccessInfo AccessInfo 114 DatabaseID uint64 115 TableID uint64 116 } 117 118 type Checkpoint struct { 119 FlushDuration time.Duration 120 } 121 122 type InspectDN struct { 123 AccessInfo AccessInfo 124 Operation string 125 } 126 127 type CreateDatabaseResp struct { 128 ID uint64 129 } 130 131 type DropDatabaseReq struct { 132 Name string 133 ID uint64 134 } 135 136 type DropDatabaseResp struct { 137 ID uint64 138 } 139 140 type CreateRelationReq struct { 141 AccessInfo AccessInfo 142 DatabaseID uint64 143 DatabaseName string 144 Name string 145 RelationId uint64 146 Type RelationType 147 Defs []engine.TableDef 148 } 149 150 type UpdateConstraintReq struct { 151 TableId uint64 152 TableName string 153 DatabaseId uint64 154 DatabaseName string 155 Constraint []byte 156 } 157 158 type UpdateConstraintResp struct{} 159 160 type CreateRelationResp struct { 161 ID uint64 162 } 163 164 type DropOrTruncateRelationReq struct { 165 IsDrop bool 166 DatabaseID uint64 167 DatabaseName string 168 Name string 169 ID uint64 170 NewId uint64 171 } 172 173 type DropOrTruncateRelationResp struct { 174 } 175 176 type EntryType int32 177 178 const ( 179 EntryInsert EntryType = 0 180 EntryDelete EntryType = 1 181 ) 182 183 type LocationKey struct{} 184 185 type WriteReq struct { 186 Type EntryType 187 DatabaseId uint64 188 TableID uint64 189 DatabaseName string 190 TableName string 191 Schema *catalog2.Schema 192 Batch *batch.Batch 193 //S3 object file name 194 FileName string 195 MetaLocs []string 196 //for delete on S3 197 DeltaLocs []string 198 //tasks for loading primary keys or deleted row ids 199 Jobs []*tasks.Job 200 //loaded sorted primary keys or deleted row ids. 201 JobRes []*tasks.JobResult 202 //load context cancel function 203 Cancel context.CancelFunc 204 } 205 206 type WriteResp struct { 207 } 208 209 type InspectResp struct { 210 Typ int `json:"-"` 211 Message string `json:"msg"` 212 Payload []byte `json:"-"` 213 } 214 215 const ( 216 InspectNormal = 0 217 InspectCata = 1 218 ) 219 220 func (r *InspectResp) GetResponse() any { 221 var ret any = r 222 switch r.Typ { 223 case InspectCata: 224 ret = new(CatalogResp) 225 types.Decode(r.Payload, ret) 226 } 227 return ret 228 } 229 230 type CatalogResp struct { 231 Item string `json:"Item,omitempty"` 232 Sub []*CatalogResp `json:"Sub,omitempty"` 233 }