forked from grafana/metrictank
-
Notifications
You must be signed in to change notification settings - Fork 7
/
tables.go
49 lines (43 loc) · 1.29 KB
/
tables.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
package main
import (
"fmt"
"sort"
"github.com/grafana/metrictank/store/cassandra"
log "github.com/sirupsen/logrus"
)
type TablesByTTL []cassandra.Table
func (t TablesByTTL) Len() int { return len(t) }
func (t TablesByTTL) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t TablesByTTL) Less(i, j int) bool { return t[i].TTL < t[j].TTL }
// getTables returns the requested cassandra store tables in TTL asc order based on match string
func getTables(store *cassandra.CassandraStore, match string) ([]cassandra.Table, error) {
var tables []cassandra.Table
if match == "*" || match == "" {
for _, table := range store.TTLTables {
if !cassandra.IsStoreTable(table.Name) {
continue
}
tables = append(tables, table)
}
sort.Sort(TablesByTTL(tables))
} else {
for _, table := range store.TTLTables {
if table.Name == match {
tables = append(tables, table)
return tables, nil
}
}
return nil, fmt.Errorf("table %q not found", match)
}
return tables, nil
}
//printTables prints all tables in the store
func printTables(store *cassandra.CassandraStore) {
tables, err := getTables(store, "")
if err != nil {
log.Fatal(err.Error())
}
for _, table := range tables {
fmt.Printf("%s (%d hours <= ttl < %d hours)\n", table.Name, table.TTL, table.TTL*2)
}
}