github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/plan/function/builtin/multi/faultinj.go (about) 1 // Copyright 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 multi 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/common/moerr" 19 "github.com/matrixorigin/matrixone/pkg/container/types" 20 "github.com/matrixorigin/matrixone/pkg/container/vector" 21 "github.com/matrixorigin/matrixone/pkg/util/fault" 22 "github.com/matrixorigin/matrixone/pkg/vm/process" 23 ) 24 25 func EnableFaultInjection(vecs []*vector.Vector, proc *process.Process) (*vector.Vector, error) { 26 fault.Enable() 27 return proc.AllocBoolScalarVector(true), nil 28 } 29 30 func DisableFaultInjection(vecs []*vector.Vector, proc *process.Process) (*vector.Vector, error) { 31 fault.Disable() 32 return proc.AllocBoolScalarVector(true), nil 33 } 34 35 func AddFaultPoint(vecs []*vector.Vector, proc *process.Process) (*vector.Vector, error) { 36 for i := 0; i < 5; i++ { 37 if vecs[i].IsScalarNull() || !vecs[i].IsScalar() { 38 return nil, moerr.NewInvalidArg(proc.Ctx, "AddFaultPoint", "not scalar") 39 } 40 } 41 42 name := vecs[0].GetString(0) 43 freq := vecs[1].GetString(0) 44 action := vecs[2].GetString(0) 45 iarg := vector.GetValueAt[int64](vecs[3], 0) 46 sarg := vecs[4].GetString(0) 47 48 if err := fault.AddFaultPoint(proc.Ctx, name, freq, action, iarg, sarg); err != nil { 49 return nil, err 50 } 51 52 return proc.AllocBoolScalarVector(true), nil 53 } 54 55 func RemoveFaultPoint(vecs []*vector.Vector, proc *process.Process) (*vector.Vector, error) { 56 if vecs[0].IsScalarNull() || !vecs[0].IsScalar() { 57 return nil, moerr.NewInvalidArg(proc.Ctx, "RemoveFaultPoint", "not scalar") 58 } 59 60 name := vecs[0].GetString(0) 61 if err := fault.RemoveFaultPoint(proc.Ctx, name); err != nil { 62 return nil, err 63 } 64 return proc.AllocBoolScalarVector(true), nil 65 } 66 67 func TriggerFaultPoint(vecs []*vector.Vector, proc *process.Process) (*vector.Vector, error) { 68 if vecs[0].IsScalarNull() || !vecs[0].IsScalar() { 69 return nil, moerr.NewInvalidArg(proc.Ctx, "TriggerFaultPoint", "not scalar") 70 } 71 72 name := vecs[0].GetString(0) 73 iv, _, ok := fault.TriggerFault(name) 74 if !ok { 75 return proc.AllocScalarNullVector(types.T_int64.ToType()), nil 76 } 77 return proc.AllocInt64ScalarVector(iv), nil 78 }