2016-06-03 01:09:14 +00:00
|
|
|
package command
|
2012-08-07 08:29:22 +00:00
|
|
|
|
|
|
|
import (
|
2012-08-24 05:46:54 +00:00
|
|
|
"net/http"
|
2012-09-17 00:31:15 +00:00
|
|
|
"os"
|
2012-10-06 17:50:52 +00:00
|
|
|
"runtime"
|
2012-08-24 05:46:54 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"time"
|
2014-10-26 18:34:55 +00:00
|
|
|
|
2016-06-03 01:09:14 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/server"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
2012-08-07 08:29:22 +00:00
|
|
|
)
|
|
|
|
|
2015-01-13 08:27:51 +00:00
|
|
|
var (
|
|
|
|
v VolumeServerOptions
|
|
|
|
)
|
|
|
|
|
|
|
|
type VolumeServerOptions struct {
|
|
|
|
port *int
|
2015-03-09 08:10:01 +00:00
|
|
|
publicPort *int
|
2015-01-13 08:27:51 +00:00
|
|
|
folders []string
|
|
|
|
folderMaxLimits []int
|
|
|
|
ip *string
|
2015-02-02 23:51:25 +00:00
|
|
|
publicUrl *string
|
2015-01-13 08:27:51 +00:00
|
|
|
bindIp *string
|
|
|
|
master *string
|
|
|
|
pulseSeconds *int
|
|
|
|
idleConnectionTimeout *int
|
|
|
|
maxCpu *int
|
|
|
|
dataCenter *string
|
|
|
|
rack *string
|
|
|
|
whiteList []string
|
Add boltdb for volume needle map
boltdb is fairly slow to write, about 6 minutes for recreating index
for 1553934 files. Boltdb loads 1,553,934 x 16 = 24,862,944bytes from
disk, and generate the boltdb as large as 134,217,728 bytes in 6
minutes.
To compare, for leveldb, it recreates index in leveldb as large as
27,188,148 bytes in 8 seconds.
For in memory version, it loads the index in
To test the memory consumption, the leveldb or boltdb index are
created. And the server is restarted. Using the benchmark tool to read
lots of files. There are 7 volumes in benchmark collection, each with
about 1553K files.
For leveldb, the memory starts at 142,884KB, and stays at 179,340KB.
For boltdb, the memory starts at 73,756KB, and stays at 144,564KB.
For in-memory, the memory starts at 368,152KB, and stays at 448,032KB.
2015-03-29 18:04:32 +00:00
|
|
|
indexType *string
|
2015-01-13 08:27:51 +00:00
|
|
|
fixJpgOrientation *bool
|
2015-08-03 21:43:15 +00:00
|
|
|
readRedirect *bool
|
2016-11-16 15:09:57 +00:00
|
|
|
enableBytesCache *bool
|
2015-01-13 08:27:51 +00:00
|
|
|
}
|
|
|
|
|
2012-08-07 08:29:22 +00:00
|
|
|
func init() {
|
2012-08-24 05:46:54 +00:00
|
|
|
cmdVolume.Run = runVolume // break init cycle
|
2015-01-13 08:27:51 +00:00
|
|
|
v.port = cmdVolume.Flag.Int("port", 8080, "http listen port")
|
2015-03-09 08:10:01 +00:00
|
|
|
v.publicPort = cmdVolume.Flag.Int("port.public", 0, "port opened to public")
|
2015-01-13 08:27:51 +00:00
|
|
|
v.ip = cmdVolume.Flag.String("ip", "", "ip or server name")
|
2015-02-02 23:51:25 +00:00
|
|
|
v.publicUrl = cmdVolume.Flag.String("publicUrl", "", "Publicly accessible address")
|
2015-01-13 08:27:51 +00:00
|
|
|
v.bindIp = cmdVolume.Flag.String("ip.bind", "0.0.0.0", "ip address to bind to")
|
|
|
|
v.master = cmdVolume.Flag.String("mserver", "localhost:9333", "master server location")
|
|
|
|
v.pulseSeconds = cmdVolume.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats, must be smaller than or equal to the master's setting")
|
|
|
|
v.idleConnectionTimeout = cmdVolume.Flag.Int("idleTimeout", 10, "connection idle seconds")
|
|
|
|
v.maxCpu = cmdVolume.Flag.Int("maxCpu", 0, "maximum number of CPUs. 0 means all available CPUs")
|
|
|
|
v.dataCenter = cmdVolume.Flag.String("dataCenter", "", "current volume server's data center name")
|
|
|
|
v.rack = cmdVolume.Flag.String("rack", "", "current volume server's rack name")
|
Add boltdb for volume needle map
boltdb is fairly slow to write, about 6 minutes for recreating index
for 1553934 files. Boltdb loads 1,553,934 x 16 = 24,862,944bytes from
disk, and generate the boltdb as large as 134,217,728 bytes in 6
minutes.
To compare, for leveldb, it recreates index in leveldb as large as
27,188,148 bytes in 8 seconds.
For in memory version, it loads the index in
To test the memory consumption, the leveldb or boltdb index are
created. And the server is restarted. Using the benchmark tool to read
lots of files. There are 7 volumes in benchmark collection, each with
about 1553K files.
For leveldb, the memory starts at 142,884KB, and stays at 179,340KB.
For boltdb, the memory starts at 73,756KB, and stays at 144,564KB.
For in-memory, the memory starts at 368,152KB, and stays at 448,032KB.
2015-03-29 18:04:32 +00:00
|
|
|
v.indexType = cmdVolume.Flag.String("index", "memory", "Choose [memory|leveldb|boltdb] mode for memory~performance balance.")
|
2015-01-13 08:27:51 +00:00
|
|
|
v.fixJpgOrientation = cmdVolume.Flag.Bool("images.fix.orientation", true, "Adjust jpg orientation when uploading.")
|
2015-08-03 21:43:15 +00:00
|
|
|
v.readRedirect = cmdVolume.Flag.Bool("read.redirect", true, "Redirect moved or non-local volumes.")
|
2016-11-16 15:09:57 +00:00
|
|
|
v.enableBytesCache = cmdVolume.Flag.Bool("cache.enable", false, "direct cache instead of OS cache, cost more memory.")
|
2012-08-07 08:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var cmdVolume = &Command{
|
2012-09-26 08:55:56 +00:00
|
|
|
UsageLine: "volume -port=8080 -dir=/tmp -max=5 -ip=server_name -mserver=localhost:9333",
|
2012-08-24 05:46:54 +00:00
|
|
|
Short: "start a volume server",
|
|
|
|
Long: `start a volume server to provide storage spaces
|
2012-08-07 08:29:22 +00:00
|
|
|
|
|
|
|
`,
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2013-08-28 17:39:15 +00:00
|
|
|
volumeFolders = cmdVolume.Flag.String("dir", os.TempDir(), "directories to store data files. dir[,dir]...")
|
2013-08-13 16:22:06 +00:00
|
|
|
maxVolumeCounts = cmdVolume.Flag.String("max", "7", "maximum numbers of volumes, count[,count]...")
|
|
|
|
volumeWhiteListOption = cmdVolume.Flag.String("whiteList", "", "comma separated Ip addresses having write permission. No limit if empty.")
|
2012-08-07 08:29:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func runVolume(cmd *Command, args []string) bool {
|
2015-01-13 08:27:51 +00:00
|
|
|
if *v.maxCpu < 1 {
|
|
|
|
*v.maxCpu = runtime.NumCPU()
|
2012-11-07 09:51:43 +00:00
|
|
|
}
|
2015-01-13 08:27:51 +00:00
|
|
|
runtime.GOMAXPROCS(*v.maxCpu)
|
|
|
|
|
2015-01-13 08:36:44 +00:00
|
|
|
//Set multiple folders and each folder's max volume count limit'
|
2015-01-13 08:27:51 +00:00
|
|
|
v.folders = strings.Split(*volumeFolders, ",")
|
2013-07-13 18:38:01 +00:00
|
|
|
maxCountStrings := strings.Split(*maxVolumeCounts, ",")
|
|
|
|
for _, maxString := range maxCountStrings {
|
|
|
|
if max, e := strconv.Atoi(maxString); e == nil {
|
2015-01-13 08:27:51 +00:00
|
|
|
v.folderMaxLimits = append(v.folderMaxLimits, max)
|
2013-07-13 18:38:01 +00:00
|
|
|
} else {
|
2014-04-17 07:16:44 +00:00
|
|
|
glog.Fatalf("The max specified in -max not a valid number %s", maxString)
|
2013-07-13 18:38:01 +00:00
|
|
|
}
|
2012-09-17 00:31:15 +00:00
|
|
|
}
|
2015-01-13 08:27:51 +00:00
|
|
|
if len(v.folders) != len(v.folderMaxLimits) {
|
|
|
|
glog.Fatalf("%d directories by -dir, but only %d max is set by -max", len(v.folders), len(v.folderMaxLimits))
|
2013-07-13 18:38:01 +00:00
|
|
|
}
|
2015-01-13 08:27:51 +00:00
|
|
|
for _, folder := range v.folders {
|
2013-12-09 21:27:09 +00:00
|
|
|
if err := util.TestFolderWritable(folder); err != nil {
|
|
|
|
glog.Fatalf("Check Data Folder(-dir) Writable %s : %s", folder, err)
|
2013-07-13 18:38:01 +00:00
|
|
|
}
|
2012-09-17 00:31:15 +00:00
|
|
|
}
|
2015-01-13 08:36:44 +00:00
|
|
|
|
|
|
|
//security related white list configuration
|
2015-01-13 08:27:51 +00:00
|
|
|
if *volumeWhiteListOption != "" {
|
|
|
|
v.whiteList = strings.Split(*volumeWhiteListOption, ",")
|
|
|
|
}
|
2012-09-26 10:27:10 +00:00
|
|
|
|
2015-02-02 23:51:25 +00:00
|
|
|
if *v.ip == "" {
|
|
|
|
*v.ip = "127.0.0.1"
|
2012-09-26 09:29:16 +00:00
|
|
|
}
|
2012-09-20 09:11:08 +00:00
|
|
|
|
2015-03-09 08:10:01 +00:00
|
|
|
if *v.publicPort == 0 {
|
|
|
|
*v.publicPort = *v.port
|
2015-01-19 01:03:38 +00:00
|
|
|
}
|
2015-04-08 18:08:08 +00:00
|
|
|
if *v.publicUrl == "" {
|
|
|
|
*v.publicUrl = *v.ip + ":" + strconv.Itoa(*v.publicPort)
|
|
|
|
}
|
2015-03-09 08:10:01 +00:00
|
|
|
isSeperatedPublicPort := *v.publicPort != *v.port
|
2015-01-19 01:03:38 +00:00
|
|
|
|
2015-03-09 08:10:01 +00:00
|
|
|
volumeMux := http.NewServeMux()
|
|
|
|
publicVolumeMux := volumeMux
|
|
|
|
if isSeperatedPublicPort {
|
|
|
|
publicVolumeMux = http.NewServeMux()
|
2015-01-19 01:03:38 +00:00
|
|
|
}
|
2012-08-24 05:46:54 +00:00
|
|
|
|
Add boltdb for volume needle map
boltdb is fairly slow to write, about 6 minutes for recreating index
for 1553934 files. Boltdb loads 1,553,934 x 16 = 24,862,944bytes from
disk, and generate the boltdb as large as 134,217,728 bytes in 6
minutes.
To compare, for leveldb, it recreates index in leveldb as large as
27,188,148 bytes in 8 seconds.
For in memory version, it loads the index in
To test the memory consumption, the leveldb or boltdb index are
created. And the server is restarted. Using the benchmark tool to read
lots of files. There are 7 volumes in benchmark collection, each with
about 1553K files.
For leveldb, the memory starts at 142,884KB, and stays at 179,340KB.
For boltdb, the memory starts at 73,756KB, and stays at 144,564KB.
For in-memory, the memory starts at 368,152KB, and stays at 448,032KB.
2015-03-29 18:04:32 +00:00
|
|
|
volumeNeedleMapKind := storage.NeedleMapInMemory
|
|
|
|
switch *v.indexType {
|
|
|
|
case "leveldb":
|
|
|
|
volumeNeedleMapKind = storage.NeedleMapLevelDb
|
|
|
|
case "boltdb":
|
|
|
|
volumeNeedleMapKind = storage.NeedleMapBoltDb
|
|
|
|
}
|
2015-03-09 08:10:01 +00:00
|
|
|
volumeServer := weed_server.NewVolumeServer(volumeMux, publicVolumeMux,
|
|
|
|
*v.ip, *v.port, *v.publicUrl,
|
2015-01-19 01:03:38 +00:00
|
|
|
v.folders, v.folderMaxLimits,
|
Add boltdb for volume needle map
boltdb is fairly slow to write, about 6 minutes for recreating index
for 1553934 files. Boltdb loads 1,553,934 x 16 = 24,862,944bytes from
disk, and generate the boltdb as large as 134,217,728 bytes in 6
minutes.
To compare, for leveldb, it recreates index in leveldb as large as
27,188,148 bytes in 8 seconds.
For in memory version, it loads the index in
To test the memory consumption, the leveldb or boltdb index are
created. And the server is restarted. Using the benchmark tool to read
lots of files. There are 7 volumes in benchmark collection, each with
about 1553K files.
For leveldb, the memory starts at 142,884KB, and stays at 179,340KB.
For boltdb, the memory starts at 73,756KB, and stays at 144,564KB.
For in-memory, the memory starts at 368,152KB, and stays at 448,032KB.
2015-03-29 18:04:32 +00:00
|
|
|
volumeNeedleMapKind,
|
2015-01-13 08:27:51 +00:00
|
|
|
*v.master, *v.pulseSeconds, *v.dataCenter, *v.rack,
|
|
|
|
v.whiteList,
|
2015-08-03 21:43:15 +00:00
|
|
|
*v.fixJpgOrientation, *v.readRedirect,
|
2016-11-16 15:09:57 +00:00
|
|
|
*v.enableBytesCache,
|
2013-12-02 09:37:36 +00:00
|
|
|
)
|
2012-08-24 05:46:54 +00:00
|
|
|
|
2015-01-13 08:36:44 +00:00
|
|
|
listeningAddress := *v.bindIp + ":" + strconv.Itoa(*v.port)
|
2014-09-21 06:30:35 +00:00
|
|
|
glog.V(0).Infoln("Start Seaweed volume server", util.VERSION, "at", listeningAddress)
|
2015-01-13 08:27:51 +00:00
|
|
|
listener, e := util.NewListener(listeningAddress, time.Duration(*v.idleConnectionTimeout)*time.Second)
|
2012-08-24 05:46:54 +00:00
|
|
|
if e != nil {
|
2015-01-14 01:04:41 +00:00
|
|
|
glog.Fatalf("Volume server listener error:%v", e)
|
2014-03-20 18:07:15 +00:00
|
|
|
}
|
2015-03-09 08:10:01 +00:00
|
|
|
if isSeperatedPublicPort {
|
|
|
|
publicListeningAddress := *v.bindIp + ":" + strconv.Itoa(*v.publicPort)
|
|
|
|
glog.V(0).Infoln("Start Seaweed volume server", util.VERSION, "public at", publicListeningAddress)
|
|
|
|
publicListener, e := util.NewListener(publicListeningAddress, time.Duration(*v.idleConnectionTimeout)*time.Second)
|
2015-01-19 01:03:38 +00:00
|
|
|
if e != nil {
|
|
|
|
glog.Fatalf("Volume server listener error:%v", e)
|
|
|
|
}
|
|
|
|
go func() {
|
2015-03-09 08:10:01 +00:00
|
|
|
if e := http.Serve(publicListener, publicVolumeMux); e != nil {
|
|
|
|
glog.Fatalf("Volume server fail to serve public: %v", e)
|
2015-01-19 01:03:38 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
2014-03-20 18:07:15 +00:00
|
|
|
|
2014-05-13 22:04:04 +00:00
|
|
|
OnInterrupt(func() {
|
|
|
|
volumeServer.Shutdown()
|
|
|
|
})
|
2014-05-13 07:04:28 +00:00
|
|
|
|
2015-03-09 08:10:01 +00:00
|
|
|
if e := http.Serve(listener, volumeMux); e != nil {
|
2015-01-14 01:04:41 +00:00
|
|
|
glog.Fatalf("Volume server fail to serve: %v", e)
|
2012-08-24 05:46:54 +00:00
|
|
|
}
|
|
|
|
return true
|
2012-08-07 08:29:22 +00:00
|
|
|
}
|