github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/entire_engine.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 engine 16 17 import ( 18 "context" 19 "strings" 20 21 "github.com/matrixorigin/matrixone/pkg/common/moerr" 22 "github.com/matrixorigin/matrixone/pkg/defines" 23 "github.com/matrixorigin/matrixone/pkg/pb/plan" 24 "github.com/matrixorigin/matrixone/pkg/pb/timestamp" 25 "github.com/matrixorigin/matrixone/pkg/txn/client" 26 ) 27 28 func GetTempTableName(DbName string, TblName string) string { 29 return strings.ReplaceAll(DbName, ".", "DOT") + "." + strings.ReplaceAll(TblName, ".", "DOT") 30 } 31 32 func (e *EntireEngine) New(ctx context.Context, op client.TxnOperator) error { 33 err := e.Engine.New(ctx, op) 34 if err == nil && e.TempEngine != nil { 35 return e.TempEngine.New(ctx, op) 36 } 37 return err 38 } 39 40 func (e *EntireEngine) Commit(ctx context.Context, op client.TxnOperator) error { 41 err := e.Engine.Commit(ctx, op) 42 if err == nil && e.TempEngine != nil { 43 return e.TempEngine.Commit(ctx, op) 44 } 45 return err 46 } 47 48 func (e *EntireEngine) Rollback(ctx context.Context, op client.TxnOperator) error { 49 err := e.Engine.Rollback(ctx, op) 50 if err == nil && e.TempEngine != nil { 51 return e.TempEngine.Rollback(ctx, op) 52 } 53 return err 54 } 55 56 func (e *EntireEngine) Delete(ctx context.Context, databaseName string, op client.TxnOperator) error { 57 return e.Engine.Delete(ctx, databaseName, op) 58 } 59 60 func (e *EntireEngine) Create(ctx context.Context, databaseName string, op client.TxnOperator) error { 61 return e.Engine.Create(ctx, databaseName, op) 62 } 63 64 func (e *EntireEngine) Databases(ctx context.Context, op client.TxnOperator) (databaseNames []string, err error) { 65 return e.Engine.Databases(ctx, op) 66 } 67 68 func (e *EntireEngine) Database(ctx context.Context, databaseName string, op client.TxnOperator) (Database, error) { 69 if databaseName == defines.TEMPORARY_DBNAME { 70 if e.TempEngine != nil { 71 return e.TempEngine.Database(ctx, defines.TEMPORARY_DBNAME, op) 72 } else { 73 return nil, moerr.NewInternalError(ctx, "temporary engine not init yet") 74 } 75 } 76 return e.Engine.Database(ctx, databaseName, op) 77 } 78 79 func (e *EntireEngine) Nodes() (cnNodes Nodes, err error) { 80 return e.Engine.Nodes() 81 } 82 83 func (e *EntireEngine) Hints() Hints { 84 return e.Engine.Hints() 85 } 86 87 func (e *EntireEngine) NewBlockReader(ctx context.Context, num int, ts timestamp.Timestamp, 88 expr *plan.Expr, ranges [][]byte, tblDef *plan.TableDef) ([]Reader, error) { 89 return e.Engine.NewBlockReader(ctx, num, ts, expr, ranges, tblDef) 90 } 91 92 func (e *EntireEngine) GetNameById(ctx context.Context, op client.TxnOperator, tableId uint64) (dbName string, tblName string, err error) { 93 return e.Engine.GetNameById(ctx, op, tableId) 94 } 95 96 func (e *EntireEngine) GetRelationById(ctx context.Context, op client.TxnOperator, tableId uint64) (dbName string, tblName string, rel Relation, err error) { 97 return e.Engine.GetRelationById(ctx, op, tableId) 98 }