mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
fixing help message printing
This commit is contained in:
parent
a56a523f29
commit
03aa23fb1b
|
@ -38,7 +38,10 @@ func (c *Command) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Command) Usage() {
|
func (c *Command) Usage() {
|
||||||
fmt.Fprintf(os.Stderr, "Usage: %s\n", c.UsageLine)
|
fmt.Fprintf(os.Stderr, "Example: weed %s\n", c.UsageLine)
|
||||||
|
fmt.Fprintf(os.Stderr, "Default Usage:\n")
|
||||||
|
c.Flag.PrintDefaults()
|
||||||
|
fmt.Fprintf(os.Stderr, "Description:\n")
|
||||||
fmt.Fprintf(os.Stderr, " %s\n", strings.TrimSpace(c.Long))
|
fmt.Fprintf(os.Stderr, " %s\n", strings.TrimSpace(c.Long))
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"pkg/storage"
|
"pkg/storage"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -30,6 +31,7 @@ var (
|
||||||
capacity = cmdMaster.Flag.Int("capacity", 100, "maximum number of volumes to hold")
|
capacity = cmdMaster.Flag.Int("capacity", 100, "maximum number of volumes to hold")
|
||||||
mapper *directory.Mapper
|
mapper *directory.Mapper
|
||||||
volumeSizeLimitMB = cmdMaster.Flag.Uint("volumeSizeLimitMB", 32*1024, "Default Volume Size in MegaBytes")
|
volumeSizeLimitMB = cmdMaster.Flag.Uint("volumeSizeLimitMB", 32*1024, "Default Volume Size in MegaBytes")
|
||||||
|
mpulse = cmdMaster.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats")
|
||||||
)
|
)
|
||||||
|
|
||||||
func dirLookupHandler(w http.ResponseWriter, r *http.Request) {
|
func dirLookupHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -64,7 +66,7 @@ func dirJoinHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if *IsDebug {
|
if *IsDebug {
|
||||||
log.Println(s, "volumes", r.FormValue("volumes"))
|
log.Println(s, "volumes", r.FormValue("volumes"))
|
||||||
}
|
}
|
||||||
mapper.Add(directory.NewMachine(s, publicUrl, *volumes))
|
mapper.Add(directory.NewMachine(s, publicUrl, *volumes, time.Now().Unix()))
|
||||||
}
|
}
|
||||||
func dirStatusHandler(w http.ResponseWriter, r *http.Request) {
|
func dirStatusHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
writeJson(w, r, mapper)
|
writeJson(w, r, mapper)
|
||||||
|
@ -72,7 +74,7 @@ func dirStatusHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func runMaster(cmd *Command, args []string) bool {
|
func runMaster(cmd *Command, args []string) bool {
|
||||||
log.Println("Volume Size Limit is", *volumeSizeLimitMB, "MB")
|
log.Println("Volume Size Limit is", *volumeSizeLimitMB, "MB")
|
||||||
mapper = directory.NewMapper(*metaFolder, "directory", uint64(*volumeSizeLimitMB)*1024*1024)
|
mapper = directory.NewMapper(*metaFolder, "directory", uint64(*volumeSizeLimitMB)*1024*1024, *mpulse)
|
||||||
http.HandleFunc("/dir/assign", dirAssignHandler)
|
http.HandleFunc("/dir/assign", dirAssignHandler)
|
||||||
http.HandleFunc("/dir/lookup", dirLookupHandler)
|
http.HandleFunc("/dir/lookup", dirLookupHandler)
|
||||||
http.HandleFunc("/dir/join", dirJoinHandler)
|
http.HandleFunc("/dir/join", dirJoinHandler)
|
||||||
|
|
|
@ -30,7 +30,7 @@ var (
|
||||||
volumes = cmdVolume.Flag.String("volumes", "0,1-3,4", "comma-separated list of volume ids or range of ids")
|
volumes = cmdVolume.Flag.String("volumes", "0,1-3,4", "comma-separated list of volume ids or range of ids")
|
||||||
publicUrl = cmdVolume.Flag.String("publicUrl", "localhost:8080", "public url to serve data read")
|
publicUrl = cmdVolume.Flag.String("publicUrl", "localhost:8080", "public url to serve data read")
|
||||||
metaServer = cmdVolume.Flag.String("mserver", "localhost:9333", "master directory server to store mappings")
|
metaServer = cmdVolume.Flag.String("mserver", "localhost:9333", "master directory server to store mappings")
|
||||||
pulse = cmdVolume.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats")
|
vpulse = cmdVolume.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats")
|
||||||
|
|
||||||
store *storage.Store
|
store *storage.Store
|
||||||
)
|
)
|
||||||
|
@ -162,7 +162,7 @@ func runVolume(cmd *Command, args []string) bool {
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
store.Join(*metaServer)
|
store.Join(*metaServer)
|
||||||
time.Sleep(time.Duration(float32(*pulse*1e3)*(1+rand.Float32())) * time.Millisecond)
|
time.Sleep(time.Duration(float32(*vpulse*1e3)*(1+rand.Float32())) * time.Millisecond)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
log.Println("store joined at", *metaServer)
|
log.Println("store joined at", *metaServer)
|
||||||
|
|
|
@ -52,7 +52,7 @@ func main() {
|
||||||
if args[0] == "help" {
|
if args[0] == "help" {
|
||||||
help(args[1:])
|
help(args[1:])
|
||||||
for _, cmd := range commands {
|
for _, cmd := range commands {
|
||||||
if len(args)>2 && cmd.Name() == args[1] && cmd.Run != nil {
|
if len(args)>=2 && cmd.Name() == args[1] && cmd.Run != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Default Parameters:\n")
|
fmt.Fprintf(os.Stderr, "Default Parameters:\n")
|
||||||
cmd.Flag.PrintDefaults()
|
cmd.Flag.PrintDefaults()
|
||||||
}
|
}
|
||||||
|
@ -93,12 +93,6 @@ The commands are:
|
||||||
|
|
||||||
Use "weed help [command]" for more information about a command.
|
Use "weed help [command]" for more information about a command.
|
||||||
|
|
||||||
Additional help topics:
|
|
||||||
{{range .}}{{if not .Runnable}}
|
|
||||||
{{.Name | printf "%-11s"}} {{.Short}}{{end}}{{end}}
|
|
||||||
|
|
||||||
Use "weed help [topic]" for more information about that topic.
|
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
var helpTemplate = `{{if .Runnable}}Usage: weed {{.UsageLine}}
|
var helpTemplate = `{{if .Runnable}}Usage: weed {{.UsageLine}}
|
||||||
|
|
|
@ -7,36 +7,38 @@ import (
|
||||||
"pkg/sequence"
|
"pkg/sequence"
|
||||||
"pkg/storage"
|
"pkg/storage"
|
||||||
"pkg/util"
|
"pkg/util"
|
||||||
"sync"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Machine struct {
|
type Machine struct {
|
||||||
Volumes []storage.VolumeInfo
|
Volumes []storage.VolumeInfo
|
||||||
Url string //<server name/ip>[:port]
|
Url string //<server name/ip>[:port]
|
||||||
PublicUrl string
|
PublicUrl string
|
||||||
|
LastSeen int64 // unix time in seconds
|
||||||
}
|
}
|
||||||
|
|
||||||
type Mapper struct {
|
type Mapper struct {
|
||||||
volumeLock sync.Mutex
|
|
||||||
Machines map[string]*Machine
|
Machines map[string]*Machine
|
||||||
vid2machineId map[storage.VolumeId]*Machine //machineId is +1 of the index of []*Machine, to detect not found entries
|
vid2machine map[storage.VolumeId]*Machine
|
||||||
Writers []storage.VolumeId // transient array of Writers volume id
|
Writers []storage.VolumeId // transient array of Writers volume id
|
||||||
|
pulse int64
|
||||||
|
|
||||||
volumeSizeLimit uint64
|
volumeSizeLimit uint64
|
||||||
|
|
||||||
sequence sequence.Sequencer
|
sequence sequence.Sequencer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMachine(server, publicUrl string, volumes []storage.VolumeInfo) *Machine {
|
func NewMachine(server, publicUrl string, volumes []storage.VolumeInfo, lastSeen int64) *Machine {
|
||||||
return &Machine{Url: server, PublicUrl: publicUrl, Volumes: volumes}
|
return &Machine{Url: server, PublicUrl: publicUrl, Volumes: volumes, LastSeen: lastSeen}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMapper(dirname string, filename string, volumeSizeLimit uint64) (m *Mapper) {
|
func NewMapper(dirname string, filename string, volumeSizeLimit uint64, pulse int) (m *Mapper) {
|
||||||
m = &Mapper{}
|
m = &Mapper{}
|
||||||
m.vid2machineId = make(map[storage.VolumeId]*Machine)
|
m.vid2machine = make(map[storage.VolumeId]*Machine)
|
||||||
m.volumeSizeLimit = volumeSizeLimit
|
m.volumeSizeLimit = volumeSizeLimit
|
||||||
m.Writers = *new([]storage.VolumeId)
|
m.Writers = *new([]storage.VolumeId)
|
||||||
m.Machines = make(map[string]*Machine)
|
m.Machines = make(map[string]*Machine)
|
||||||
|
m.pulse = int64(pulse)
|
||||||
|
|
||||||
m.sequence = sequence.NewSequencer(dirname, filename)
|
m.sequence = sequence.NewSequencer(dirname, filename)
|
||||||
|
|
||||||
|
@ -49,7 +51,7 @@ func (m *Mapper) PickForWrite(c string) (string, int, *Machine, error) {
|
||||||
return "", 0, nil, errors.New("No more writable volumes!")
|
return "", 0, nil, errors.New("No more writable volumes!")
|
||||||
}
|
}
|
||||||
vid := m.Writers[rand.Intn(len_writers)]
|
vid := m.Writers[rand.Intn(len_writers)]
|
||||||
machine := m.vid2machineId[vid]
|
machine := m.vid2machine[vid]
|
||||||
if machine != nil {
|
if machine != nil {
|
||||||
fileId, count := m.sequence.NextFileId(util.ParseInt(c, 1))
|
fileId, count := m.sequence.NextFileId(util.ParseInt(c, 1))
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
|
@ -60,31 +62,41 @@ func (m *Mapper) PickForWrite(c string) (string, int, *Machine, error) {
|
||||||
return "", 0, nil, errors.New("Strangely vid " + vid.String() + " is on no machine!")
|
return "", 0, nil, errors.New("Strangely vid " + vid.String() + " is on no machine!")
|
||||||
}
|
}
|
||||||
func (m *Mapper) Get(vid storage.VolumeId) (*Machine, error) {
|
func (m *Mapper) Get(vid storage.VolumeId) (*Machine, error) {
|
||||||
machine := m.vid2machineId[vid]
|
machine := m.vid2machine[vid]
|
||||||
if machine == nil {
|
if machine == nil {
|
||||||
return nil, errors.New("invalid volume id " + vid.String())
|
return nil, errors.New("invalid volume id " + vid.String())
|
||||||
}
|
}
|
||||||
return machine, nil
|
return machine, nil
|
||||||
}
|
}
|
||||||
func (m *Mapper) Add(machine *Machine) {
|
func (m *Mapper) Add(machine *Machine) {
|
||||||
//check existing machine, linearly
|
|
||||||
//log.Println("Adding machine", machine.Server.Url)
|
|
||||||
m.volumeLock.Lock()
|
|
||||||
m.Machines[machine.Url] = machine
|
m.Machines[machine.Url] = machine
|
||||||
m.volumeLock.Unlock()
|
//add to vid2machine map, and Writers array
|
||||||
|
|
||||||
//add to vid2machineId map, and Writers array
|
|
||||||
for _, v := range machine.Volumes {
|
for _, v := range machine.Volumes {
|
||||||
m.vid2machineId[v.Id] = machine
|
m.vid2machine[v.Id] = machine
|
||||||
}
|
}
|
||||||
|
m.refreshWritableVolumes()
|
||||||
|
}
|
||||||
|
func (m *Mapper) StartRefreshWritableVolumes() {
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
m.refreshWritableVolumes()
|
||||||
|
time.Sleep(time.Duration(float32(m.pulse*1e3)*(1+rand.Float32())) * time.Millisecond)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mapper) refreshWritableVolumes() {
|
||||||
|
freshThreshHold := time.Now().Unix() - 5*m.pulse //5 times of sleep interval
|
||||||
//setting Writers, copy-on-write because of possible updating, this needs some future work!
|
//setting Writers, copy-on-write because of possible updating, this needs some future work!
|
||||||
var writers []storage.VolumeId
|
var writers []storage.VolumeId
|
||||||
for _, machine_entry := range m.Machines {
|
for _, machine_entry := range m.Machines {
|
||||||
|
if machine_entry.LastSeen > freshThreshHold {
|
||||||
for _, v := range machine_entry.Volumes {
|
for _, v := range machine_entry.Volumes {
|
||||||
if uint64(v.Size) < m.volumeSizeLimit {
|
if uint64(v.Size) < m.volumeSizeLimit {
|
||||||
writers = append(writers, v.Id)
|
writers = append(writers, v.Id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
m.Writers = writers
|
m.Writers = writers
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue