aboutsummaryrefslogtreecommitdiff
path: root/weed/command/volume.go
diff options
context:
space:
mode:
Diffstat (limited to 'weed/command/volume.go')
-rw-r--r--weed/command/volume.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/weed/command/volume.go b/weed/command/volume.go
index 9d665d143..8caa8d92f 100644
--- a/weed/command/volume.go
+++ b/weed/command/volume.go
@@ -50,6 +50,7 @@ type VolumeServerOptions struct {
memProfile *string
compactionMBPerSecond *int
fileSizeLimitMB *int
+ enableTcp *bool // temporary toggle
}
func init() {
@@ -71,6 +72,7 @@ func init() {
v.memProfile = cmdVolume.Flag.String("memprofile", "", "memory profile output file")
v.compactionMBPerSecond = cmdVolume.Flag.Int("compactionMBps", 0, "limit background compaction or copying speed in mega bytes per second")
v.fileSizeLimitMB = cmdVolume.Flag.Int("fileSizeLimitMB", 256, "limit file size to avoid out of memory")
+ v.enableTcp = cmdVolume.Flag.Bool("enableTcp", false, "[experimental] toggle tcp port, running on 20000 + port")
}
var cmdVolume = &Command{
@@ -168,6 +170,10 @@ func (v VolumeServerOptions) startVolumeServer(volumeFolders, maxVolumeCounts, v
// starting grpc server
grpcS := v.startGrpcService(volumeServer)
+ if v.enableTcp != nil && *v.enableTcp {
+ go v.startTcpServer(volumeServer)
+ }
+
// starting public http server
var publicHttpDown httpdown.Server
if v.isSeparatedPublicPort() {
@@ -245,6 +251,32 @@ func (v VolumeServerOptions) startGrpcService(vs volume_server_pb.VolumeServerSe
return grpcS
}
+func (v VolumeServerOptions) startTcpServer(vs *weed_server.VolumeServer) {
+ tcpPort := *v.port + 20000
+ tcpL, err := util.NewListener(*v.bindIp+":"+strconv.Itoa(tcpPort), 0)
+ if err != nil {
+ glog.Fatalf("failed to listen on tcp port %d: %v", tcpPort, err)
+ }
+ defer tcpL.Close()
+
+ for {
+ c, err := tcpL.Accept()
+ if err!= nil {
+ glog.V(0).Infof("accept tcp connection: %v", err)
+ continue
+ }
+ go func() {
+ for {
+ if err := vs.HandleTcpConnection(c); err != nil {
+ glog.V(0).Infof("handle tcp remote %s: %v", c.RemoteAddr(), err)
+ return
+ }
+ }
+
+ }()
+ }
+}
+
func (v VolumeServerOptions) startPublicHttpService(handler http.Handler) httpdown.Server {
publicListeningAddress := *v.bindIp + ":" + strconv.Itoa(*v.publicPort)
glog.V(0).Infoln("Start Seaweed volume server", util.VERSION, "public at", publicListeningAddress)