mirror of
https://github.com/minio/minio.git
synced 2025-03-31 09:43:43 -04:00
Merge pull request #562 from fkautz/pr_out_reimagining_memory_settings_cli_input
This commit is contained in:
commit
faaa647b0d
65
main.go
65
main.go
@ -61,11 +61,11 @@ USAGE:
|
|||||||
minio mode {{.Name}} SIZE
|
minio mode {{.Name}} SIZE
|
||||||
|
|
||||||
EXAMPLES:
|
EXAMPLES:
|
||||||
1. Limit maximum memory usage to 64MB
|
1. Limit maximum memory usage to 64MB with 1h expiration
|
||||||
$ minio mode {{.Name}} 64MB
|
$ minio mode {{.Name}} limit 64MB expire 1h
|
||||||
|
|
||||||
2. Limit maximum memory usage to 4GB
|
2. Limit maximum memory usage to 4GB with no time expiration
|
||||||
$ minio mode {{.Name}} 4GB
|
$ minio mode {{.Name}} limit 4GB
|
||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,23 +135,56 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runMemory(c *cli.Context) {
|
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
|
cli.ShowCommandHelpAndExit(c, "memory", 1) // last argument is exit code
|
||||||
}
|
}
|
||||||
apiServerConfig := getAPIServerConfig(c)
|
apiServerConfig := getAPIServerConfig(c)
|
||||||
maxMemory, err := humanize.ParseBytes(c.Args().First())
|
|
||||||
if err != nil {
|
var maxMemory uint64
|
||||||
Fatalf("Invalid memory size [%s] passed. Reason: %s\n", c.Args().First(), iodine.New(err, nil))
|
maxMemorySet := false
|
||||||
}
|
|
||||||
tail := c.Args().Tail()
|
|
||||||
var expiration time.Duration
|
var expiration time.Duration
|
||||||
if tail.First() != "" {
|
expirationSet := false
|
||||||
expiration, err = time.ParseDuration(tail.First())
|
|
||||||
if err != nil {
|
var err error
|
||||||
Fatalf("Invalid expiration time [%s] passed. Reason: %s\n", tail.First(), iodine.New(err, nil))
|
|
||||||
|
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{
|
memoryDriver := server.MemoryFactory{
|
||||||
Config: apiServerConfig,
|
Config: apiServerConfig,
|
||||||
|
@ -74,7 +74,7 @@ func Start(maxSize uint64, expiration time.Duration) (chan<- string, <-chan erro
|
|||||||
memory.shutdown = false
|
memory.shutdown = false
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case maxSize == 0:
|
case maxSize <= 0:
|
||||||
memory.maxSize = 9223372036854775807
|
memory.maxSize = 9223372036854775807
|
||||||
case maxSize > 0:
|
case maxSize > 0:
|
||||||
memory.maxSize = maxSize
|
memory.maxSize = maxSize
|
||||||
|
Loading…
x
Reference in New Issue
Block a user