@@ -18,6 +18,7 @@ import (
18
18
"github.com/grafana/metrictank/util"
19
19
opentracing "github.com/opentracing/opentracing-go"
20
20
tags "github.com/opentracing/opentracing-go/ext"
21
+ "github.com/raintank/dur"
21
22
"github.com/raintank/schema"
22
23
log "github.com/sirupsen/logrus"
23
24
)
@@ -62,7 +63,7 @@ func formatRowKey(key schema.AMKey, ts uint32) string {
62
63
}
63
64
64
65
func formatFamily (ttl uint32 ) string {
65
- return fmt . Sprintf ( "ret_%d" , ttlToHours ( ttl ) )
66
+ return dur . FormatDuration ( dur )
66
67
}
67
68
68
69
func PrepareChunkData (span uint32 , data []byte ) []byte {
@@ -94,14 +95,6 @@ func mutationFromWriteRequest(cwr *mdata.ChunkWriteRequest) (*bigtable.Mutation,
94
95
return mut , len (value )
95
96
}
96
97
97
- func ttlToHours (ttl uint32 ) uint32 {
98
- hours := ttl / (60 * 60 )
99
- if hours < 1 {
100
- hours = 1
101
- }
102
- return hours
103
- }
104
-
105
98
type Store struct {
106
99
tbl * bigtable.Table
107
100
client * bigtable.Client
@@ -144,7 +137,7 @@ func NewStore(cfg *StoreConfig, ttls []uint32) (*Store, error) {
144
137
Families : make (map [string ]bigtable.GCPolicy ),
145
138
}
146
139
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 )
148
141
}
149
142
err := adminClient .CreateTableFromConf (ctx , & table )
150
143
if err != nil {
@@ -169,13 +162,13 @@ func NewStore(cfg *StoreConfig, ttls []uint32) (*Store, error) {
169
162
if err != nil {
170
163
return nil , fmt .Errorf ("btStore: failed to create cf %s/%s. %s" , cfg .TableName , formatFamily (ttl ), err )
171
164
}
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 ))
173
166
if err != nil {
174
167
return nil , fmt .Errorf ("btStore: failed to set GCPolicy of %s/%s. %s" , cfg .TableName , formatFamily (ttl ), err )
175
168
}
176
169
} else if policy == "" {
177
170
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 ))
179
172
if err != nil {
180
173
return nil , fmt .Errorf ("btStore: failed to set GCPolicy of %s/%s. %s" , cfg .TableName , formatFamily (ttl ), err )
181
174
}
0 commit comments