forked from influxdata/flux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_management.go
63 lines (56 loc) · 1.81 KB
/
resource_management.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package flux
import (
"math"
"strconv"
"github.com/influxdata/flux/codes"
"github.com/influxdata/flux/internal/errors"
)
// ResourceManagement defines how the query should consume avaliable resources.
type ResourceManagement struct {
// Priority or the query.
// Queries with a lower value will move to the front of the priority queue.
// A zero value indicates the highest priority.
Priority Priority `json:"priority"`
// ConcurrencyQuota is the number of concurrency workers allowed to process this query.
// A zero value indicates the planner can pick the optimal concurrency.
ConcurrencyQuota int `json:"concurrency_quota"`
// MemoryBytesQuota is the number of bytes of RAM this query may consume.
// There is a small amount of overhead memory being consumed by a query that will not be counted towards this limit.
// A zero value indicates unlimited.
MemoryBytesQuota int64 `json:"memory_bytes_quota"`
}
// Priority is an integer that represents the query priority.
// Any positive 32bit integer value may be used.
// Special constants are provided to represent the extreme high and low priorities.
type Priority int32
const (
// High is the highest possible priority = 0
High Priority = 0
// Low is the lowest possible priority = MaxInt32
Low Priority = math.MaxInt32
)
func (p Priority) MarshalText() ([]byte, error) {
switch p {
case Low:
return []byte("low"), nil
case High:
return []byte("high"), nil
default:
return []byte(strconv.FormatInt(int64(p), 10)), nil
}
}
func (p *Priority) UnmarshalText(txt []byte) error {
switch s := string(txt); s {
case "low":
*p = Low
case "high":
*p = High
default:
i, err := strconv.ParseInt(s, 10, 32)
if err != nil {
return errors.Wrap(err, codes.Invalid, "invalid priority, must be an integer or 'low','high'")
}
*p = Priority(i)
}
return nil
}