github.com/matrixorigin/matrixone@v1.2.0/pkg/cnservice/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 cnservice 16 17 type PortSlot int 18 19 // New service should add before the last one. 20 const ( 21 PipelineService PortSlot = iota 22 LockService 23 QueryService 24 Gossip 25 MaxService 26 ) 27 28 // String implements the fmt.Stringer interface. 29 func (s PortSlot) String() string { 30 switch s { 31 case PipelineService: 32 return "Pipeline service" 33 case LockService: 34 return "Lock service" 35 case QueryService: 36 return "Query service" 37 case Gossip: 38 return "Gossip" 39 default: 40 return "Unknown service" 41 } 42 } 43 44 // newPortStrategy returns true only if the port-base is not configured. 45 func (s *service) newPortStrategy() bool { 46 return s.cfg.PortBase != 0 47 } 48 49 func (s *service) 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 *service) pipelineServiceServiceAddr() string { 59 if s.newPortStrategy() { 60 return s.addressMgr.ServiceAddress(int(PipelineService)) 61 } 62 return s.cfg.ServiceAddress 63 } 64 65 func (s *service) pipelineServiceListenAddr() string { 66 if s.newPortStrategy() { 67 return s.addressMgr.ListenAddress(int(PipelineService)) 68 } 69 return s.cfg.ListenAddress 70 } 71 72 func (s *service) lockServiceServiceAddr() string { 73 if s.newPortStrategy() { 74 return s.addressMgr.ServiceAddress(int(LockService)) 75 } 76 return s.cfg.LockService.ServiceAddress 77 } 78 79 func (s *service) lockServiceListenAddr() string { 80 if s.newPortStrategy() { 81 return s.addressMgr.ListenAddress(int(LockService)) 82 } 83 return s.cfg.LockService.ListenAddress 84 } 85 86 func (s *service) queryServiceServiceAddr() string { 87 if s.newPortStrategy() { 88 return s.addressMgr.ServiceAddress(int(QueryService)) 89 } 90 return s.cfg.QueryServiceConfig.Address.ServiceAddress 91 } 92 93 func (s *service) queryServiceListenAddr() string { 94 if s.newPortStrategy() { 95 return s.addressMgr.ListenAddress(int(QueryService)) 96 } 97 return s.cfg.QueryServiceConfig.Address.ListenAddress 98 } 99 100 func (s *service) gossipServiceAddr() string { 101 if s.newPortStrategy() { 102 return s.addressMgr.ServiceAddress(int(Gossip)) 103 } 104 return "" 105 } 106 107 func (s *service) gossipListenAddr() string { 108 if s.newPortStrategy() { 109 return s.addressMgr.ListenAddress(int(Gossip)) 110 } 111 return "" 112 }