Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit 712e539

Browse files
author
woodsaj
committed
use stringified duration for columnFamily name
1 parent 9bf810d commit 712e539

File tree

6 files changed

+21
-17
lines changed

6 files changed

+21
-17
lines changed

Gopkg.lock

+2-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ unused-packages = true
110110

111111
[[constraint]]
112112
name = "github.com/raintank/dur"
113-
branch = "v2"
113+
revision = "master"
114114

115115
[[constraint]]
116116
name = "github.com/raintank/gziper"

mdata/schema.go

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ func MaxChunkSpan() uint32 {
88
return Schemas.MaxChunkSpan()
99
}
1010

11+
// TTLs returns the full set of unique TTLs (in seconds) used by the current schema config.
1112
func TTLs() []uint32 {
1213
return Schemas.TTLs()
1314
}

store/bigtable/bigtable.go

+5-12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/grafana/metrictank/util"
1919
opentracing "github.com/opentracing/opentracing-go"
2020
tags "github.com/opentracing/opentracing-go/ext"
21+
"github.com/raintank/dur"
2122
"github.com/raintank/schema"
2223
log "github.com/sirupsen/logrus"
2324
)
@@ -62,7 +63,7 @@ func formatRowKey(key schema.AMKey, ts uint32) string {
6263
}
6364

6465
func formatFamily(ttl uint32) string {
65-
return fmt.Sprintf("ret_%d", ttlToHours(ttl))
66+
return dur.FormatDuration(dur)
6667
}
6768

6869
func PrepareChunkData(span uint32, data []byte) []byte {
@@ -94,14 +95,6 @@ func mutationFromWriteRequest(cwr *mdata.ChunkWriteRequest) (*bigtable.Mutation,
9495
return mut, len(value)
9596
}
9697

97-
func ttlToHours(ttl uint32) uint32 {
98-
hours := ttl / (60 * 60)
99-
if hours < 1 {
100-
hours = 1
101-
}
102-
return hours
103-
}
104-
10598
type Store struct {
10699
tbl *bigtable.Table
107100
client *bigtable.Client
@@ -144,7 +137,7 @@ func NewStore(cfg *StoreConfig, ttls []uint32) (*Store, error) {
144137
Families: make(map[string]bigtable.GCPolicy),
145138
}
146139
for _, ttl := range ttls {
147-
table.Families[formatFamily(ttl)] = bigtable.MaxAgePolicy(time.Duration(ttl/(60*60)) * time.Hour)
140+
table.Families[formatFamily(ttl)] = bigtable.MaxAgePolicy(time.Duration(ttl) * time.Second)
148141
}
149142
err := adminClient.CreateTableFromConf(ctx, &table)
150143
if err != nil {
@@ -169,13 +162,13 @@ func NewStore(cfg *StoreConfig, ttls []uint32) (*Store, error) {
169162
if err != nil {
170163
return nil, fmt.Errorf("btStore: failed to create cf %s/%s. %s", cfg.TableName, formatFamily(ttl), err)
171164
}
172-
err = adminClient.SetGCPolicy(ctx, cfg.TableName, formatFamily(ttl), bigtable.MaxAgePolicy(time.Duration(ttl/(60*60))*time.Hour))
165+
err = adminClient.SetGCPolicy(ctx, cfg.TableName, formatFamily(ttl), bigtable.MaxAgePolicy(time.Duration(ttl)*time.Second))
173166
if err != nil {
174167
return nil, fmt.Errorf("btStore: failed to set GCPolicy of %s/%s. %s", cfg.TableName, formatFamily(ttl), err)
175168
}
176169
} else if policy == "" {
177170
log.Infof("btStore: column family %s/%s exists but has no GCPolicy. creating it", cfg.TableName, formatFamily(ttl))
178-
err = adminClient.SetGCPolicy(ctx, cfg.TableName, formatFamily(ttl), bigtable.MaxAgePolicy(time.Duration(ttl/(60*60))*time.Hour))
171+
err = adminClient.SetGCPolicy(ctx, cfg.TableName, formatFamily(ttl), bigtable.MaxAgePolicy(time.Duration(ttl)*time.Second))
179172
if err != nil {
180173
return nil, fmt.Errorf("btStore: failed to set GCPolicy of %s/%s. %s", cfg.TableName, formatFamily(ttl), err)
181174
}

store/bigtable/config.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ type StoreConfig struct {
2525
}
2626

2727
func (cfg *StoreConfig) Validate() error {
28-
// If we dont have any write threads, then we dont WriteMaxFlushSize and WriteQueueSize
28+
// If we dont have any write threads, then WriteMaxFlushSize and WriteQueueSize
2929
// are not used. If we do have write threads, then we need to make sure that
30+
// the the writeMaxFlushSize is not larger then the bigtable hardcoded limit of 100k
31+
// and that the writeQueue size is larger then the maxFlush.
3032
if cfg.WriteConcurrency > 0 {
3133
if cfg.WriteMaxFlushSize > 100000 {
3234
return fmt.Errorf("write-max-flush-size must be <= 100000.")

vendor/github.com/raintank/dur/datetime.go

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)