mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
parent
5495497876
commit
c012902c16
|
@ -3,7 +3,7 @@ package command
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/chrislusf/seaweedfs/weed/storage/types"
|
||||
"github.com/chrislusf/seaweedfs/weed/udptransfer"
|
||||
"github.com/chrislusf/seaweedfs/weed/wdclient/penet"
|
||||
"net"
|
||||
"net/http"
|
||||
httppprof "net/http/pprof"
|
||||
|
@ -401,13 +401,7 @@ func (v VolumeServerOptions) startTcpService(volumeServer *weed_server.VolumeSer
|
|||
func (v VolumeServerOptions) startUdpService(volumeServer *weed_server.VolumeServer) {
|
||||
listeningAddress := *v.bindIp + ":" + strconv.Itoa(*v.port+20001)
|
||||
|
||||
listener, err := udptransfer.NewEndpoint(&udptransfer.Params{
|
||||
LocalAddr: listeningAddress,
|
||||
Bandwidth: 100,
|
||||
FastRetransmit: true,
|
||||
FlatTraffic: true,
|
||||
IsServ: true,
|
||||
})
|
||||
listener, err := penet.Listen("", listeningAddress)
|
||||
if err != nil {
|
||||
glog.Fatalf("Volume server listen on %s:%v", listeningAddress, err)
|
||||
}
|
||||
|
@ -416,7 +410,6 @@ func (v VolumeServerOptions) startUdpService(volumeServer *weed_server.VolumeSer
|
|||
for {
|
||||
conn, err := listener.Accept()
|
||||
if err == nil {
|
||||
glog.V(0).Infof("Client from %s", conn.RemoteAddr())
|
||||
go volumeServer.HandleUdpConnection(conn)
|
||||
} else if isTemporaryError(err) {
|
||||
continue
|
||||
|
|
|
@ -10,8 +10,6 @@ import (
|
|||
func (vs *VolumeServer) HandleUdpConnection(c net.Conn) {
|
||||
defer c.Close()
|
||||
|
||||
glog.V(0).Infof("Serving writes from %s", c.RemoteAddr().String())
|
||||
|
||||
bufReader := bufio.NewReaderSize(c, 1024*1024)
|
||||
bufWriter := bufio.NewWriterSize(c, 1024*1024)
|
||||
|
||||
|
@ -19,7 +17,7 @@ func (vs *VolumeServer) HandleUdpConnection(c net.Conn) {
|
|||
cmd, err := bufReader.ReadString('\n')
|
||||
if err != nil {
|
||||
if err != io.EOF {
|
||||
glog.Errorf("read command from %s: %v", c.RemoteAddr().String(), err)
|
||||
// glog.Errorf("read command from: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
1048
weed/wdclient/penet/penet.go
Normal file
1048
weed/wdclient/penet/penet.go
Normal file
File diff suppressed because it is too large
Load diff
|
@ -3,18 +3,22 @@ package wdclient
|
|||
import (
|
||||
"bufio"
|
||||
"github.com/chrislusf/seaweedfs/weed/pb"
|
||||
"github.com/chrislusf/seaweedfs/weed/udptransfer"
|
||||
"github.com/chrislusf/seaweedfs/weed/util"
|
||||
"github.com/chrislusf/seaweedfs/weed/wdclient/penet"
|
||||
"io"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
// VolumeUdpClient put/get/delete file chunks directly on volume servers without replication
|
||||
type VolumeUdpClient struct {
|
||||
Conn net.Conn
|
||||
bufWriter *bufio.Writer
|
||||
bufReader *bufio.Reader
|
||||
}
|
||||
|
||||
type VolumeUdpConn struct {
|
||||
net.Conn
|
||||
Conn net.Conn
|
||||
bufWriter *bufio.Writer
|
||||
bufReader *bufio.Reader
|
||||
}
|
||||
|
@ -30,41 +34,29 @@ func (c *VolumeUdpClient) PutFileChunk(volumeServerAddress string, fileId string
|
|||
return parseErr
|
||||
}
|
||||
|
||||
listener, err := udptransfer.NewEndpoint(&udptransfer.Params{
|
||||
LocalAddr: "",
|
||||
Bandwidth: 100,
|
||||
FastRetransmit: true,
|
||||
FlatTraffic: true,
|
||||
IsServ: false,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
if c.Conn == nil {
|
||||
c.Conn, err = penet.DialTimeout("", udpAddress, 500*time.Millisecond)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.bufWriter = bufio.NewWriter(c.Conn)
|
||||
}
|
||||
defer listener.Close()
|
||||
|
||||
conn, err := listener.Dial(udpAddress)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
bufWriter := bufio.NewWriter(conn)
|
||||
|
||||
buf := []byte("+" + fileId + "\n")
|
||||
_, err = bufWriter.Write([]byte(buf))
|
||||
_, err = c.bufWriter.Write([]byte(buf))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
util.Uint32toBytes(buf[0:4], fileSize)
|
||||
_, err = bufWriter.Write(buf[0:4])
|
||||
_, err = c.bufWriter.Write(buf[0:4])
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, err = io.Copy(bufWriter, fileReader)
|
||||
_, err = io.Copy(c.bufWriter, fileReader)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
bufWriter.Flush()
|
||||
c.bufWriter.Flush()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue