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

Commit 10c9db7

Browse files
committed
remove crufty NewBareIterGen()
no longer needed + now we have some actual validation
1 parent f10aabb commit 10c9db7

File tree

7 files changed

+32
-14
lines changed

7 files changed

+32
-14
lines changed

api/dataprocessor_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,10 @@ func TestGetSeriesCachedStore(t *testing.T) {
553553
// populate cache and store according to pattern definition
554554
var prevts uint32
555555
for i := 0; i < len(tc.Pattern); i++ {
556-
itgen := chunk.NewBareIterGen(chunks[i].Series.T0, 0, chunks[i].Encode(span))
556+
itgen, err := chunk.NewIterGen(chunks[i].Series.T0, 0, chunks[i].Encode(span))
557+
if err != nil {
558+
t.Fatalf("NewIterGen error: %s", err)
559+
}
557560
if pattern[i] == 'c' || pattern[i] == 'b' {
558561
c.Add(metric, prevts, itgen)
559562
}

cmd/mt-whisper-importer-reader/main.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,11 @@ func encodedChunksFromPoints(points []whisper.Point, intervalIn, chunkSpan uint3
365365
} else if prevT0 != t0 {
366366
c.Finish()
367367

368-
encodedChunks = append(encodedChunks, chunk.NewBareIterGen(c.Series.T0, intervalIn, c.Encode(chunkSpan)))
368+
itgen, err := chunk.NewIterGen(c.Series.T0, intervalIn, c.Encode(chunkSpan))
369+
if err != nil {
370+
panic(fmt.Sprintf("ERROR: failed to construct IterGen: %s", err))
371+
}
372+
encodedChunks = append(encodedChunks, itgen)
369373

370374
c = chunk.New(t0)
371375
prevT0 = t0
@@ -381,7 +385,11 @@ func encodedChunksFromPoints(points []whisper.Point, intervalIn, chunkSpan uint3
381385
// or if writeUnfinishedChunks is on, we close the chunk and push it
382386
if point.Timestamp == t0+chunkSpan-intervalIn || *writeUnfinishedChunks {
383387
c.Finish()
384-
encodedChunks = append(encodedChunks, chunk.NewBareIterGen(c.Series.T0, intervalIn, c.Encode(chunkSpan)))
388+
itgen, err := chunk.NewIterGen(c.Series.T0, intervalIn, c.Encode(chunkSpan))
389+
if err != nil {
390+
panic(fmt.Sprintf("ERROR: failed to construct IterGen: %s", err))
391+
}
392+
encodedChunks = append(encodedChunks, itgen)
385393
}
386394

387395
return encodedChunks

mdata/aggmetric.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,10 @@ func (a *AggMetric) pushToCache(c *chunk.Chunk) {
348348
// push into cache
349349
intervalHint := a.Key.Archive.Span()
350350

351-
itergen := chunk.NewBareIterGen(c.Series.T0, intervalHint, c.Encode(a.ChunkSpan))
351+
itergen, err := chunk.NewIterGen(c.Series.T0, intervalHint, c.Encode(a.ChunkSpan))
352+
if err != nil {
353+
log.Errorf("AM: %s failed to generate IterGen. this should never happen: %s", a.Key, err)
354+
}
352355
go a.cachePusher.AddIfHot(a.Key, 0, itergen)
353356
}
354357

mdata/cache/ccache_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ func getItgen(t testing.TB, values []uint32, ts uint32, spanaware bool) chunk.It
3131
}
3232
buf.Write(b)
3333

34-
return chunk.NewBareIterGen(ts, 1, buf.Bytes())
34+
itgen, err := chunk.NewIterGen(ts, 1, buf.Bytes())
35+
if err != nil {
36+
t.Fatalf("invalid IterGen: %s", err)
37+
}
38+
return itgen
39+
3540
}
3641

3742
func getConnectedChunks(t *testing.T, metric schema.AMKey) *CCache {

mdata/chunk/chunk_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ func TestRealProduction4hChunksWithSinglePointThatNeedRemediation(t *testing.T)
4040
if err != nil {
4141
t.Fatal(err)
4242
}
43-
itgen := NewBareIterGen(rc.t0, 30*60, data)
43+
itgen, err := NewIterGen(rc.t0, 30*60, data)
44+
if err != nil {
45+
t.Errorf("case %d: could not construct itergen: %s", i, err)
46+
}
4447
iter, err := itgen.Get()
4548
if err != nil {
4649
t.Errorf("case %d: could not get iterator: %s", i, err)

mdata/chunk/itergen.go

-7
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ type IterGen struct {
1919
B []byte
2020
}
2121

22-
// NewBareIterGen creates an IterGen without validation
23-
// note: it's ok for intervalHint to be 0 or 1 to mean unknown.
24-
// it just means that series4h corruptions can't be remediated in single-point-per-chunk scenarios
25-
func NewBareIterGen(t0, intervalHint uint32, b []byte) IterGen {
26-
return IterGen{t0, intervalHint, b}
27-
}
28-
2922
// NewIterGen creates an IterGen and performs crude validation of the data
3023
// note: it's ok for intervalHint to be 0 or 1 to mean unknown.
3124
// it just means that series4h corruptions can't be remediated in single-point-per-chunk scenarios

mdata/store_mock.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ func (c *MockStore) Items() int {
4040
func (c *MockStore) Add(cwr *ChunkWriteRequest) {
4141
if !c.Drop {
4242
intervalHint := cwr.Key.Archive.Span()
43-
itgen := chunk.NewBareIterGen(cwr.Chunk.Series.T0, intervalHint, cwr.Chunk.Encode(cwr.Span))
43+
itgen, err := chunk.NewIterGen(cwr.Chunk.Series.T0, intervalHint, cwr.Chunk.Encode(cwr.Span))
44+
if err != nil {
45+
panic(err)
46+
}
4447
c.results[cwr.Key] = append(c.results[cwr.Key], itgen)
4548
c.items++
4649
}

0 commit comments

Comments
 (0)