Merge pull request #562 from fkautz/pr_out_reimagining_memory_settings_cli_input

master
Frederick F. Kautz IV 10 years ago
commit faaa647b0d
  1. 61
      main.go
  2. 2
      pkg/storage/drivers/memory/memory.go

@ -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())
var maxMemory uint64
maxMemorySet := false
var expiration time.Duration
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", c.Args().First(), iodine.New(err, nil))
Fatalf("Invalid memory size [%s] passed. Reason: %s\n", args.First(), iodine.New(err, nil))
}
tail := c.Args().Tail()
var expiration time.Duration
if tail.First() != "" {
expiration, err = time.ParseDuration(tail.First())
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", tail.First(), iodine.New(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,

@ -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

Loading…
Cancel
Save