diff --git a/mgr.go b/mgr.go index 7c24751..e4cb5f2 100644 --- a/mgr.go +++ b/mgr.go @@ -445,7 +445,9 @@ const splitBits = 4 func (m *mgr) splitChunk(c *chunk) { frac := c.duration() / splitBits - if hasSubSecondD(frac) { + if frac < c.stream.SplitUntil { + frac = c.stream.SplitUntil + } else if hasSubSecondD(frac) { frac = frac + time.Second/2 frac = frac.Round(time.Second) } diff --git a/mgr_test.go b/mgr_test.go index c3c5f19..81e1f36 100644 --- a/mgr_test.go +++ b/mgr_test.go @@ -1621,15 +1621,18 @@ func TestQueryManager_Query(t *testing.T) { chunks []expectedChunk } testCases := []struct { - name string - chunks []expectedChunk + name string + splitUntil time.Duration + chunks []expectedChunk }{ { - name: "Already Minimum Chunk Size", - chunks: []expectedChunk{{time.Second, 0, 2, nil}}, + name: "Already Minimum Chunk Size", + splitUntil: time.Second, + chunks: []expectedChunk{{time.Second, 0, 2, nil}}, }, { - name: "One Split in Half", + name: "One Split in Half", + splitUntil: time.Second, chunks: []expectedChunk{ { size: 2 * time.Second, @@ -1643,7 +1646,8 @@ func TestQueryManager_Query(t *testing.T) { }, }, { - name: "One Split in Thirds", + name: "One Split in Thirds", + splitUntil: time.Second, chunks: []expectedChunk{ { size: 3 * time.Second, @@ -1658,7 +1662,8 @@ func TestQueryManager_Query(t *testing.T) { }, }, { - name: "One Split in Quarters", + name: "One Split in Quarters", + splitUntil: time.Second, chunks: []expectedChunk{ { size: 4 * time.Second, @@ -1674,7 +1679,8 @@ func TestQueryManager_Query(t *testing.T) { }, }, { - name: "Odd Splits", + name: "Odd Splits", + splitUntil: time.Second, chunks: []expectedChunk{ { size: 5 * time.Second, @@ -1695,6 +1701,21 @@ func TestQueryManager_Query(t *testing.T) { }, }, }, + { + name: "Split Range Cannot Go Below SplitUntil", + splitUntil: 50 * time.Second, + chunks: []expectedChunk{ + { + size: 100 * time.Second, + start: 0, + end: 2, + chunks: []expectedChunk{ + {50 * time.Second, 0, 1, nil}, + {50 * time.Second, 1, 2, nil}, + }, + }, + }, + }, } // Run the sub-tests. @@ -1778,7 +1799,7 @@ func TestQueryManager_Query(t *testing.T) { End: defaultStart.Add(offset), Limit: maxLimit, Chunk: testCase.chunks[0].size, - SplitUntil: time.Second, + SplitUntil: testCase.splitUntil, }) require.NoError(t, err) require.NotNil(t, s)