github.com/matrixorigin/matrixone@v1.2.0/pkg/tnservice/service_ports.go (about) 1 // Copyright 2021 - 2023 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 tnservice 16 17 type PortSlot int 18 19 // New service should add before the last one. 20 const ( 21 TxnService PortSlot = iota 22 LogtailService 23 LockService 24 QueryService 25 MaxService 26 ) 27 28 // String implements the fmt.Stringer interface. 29 func (s PortSlot) String() string { 30 switch s { 31 case TxnService: 32 return "Txn service" 33 case LogtailService: 34 return "Logtail service" 35 case LockService: 36 return "Lock service" 37 case QueryService: 38 return "Query service" 39 default: 40 return "Unknown service" 41 } 42 } 43 44 // newPortStrategy returns true only if the port-base is not configured. 45 func (s *store) newPortStrategy() bool { 46 return s.cfg.PortBase != 0 47 } 48 49 func (s *store) registerServices() { 50 for slot := 0; slot < int(MaxService); slot++ { 51 s.addressMgr.Register(slot) 52 } 53 } 54 55 // The following methods mainly consider configuration compatibility. 56 // If there are no compatibility issues anymore, the methods could 57 // be removed. 58 func (s *store) txnServiceServiceAddr() string { 59 if s.newPortStrategy() { 60 return s.addressMgr.ServiceAddress(int(TxnService)) 61 } 62 return s.cfg.ServiceAddress 63 } 64 65 func (s *store) txnServiceListenAddr() string { 66 if s.newPortStrategy() { 67 return s.addressMgr.ListenAddress(int(TxnService)) 68 } 69 return s.cfg.ListenAddress 70 } 71 72 func (s *store) logtailServiceServiceAddr() string { 73 if s.newPortStrategy() { 74 return s.addressMgr.ServiceAddress(int(LogtailService)) 75 } 76 return s.cfg.LogtailServer.ServiceAddress 77 } 78 79 func (s *store) logtailServiceListenAddr() string { 80 if s.newPortStrategy() { 81 return s.addressMgr.ListenAddress(int(LogtailService)) 82 } 83 return s.cfg.LogtailServer.ListenAddress 84 } 85 86 func (s *store) lockServiceServiceAddr() string { 87 if s.newPortStrategy() { 88 return s.addressMgr.ServiceAddress(int(LockService)) 89 } 90 return s.cfg.LockService.ServiceAddress 91 } 92 93 func (s *store) lockServiceListenAddr() string { 94 if s.newPortStrategy() { 95 return s.addressMgr.ListenAddress(int(LockService)) 96 } 97 return s.cfg.LockService.ListenAddress 98 } 99 100 func (s *store) queryServiceServiceAddr() string { 101 if s.newPortStrategy() { 102 return s.addressMgr.ServiceAddress(int(QueryService)) 103 } 104 return "" 105 } 106 107 func (s *store) queryServiceListenAddr() string { 108 if s.newPortStrategy() { 109 return s.addressMgr.ListenAddress(int(QueryService)) 110 } 111 return "" 112 }