github.com/matrixorigin/matrixone@v0.7.0/pkg/txn/storage/tae/storage_debug.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 taestorage 16 17 import ( 18 "context" 19 20 "github.com/fagongzi/util/protoc" 21 "github.com/matrixorigin/matrixone/pkg/common/moerr" 22 "github.com/matrixorigin/matrixone/pkg/container/types" 23 "github.com/matrixorigin/matrixone/pkg/pb/ctl" 24 "github.com/matrixorigin/matrixone/pkg/pb/txn" 25 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/db" 26 ) 27 28 func (s *taeStorage) Debug(ctx context.Context, 29 txnMeta txn.TxnMeta, 30 opCode uint32, 31 data []byte) ([]byte, error) { 32 switch opCode { 33 case uint32(ctl.CmdMethod_Ping): 34 return s.handlePing(data), nil 35 case uint32(ctl.CmdMethod_Flush): 36 _, err := handleRead( 37 ctx, s, 38 txnMeta, data, 39 s.taeHandler.HandleFlushTable, 40 ) 41 if err != nil { 42 resp := protoc.MustMarshal(&ctl.DNStringResponse{ 43 ReturnStr: "Failed", 44 }) 45 return resp, err 46 } 47 resp := protoc.MustMarshal(&ctl.DNStringResponse{ 48 ReturnStr: "OK", 49 }) 50 return resp, err 51 case uint32(ctl.CmdMethod_Checkpoint): 52 _, err := handleRead( 53 ctx, s, txnMeta, data, s.taeHandler.HandleForceCheckpoint, 54 ) 55 if err != nil { 56 resp := protoc.MustMarshal(&ctl.DNStringResponse{ 57 ReturnStr: "Failed", 58 }) 59 return resp, err 60 } 61 resp := protoc.MustMarshal(&ctl.DNStringResponse{ 62 ReturnStr: "OK", 63 }) 64 return resp, err 65 66 case uint32(ctl.CmdMethod_Inspect): 67 resp, err := handleRead( 68 ctx, s, txnMeta, data, s.taeHandler.HandleInspectDN, 69 ) 70 if err != nil { 71 return types.Encode(&db.InspectResp{ 72 Message: "Failed", 73 }) 74 } 75 return resp.Read() 76 default: 77 return nil, moerr.NewNotSupportedNoCtx("TAEStorage not support ctl method %d", opCode) 78 } 79 } 80 81 func (s *taeStorage) handlePing(data []byte) []byte { 82 req := ctl.DNPingRequest{} 83 protoc.MustUnmarshal(&req, data) 84 85 return protoc.MustMarshal(&ctl.DNPingResponse{ 86 ShardID: s.shard.ShardID, 87 ReplicaID: s.shard.ReplicaID, 88 LogShardID: s.shard.LogShardID, 89 ServiceAddress: s.shard.Address, 90 }) 91 }