github.com/KinWaiYuen/client-go/v2@v2.5.4/tikvrpc/endpoint.go (about) 1 // Copyright 2021 TiKV Authors 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 // NOTE: The code in this file is based on code from the 16 // TiDB project, licensed under the Apache License v 2.0 17 // 18 // https://github.com/pingcap/tidb/tree/cc5e161ac06827589c4966674597c137cc9e809c/store/tikv/tikvrpc/endpoint.go 19 // 20 21 // Copyright 2021 PingCAP, Inc. 22 // 23 // Licensed under the Apache License, Version 2.0 (the "License"); 24 // you may not use this file except in compliance with the License. 25 // You may obtain a copy of the License at 26 // 27 // http://www.apache.org/licenses/LICENSE-2.0 28 // 29 // Unless required by applicable law or agreed to in writing, software 30 // distributed under the License is distributed on an "AS IS" BASIS, 31 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 32 // See the License for the specific language governing permissions and 33 // limitations under the License. 34 35 package tikvrpc 36 37 import "github.com/pingcap/kvproto/pkg/metapb" 38 39 // EndpointType represents the type of a remote endpoint.. 40 type EndpointType uint8 41 42 // EndpointType type enums. 43 const ( 44 TiKV EndpointType = iota 45 TiFlash 46 TiDB 47 ) 48 49 // Name returns the name of endpoint type. 50 func (t EndpointType) Name() string { 51 switch t { 52 case TiKV: 53 return "tikv" 54 case TiFlash: 55 return "tiflash" 56 case TiDB: 57 return "tidb" 58 } 59 return "unspecified" 60 } 61 62 // Constants to determine engine type. 63 // They should be synced with PD. 64 const ( 65 engineLabelKey = "engine" 66 engineLabelTiFlash = "tiflash" 67 ) 68 69 // GetStoreTypeByMeta gets store type by store meta pb. 70 func GetStoreTypeByMeta(store *metapb.Store) EndpointType { 71 for _, label := range store.Labels { 72 if label.Key == engineLabelKey && label.Value == engineLabelTiFlash { 73 return TiFlash 74 } 75 } 76 return TiKV 77 }