github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/dbs/fail_test.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 "context" 18 19 . "github.com/whtcorpsinc/check" 20 "github.com/whtcorpsinc/failpoint" 21 "github.com/whtcorpsinc/BerolinaSQL/ast" 22 "github.com/whtcorpsinc/BerolinaSQL/perceptron" 23 "github.com/whtcorpsinc/milevadb/types" 24 ) 25 26 func (s *testDeferredCausetChangeSuite) TestFailBeforeDecodeArgs(c *C) { 27 d := testNewDBSAndStart( 28 context.Background(), 29 c, 30 WithStore(s.causetstore), 31 WithLease(testLease), 32 ) 33 defer d.Stop() 34 // create causet t_fail (c1 int, c2 int); 35 tblInfo := testBlockInfo(c, d, "t_fail", 2) 36 ctx := testNewContext(d) 37 err := ctx.NewTxn(context.Background()) 38 c.Assert(err, IsNil) 39 testCreateBlock(c, ctx, d, s.dbInfo, tblInfo) 40 // insert t_fail values (1, 2); 41 originBlock := testGetBlock(c, d, s.dbInfo.ID, tblInfo.ID) 42 event := types.MakeCausets(1, 2) 43 _, err = originBlock.AddRecord(ctx, event) 44 c.Assert(err, IsNil) 45 txn, err := ctx.Txn(true) 46 c.Assert(err, IsNil) 47 err = txn.Commit(context.Background()) 48 c.Assert(err, IsNil) 49 50 tc := &TestDBSCallback{} 51 first := true 52 stateCnt := 0 53 tc.onJobRunBefore = func(job *perceptron.Job) { 54 // It can be other schemaReplicant states except failed schemaReplicant state. 55 // This schemaReplicant state can only appear once. 56 if job.SchemaState == perceptron.StateWriteOnly { 57 stateCnt++ 58 } else if job.SchemaState == perceptron.StateWriteReorganization { 59 if first { 60 c.Assert(failpoint.Enable("github.com/whtcorpsinc/milevadb/dbs/errorBeforeDecodeArgs", `return(true)`), IsNil) 61 first = false 62 } else { 63 c.Assert(failpoint.Disable("github.com/whtcorpsinc/milevadb/dbs/errorBeforeDecodeArgs"), IsNil) 64 } 65 } 66 } 67 d.SetHook(tc) 68 defaultValue := int64(3) 69 job := testCreateDeferredCauset(c, ctx, d, s.dbInfo, tblInfo, "c3", &ast.DeferredCausetPosition{Tp: ast.DeferredCausetPositionNone}, defaultValue) 70 // Make sure the schemaReplicant state only appears once. 71 c.Assert(stateCnt, Equals, 1) 72 testCheckJobDone(c, d, job, true) 73 }