Skip to content

Commit 554eb2d

Browse files
authored
Revert "Use binary search in getSeriesIndex (grafana#621)"
This reverts commit b1a77df.
1 parent cbeb28c commit 554eb2d

File tree

3 files changed

+9
-52
lines changed

3 files changed

+9
-52
lines changed

pkg/phlaredb/profile_store_test.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -79,36 +79,6 @@ func sameProfileStream(i int) *testProfile {
7979
return tp
8080
}
8181

82-
// This will simulate a profile stream which ends and a new one starts at i > boundary
83-
func profileStreamEndingAndStarting(boundary int) func(int) *testProfile {
84-
return func(i int) *testProfile {
85-
tp := &testProfile{}
86-
87-
series := "at-beginning"
88-
if i > boundary {
89-
series = "at-end"
90-
}
91-
92-
tp.profileName = "process_cpu:cpu:nanoseconds:cpu:nanoseconds"
93-
tp.lbls = phlaremodel.LabelsFromStrings(
94-
phlaremodel.LabelNameProfileType, tp.profileName,
95-
"job", "test",
96-
"stream", series,
97-
)
98-
99-
tp.p.ID = uuid.MustParse(fmt.Sprintf("00000000-0000-0000-0000-%012d", i))
100-
tp.p.TimeNanos = time.Second.Nanoseconds() * int64(i)
101-
tp.p.Samples = []*schemav1.Sample{
102-
{
103-
StacktraceID: 0x1,
104-
Value: 10.0,
105-
},
106-
}
107-
tp.populateFingerprint()
108-
return tp
109-
}
110-
}
111-
11282
func readFullParquetFile[M any](t *testing.T, path string) ([]M, uint64) {
11383
f, err := os.Open(path)
11484
require.NoError(t, err)
@@ -161,13 +131,6 @@ func TestProfileStore_RowGroupSplitting(t *testing.T) {
161131
expectedNumRows: 100,
162132
values: sameProfileStream,
163133
},
164-
{
165-
name: "a stream ending after half of the samples and a new one starting",
166-
cfg: &ParquetConfig{MaxRowGroupBytes: 1828, MaxBufferRowCount: 100000},
167-
expectedNumRGs: 10,
168-
expectedNumRows: 100,
169-
values: profileStreamEndingAndStarting(50),
170-
},
171134
{
172135
name: "multiple row groups because of maximum row num",
173136
cfg: &ParquetConfig{MaxRowGroupBytes: 128000, MaxBufferRowCount: 10},

pkg/phlaredb/profiles.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,14 @@ type rowRangeWithSeriesIndex struct {
4141
type rowRangesWithSeriesIndex []rowRangeWithSeriesIndex
4242

4343
func (s rowRangesWithSeriesIndex) getSeriesIndex(rowNum int64) uint32 {
44-
l, r := 0, len(s)-1
45-
for l <= r {
46-
mid := (l + r) / 2
47-
if s[mid].rowRange == nil {
48-
l = mid + 1
44+
// todo: binary search
45+
for _, rg := range s {
46+
// it is possible that the series is not existing
47+
if rg.rowRange == nil {
4948
continue
5049
}
51-
if s[mid].rowNum <= rowNum && s[mid].rowNum+int64(s[mid].length) > rowNum {
52-
return s[mid].seriesIndex
53-
}
54-
if s[mid].rowNum > rowNum {
55-
r = mid - 1
56-
} else {
57-
l = mid + 1
50+
if rg.rowNum <= rowNum && rg.rowNum+int64(rg.length) > rowNum {
51+
return rg.seriesIndex
5852
}
5953
}
6054
panic("series index not found")

pkg/pprof/pprof.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ func FromProfile(p *profile.Profile) (*profilev1.Profile, error) {
190190
r.Mapping = append(r.Mapping, &profilev1.Mapping{
191191
Id: m.ID,
192192
Filename: addString(strings, m.File),
193-
MemoryStart: m.Start,
194-
MemoryLimit: m.Limit,
195-
FileOffset: m.Offset,
193+
MemoryStart: (m.Start),
194+
MemoryLimit: (m.Limit),
195+
FileOffset: (m.Offset),
196196
BuildId: addString(strings, m.BuildID),
197197
HasFunctions: m.HasFunctions,
198198
HasFilenames: m.HasFilenames,

0 commit comments

Comments
 (0)