mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 02:00:56 +00:00
enhance: support to bind target ip when start start service
Signed-off-by: Victor1319 <834863182@qq.com>
This commit is contained in:
parent
699bee6d52
commit
abe516dbfc
@ -147,7 +147,7 @@ func (dp *DataPartition) HandleLeaderChange(leader uint64) {
|
||||
}
|
||||
}()
|
||||
if dp.config.NodeID == leader {
|
||||
conn, err := net.DialTimeout("tcp", net.JoinHostPort("127.0.0.1", serverPort), time.Second)
|
||||
conn, err := net.DialTimeout("tcp", net.JoinHostPort(LocalIP, serverPort), time.Second)
|
||||
if err != nil {
|
||||
log.LogErrorf(fmt.Sprintf("HandleLeaderChange PartitionID(%v) serverPort not exsit ,error %v", dp.partitionID, err))
|
||||
go dp.raftPartition.TryToLeader(dp.partitionID)
|
||||
|
||||
@ -551,7 +551,7 @@ func (s *DataNode) registerHandler() {
|
||||
|
||||
func (s *DataNode) startTCPService() (err error) {
|
||||
log.LogInfo("Start: startTCPService")
|
||||
addr := fmt.Sprintf(":%v", s.port)
|
||||
addr := fmt.Sprintf("%s:%v", LocalIP, s.port)
|
||||
l, err := net.Listen(NetworkProtocol, addr)
|
||||
log.LogDebugf("action[startTCPService] listen %v address(%v).", NetworkProtocol, addr)
|
||||
if err != nil {
|
||||
@ -595,7 +595,7 @@ func (s *DataNode) serveConn(conn net.Conn) {
|
||||
|
||||
func (s *DataNode) startSmuxService(cfg *config.Config) (err error) {
|
||||
log.LogInfo("Start: startSmuxService")
|
||||
addr := fmt.Sprintf(":%v", s.port)
|
||||
addr := fmt.Sprintf("%s:%v", LocalIP, s.port)
|
||||
addr = util.ShiftAddrPort(addr, s.smuxPortShift)
|
||||
log.LogInfof("SmuxListenAddr: (%v)", addr)
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ func (m *Server) startHTTPService(modulename string, cfg *config.Config) {
|
||||
m.registerAPIMiddleware(router)
|
||||
exporter.InitWithRouter(modulename, cfg, router, m.port)
|
||||
var server = &http.Server{
|
||||
Addr: colonSplit + m.port,
|
||||
Addr: fmt.Sprintf("%s:%s", m.ip, m.port),
|
||||
Handler: router,
|
||||
}
|
||||
var serveAPI = func() {
|
||||
|
||||
@ -25,6 +25,8 @@ import (
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/cubefs/cubefs/util/stat"
|
||||
|
||||
"github.com/cubefs/cubefs/proto"
|
||||
"github.com/cubefs/cubefs/raftstore"
|
||||
"github.com/cubefs/cubefs/util/config"
|
||||
@ -215,9 +217,9 @@ func (m *Server) checkConfig(cfg *config.Config) (err error) {
|
||||
m.servicePath = cfg.GetString(EbsServicePathKey)
|
||||
}
|
||||
peerAddrs := cfg.GetString(cfgPeers)
|
||||
if m.ip == "" || m.port == "" || m.walDir == "" || m.storeDir == "" || m.clusterName == "" || peerAddrs == "" {
|
||||
return fmt.Errorf("%v,err:%v,%v,%v,%v,%v,%v,%v", proto.ErrInvalidCfg, "one of (ip,listen,walDir,storeDir,clusterName) is null",
|
||||
m.ip, m.port, m.walDir, m.storeDir, m.clusterName, peerAddrs)
|
||||
if m.port == "" || m.walDir == "" || m.storeDir == "" || m.clusterName == "" || peerAddrs == "" {
|
||||
return fmt.Errorf("%v,err:%v,%v,%v,%v,%v,%v", proto.ErrInvalidCfg, "one of (listen,walDir,storeDir,clusterName) is null",
|
||||
m.port, m.walDir, m.storeDir, m.clusterName, peerAddrs)
|
||||
}
|
||||
|
||||
if m.id, err = strconv.ParseUint(cfg.GetString(ID), 10, 64); err != nil {
|
||||
@ -321,6 +323,7 @@ func (m *Server) createRaftServer(cfg *config.Config) (err error) {
|
||||
raftCfg := &raftstore.Config{
|
||||
NodeID: m.id,
|
||||
RaftPath: m.walDir,
|
||||
IPAddr: cfg.GetString(IP),
|
||||
NumOfLogsToRetain: m.retainLogs,
|
||||
HeartbeatPort: int(m.config.heartbeatPort),
|
||||
ReplicaPort: int(m.config.replicaPort),
|
||||
|
||||
@ -15,8 +15,9 @@
|
||||
package metanode
|
||||
|
||||
import (
|
||||
"github.com/cubefs/cubefs/util/btree"
|
||||
"sync"
|
||||
|
||||
"github.com/cubefs/cubefs/util/btree"
|
||||
)
|
||||
|
||||
const defaultBTreeDegree = 32
|
||||
|
||||
@ -396,7 +396,12 @@ func (mp *metaPartition) HandleFatalEvent(err *raft.FatalError) {
|
||||
func (mp *metaPartition) HandleLeaderChange(leader uint64) {
|
||||
exporter.Warning(fmt.Sprintf("metaPartition(%v) changeLeader to (%v)", mp.config.PartitionId, leader))
|
||||
if mp.config.NodeId == leader {
|
||||
conn, err := net.DialTimeout("tcp", net.JoinHostPort("127.0.0.1", serverPort), time.Second)
|
||||
localIp := mp.manager.metaNode.localAddr
|
||||
if localIp == "" {
|
||||
localIp = "127.0.0.1"
|
||||
}
|
||||
|
||||
conn, err := net.DialTimeout("tcp", net.JoinHostPort(localIp, serverPort), time.Second)
|
||||
if err != nil {
|
||||
log.LogErrorf(fmt.Sprintf("HandleLeaderChange serverPort not exsit ,error %v", err))
|
||||
go mp.raftPartition.TryToLeader(mp.config.PartitionId)
|
||||
|
||||
@ -37,6 +37,7 @@ func NewInodeResponse() *InodeResponse {
|
||||
// Create and inode and attach it to the inode tree.
|
||||
func (mp *metaPartition) fsmCreateInode(ino *Inode) (status uint8) {
|
||||
status = proto.OpOk
|
||||
log.LogDebugf("execute fsmCreateInode to create ino, %v", ino.Inode)
|
||||
if _, ok := mp.inodeTree.ReplaceOrInsert(ino, false); !ok {
|
||||
status = proto.OpExistErr
|
||||
}
|
||||
|
||||
@ -15,11 +15,13 @@
|
||||
package metanode
|
||||
|
||||
import (
|
||||
"github.com/cubefs/cubefs/util"
|
||||
"github.com/xtaci/smux"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
|
||||
"github.com/cubefs/cubefs/util"
|
||||
"github.com/xtaci/smux"
|
||||
|
||||
"github.com/cubefs/cubefs/proto"
|
||||
"github.com/cubefs/cubefs/util/log"
|
||||
)
|
||||
@ -28,7 +30,8 @@ import (
|
||||
func (m *MetaNode) startServer() (err error) {
|
||||
// initialize and start the server.
|
||||
m.httpStopC = make(chan uint8)
|
||||
ln, err := net.Listen("tcp", ":"+m.listen)
|
||||
addr := fmt.Sprintf("%s:%s", m.localAddr, m.listen)
|
||||
ln, err := net.Listen("tcp", addr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -102,7 +105,8 @@ func (m *MetaNode) handlePacket(conn net.Conn, p *Packet,
|
||||
func (m *MetaNode) startSmuxServer() (err error) {
|
||||
// initialize and start the server.
|
||||
m.smuxStopC = make(chan uint8)
|
||||
addr := util.ShiftAddrPort(":"+m.listen, smuxPortShift)
|
||||
ipPort := fmt.Sprintf("%s:%s", m.localAddr, m.listen)
|
||||
addr := util.ShiftAddrPort(ipPort, smuxPortShift)
|
||||
ln, err := net.Listen("tcp", addr)
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
Loading…
Reference in New Issue
Block a user