forked from grafana/loki
/
table_client.go
62 lines (50 loc) · 1.62 KB
/
table_client.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
package chunk
import "context"
// TableClient is a client for telling Dynamo what to do with tables.
type TableClient interface {
ListTables(ctx context.Context) ([]string, error)
CreateTable(ctx context.Context, desc TableDesc) error
DeleteTable(ctx context.Context, name string) error
DescribeTable(ctx context.Context, name string) (desc TableDesc, isActive bool, err error)
UpdateTable(ctx context.Context, current, expected TableDesc) error
Stop()
}
// TableDesc describes a table.
type TableDesc struct {
Name string
UseOnDemandIOMode bool
ProvisionedRead int64
ProvisionedWrite int64
Tags Tags
WriteScale AutoScalingConfig
ReadScale AutoScalingConfig
}
// Equals returns true if other matches desc.
func (desc TableDesc) Equals(other TableDesc) bool {
if desc.WriteScale != other.WriteScale {
return false
}
if desc.ReadScale != other.ReadScale {
return false
}
// Only check provisioned read if auto scaling is disabled
if !desc.ReadScale.Enabled && desc.ProvisionedRead != other.ProvisionedRead {
return false
}
// Only check provisioned write if auto scaling is disabled
if !desc.WriteScale.Enabled && desc.ProvisionedWrite != other.ProvisionedWrite {
return false
}
// if the billing mode needs updating
if desc.UseOnDemandIOMode != other.UseOnDemandIOMode {
return false
}
if !desc.Tags.Equals(other.Tags) {
return false
}
return true
}
type byName []TableDesc
func (a byName) Len() int { return len(a) }
func (a byName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a byName) Less(i, j int) bool { return a[i].Name < a[j].Name }