Merge pull request #562 from fkautz/pr_out_reimagining_memory_settings_cli_input

This commit is contained in:
Frederick F. Kautz IV 2015-05-01 18:17:02 -07:00
commit faaa647b0d
2 changed files with 50 additions and 17 deletions

65
main.go
View File

@ -61,11 +61,11 @@ USAGE:
minio mode {{.Name}} SIZE
EXAMPLES:
1. Limit maximum memory usage to 64MB
$ minio mode {{.Name}} 64MB
1. Limit maximum memory usage to 64MB with 1h expiration
$ minio mode {{.Name}} limit 64MB expire 1h
2. Limit maximum memory usage to 4GB
$ minio mode {{.Name}} 4GB
2. Limit maximum memory usage to 4GB with no time expiration
$ minio mode {{.Name}} limit 4GB
`,
}
@ -135,23 +135,56 @@ func init() {
}
func runMemory(c *cli.Context) {
if len(c.Args()) < 1 {
if len(c.Args()) == 0 || len(c.Args())%2 != 0 {
cli.ShowCommandHelpAndExit(c, "memory", 1) // last argument is exit code
}
apiServerConfig := getAPIServerConfig(c)
maxMemory, err := humanize.ParseBytes(c.Args().First())
if err != nil {
Fatalf("Invalid memory size [%s] passed. Reason: %s\n", c.Args().First(), iodine.New(err, nil))
}
tail := c.Args().Tail()
var maxMemory uint64
maxMemorySet := false
var expiration time.Duration
if tail.First() != "" {
expiration, err = time.ParseDuration(tail.First())
if err != nil {
Fatalf("Invalid expiration time [%s] passed. Reason: %s\n", tail.First(), iodine.New(err, nil))
expirationSet := false
var err error
args := c.Args()
for len(args) > 0 {
switch args.First() {
case "limit":
{
if maxMemorySet {
Fatalf("Limit should be set only once")
}
args = args.Tail()
maxMemory, err = humanize.ParseBytes(args.First())
if err != nil {
Fatalf("Invalid memory size [%s] passed. Reason: %s\n", args.First(), iodine.New(err, nil))
}
if maxMemory < 1024*1024*10 {
Fatalf("Invalid memory size [%s] passed. Should be greater than 10M\n", args.First())
}
args = args.Tail()
maxMemorySet = true
}
case "expiration":
{
if expirationSet {
Fatalf("Expiration should be set only once")
}
args = args.Tail()
expiration, err = time.ParseDuration(args.First())
if err != nil {
Fatalf("Invalid expiration time [%s] passed. Reason: %s\n", args.First(), iodine.New(err, nil))
}
args = args.Tail()
expirationSet = true
}
default:
{
cli.ShowCommandHelpAndExit(c, "memory", 1) // last argument is exit code
}
}
} else {
expiration = 0
}
memoryDriver := server.MemoryFactory{
Config: apiServerConfig,

View File

@ -74,7 +74,7 @@ func Start(maxSize uint64, expiration time.Duration) (chan<- string, <-chan erro
memory.shutdown = false
switch {
case maxSize == 0:
case maxSize <= 0:
memory.maxSize = 9223372036854775807
case maxSize > 0:
memory.maxSize = maxSize