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

Commit 63c4e5d

Browse files
committed
do away with CCacheMetric.Init just use standard constructor
1 parent b0be867 commit 63c4e5d

File tree

3 files changed

+17
-27
lines changed

3 files changed

+17
-27
lines changed

mdata/cache/ccache.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ func (c *CCache) Add(metric schema.AMKey, prev uint32, itergen chunk.IterGen) {
136136

137137
ccm, ok := c.metricCache[metric]
138138
if !ok {
139-
ccm = NewCCacheMetric()
140-
ccm.Init(metric.MKey, prev, itergen)
139+
ccm = NewCCacheMetric(metric.MKey)
140+
ccm.Add(prev, itergen)
141141
c.metricCache[metric] = ccm
142142

143143
// if we do not have this raw key yet, create the entry with the association
@@ -166,11 +166,8 @@ func (c *CCache) AddRange(metric schema.AMKey, prev uint32, itergens []chunk.Ite
166166

167167
ccm, ok := c.metricCache[metric]
168168
if !ok {
169-
ccm = NewCCacheMetric()
170-
ccm.Init(metric.MKey, prev, itergens[0])
171-
if len(itergens) > 1 {
172-
ccm.AddRange(itergens[0].Ts, itergens[1:])
173-
}
169+
ccm = NewCCacheMetric(metric.MKey)
170+
ccm.AddRange(prev, itergens)
174171
c.metricCache[metric] = ccm
175172

176173
// if we do not have this raw key yet, create the entry with the association

mdata/cache/ccache_metric.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,13 @@ type CCacheMetric struct {
2626
}
2727

2828
// NewCCacheMetric creates a CCacheMetric
29-
func NewCCacheMetric() *CCacheMetric {
29+
func NewCCacheMetric(mkey schema.MKey) *CCacheMetric {
3030
return &CCacheMetric{
31+
MKey: mkey,
3132
chunks: make(map[uint32]*CCacheChunk),
3233
}
3334
}
3435

35-
func (mc *CCacheMetric) Init(MKey schema.MKey, prev uint32, itergen chunk.IterGen) {
36-
mc.Add(prev, itergen)
37-
mc.MKey = MKey
38-
}
39-
4036
// Del deletes chunks for the given timestamp
4137
func (mc *CCacheMetric) Del(ts uint32) int {
4238
mc.Lock()

mdata/cache/ccache_metric_test.go

+11-14
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,15 @@ func generateChunks(b testing.TB, startAt, count, step uint32) []chunk.IterGen {
1919
return res
2020
}
2121

22-
func initMetric(b testing.TB, start, step uint32) (schema.MKey, *CCacheMetric) {
23-
ccm := NewCCacheMetric()
22+
func getCCM() (schema.MKey, *CCacheMetric) {
2423
mkey, _ := schema.MKeyFromString("1.12345678901234567890123456789012")
25-
values := make([]uint32, step)
26-
c := getItgen(b, values, start, true)
27-
ccm.Init(mkey, 0, c)
24+
ccm := NewCCacheMetric(mkey)
2825
return mkey, ccm
2926
}
3027

3128
func BenchmarkAddingManyChunksOneByOne(b *testing.B) {
32-
_, ccm := initMetric(b, 10, 10)
33-
chunks := generateChunks(b, 20, uint32(b.N), 10)
29+
_, ccm := getCCM()
30+
chunks := generateChunks(b, 10, uint32(b.N), 10)
3431
prev := uint32(1)
3532
b.ResetTimer()
3633
for _, chunk := range chunks {
@@ -40,18 +37,18 @@ func BenchmarkAddingManyChunksOneByOne(b *testing.B) {
4037
}
4138

4239
func BenchmarkAddingManyChunksAtOnce(b *testing.B) {
43-
_, ccm := initMetric(b, 10, 10)
44-
chunks := generateChunks(b, 20, uint32(b.N), 10)
40+
_, ccm := getCCM()
41+
chunks := generateChunks(b, 10, uint32(b.N), 10)
4542
prev := uint32(1)
4643
b.ResetTimer()
4744
ccm.AddRange(prev, chunks)
4845
}
4946

5047
func TestAddingChunksOneByOneAndQueryingThem(t *testing.T) {
51-
mkey, ccm := initMetric(t, 10, 10)
48+
mkey, ccm := getCCM()
5249
amkey := schema.AMKey{MKey: mkey, Archive: 0}
53-
chunks := generateChunks(t, 20, 5, 10)
54-
prev := uint32(10)
50+
chunks := generateChunks(t, 10, 6, 10)
51+
prev := uint32(1)
5552
for _, chunk := range chunks {
5653
ccm.Add(prev, chunk)
5754
prev = chunk.Ts
@@ -72,9 +69,9 @@ func TestAddingChunksOneByOneAndQueryingThem(t *testing.T) {
7269
}
7370
}
7471
func TestAddingChunksAtOnceAndQueryingThem(t *testing.T) {
75-
mkey, ccm := initMetric(t, 10, 10)
72+
mkey, ccm := getCCM()
7673
amkey := schema.AMKey{MKey: mkey, Archive: 0}
77-
chunks := generateChunks(t, 20, 5, 10)
74+
chunks := generateChunks(t, 10, 6, 10)
7875
prev := uint32(10)
7976
ccm.AddRange(prev, chunks)
8077

0 commit comments

Comments
 (0)