Skip to content

Commit eb0e2e4

Browse files
author
Onkar
committed
fix lint
1 parent 2859440 commit eb0e2e4

File tree

11 files changed

+96
-94
lines changed

11 files changed

+96
-94
lines changed

banyand/internal/sidx/block_writer.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,24 +198,26 @@ func (sw *writers) GetTagWriters(tagName string) (*writer, *writer, *writer) {
198198
}
199199

200200
// blockWriter handles writing blocks to files.
201+
//
202+
//nolint:govet // struct layout optimized for readability; field alignment acceptable
201203
type blockWriter struct {
202204
writers writers
203205
metaData []byte
204206
primaryBlockData []byte
205207
primaryBlockMetadata primaryBlockMetadata
206-
totalBlocksCount uint64
207-
maxKey int64
208+
minKey int64
209+
minKeyLast int64
208210
totalUncompressedSizeBytes uint64
209211
totalCount uint64
210-
minKey int64
212+
totalBlocksCount uint64
211213
totalMinKey int64
212214
totalMaxKey int64
213-
minKeyLast int64
215+
maxKey int64
214216
totalMinTimestamp int64
215217
totalMaxTimestamp int64
216-
hasTimestamp bool
217-
sidFirst common.SeriesID
218218
sidLast common.SeriesID
219+
sidFirst common.SeriesID
220+
hasTimestamp bool
219221
hasWrittenBlocks bool
220222
}
221223

banyand/internal/sidx/element.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ type tag struct {
3838
// elements is a collection of elements optimized for batch operations.
3939
type elements struct {
4040
seriesIDs []common.SeriesID // Pooled slice
41-
userKeys []int64 // Pooled slice (replaces timestamps)
42-
timestamps []int64 // Pooled slice of timestamps (Unix nanoseconds)
43-
data [][]byte // Pooled slice of slices
44-
tags [][]*tag // Pooled slice of tag pointer slices
41+
userKeys []int64 // Pooled slice (replaces timestamps)
42+
timestamps []int64 // Pooled slice of timestamps (Unix nanoseconds)
43+
data [][]byte // Pooled slice of slices
44+
tags [][]*tag // Pooled slice of tag pointer slices
4545
}
4646

4747
// reset clears tag for reuse.

banyand/internal/sidx/element_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func TestSizeCalculation(t *testing.T) {
139139
es := generateElements()
140140
es.seriesIDs = []common.SeriesID{1, 2}
141141
es.userKeys = []int64{100, 200}
142-
es.timestamps = []int64{100, 200} // Initialize timestamps
142+
es.timestamps = []int64{100, 200} // Initialize timestamps
143143
es.data = [][]byte{[]byte("data1"), []byte("data2")} // 5 + 5 = 10 bytes
144144
// Create tag pointers
145145
tag1 := generateTag()

banyand/internal/sidx/merge.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,15 @@ func mergeBlocks(closeCh <-chan struct{}, bw *blockWriter, br *blockReader, part
190190
// Recompute timestamp ranges from source parts
191191
// (timestamps are not stored in blocks, only in part metadata)
192192
recomputeTimestampRanges(&result, parts)
193-
193+
194194
return &result, nil
195195
}
196196

197197
// recomputeTimestampRanges computes min/max timestamps from source parts.
198198
func recomputeTimestampRanges(result *partMetadata, parts []*partWrapper) {
199199
var minTimestamp *int64
200200
var maxTimestamp *int64
201-
201+
202202
for _, pw := range parts {
203203
if pw.p == nil || pw.p.partMetadata == nil {
204204
continue
@@ -215,7 +215,7 @@ func recomputeTimestampRanges(result *partMetadata, parts []*partWrapper) {
215215
}
216216
}
217217
}
218-
218+
219219
if minTimestamp != nil && maxTimestamp != nil {
220220
result.MinTimestamp = minTimestamp
221221
result.MaxTimestamp = maxTimestamp

banyand/internal/sidx/merge_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -573,16 +573,16 @@ func cloneBytes(src []byte) []byte {
573573

574574
func TestRecomputeTimestampRanges(t *testing.T) {
575575
tests := []struct {
576+
expected *partMetadata
576577
name string
577578
parts []*partWrapper
578-
expected *partMetadata
579579
}{
580580
{
581581
name: "single part with timestamps",
582582
parts: []*partWrapper{
583583
newPartWrapper(nil, &part{
584584
partMetadata: &partMetadata{
585-
ID: 1,
585+
ID: 1,
586586
MinTimestamp: intPtr(1000000000),
587587
MaxTimestamp: intPtr(2000000000),
588588
},
@@ -598,21 +598,21 @@ func TestRecomputeTimestampRanges(t *testing.T) {
598598
parts: []*partWrapper{
599599
newPartWrapper(nil, &part{
600600
partMetadata: &partMetadata{
601-
ID: 1,
601+
ID: 1,
602602
MinTimestamp: intPtr(1000000000),
603603
MaxTimestamp: intPtr(2000000000),
604604
},
605605
}),
606606
newPartWrapper(nil, &part{
607607
partMetadata: &partMetadata{
608-
ID: 2,
608+
ID: 2,
609609
MinTimestamp: intPtr(500000000),
610610
MaxTimestamp: intPtr(1500000000),
611611
},
612612
}),
613613
newPartWrapper(nil, &part{
614614
partMetadata: &partMetadata{
615-
ID: 3,
615+
ID: 3,
616616
MinTimestamp: intPtr(2500000000),
617617
MaxTimestamp: intPtr(3000000000),
618618
},
@@ -628,21 +628,21 @@ func TestRecomputeTimestampRanges(t *testing.T) {
628628
parts: []*partWrapper{
629629
newPartWrapper(nil, &part{
630630
partMetadata: &partMetadata{
631-
ID: 1,
631+
ID: 1,
632632
MinTimestamp: intPtr(1000000000),
633633
MaxTimestamp: intPtr(2000000000),
634634
},
635635
}),
636636
newPartWrapper(nil, &part{
637637
partMetadata: &partMetadata{
638-
ID: 2,
638+
ID: 2,
639639
MinTimestamp: nil,
640640
MaxTimestamp: nil,
641641
},
642642
}),
643643
newPartWrapper(nil, &part{
644644
partMetadata: &partMetadata{
645-
ID: 3,
645+
ID: 3,
646646
MinTimestamp: intPtr(500000000),
647647
MaxTimestamp: intPtr(1500000000),
648648
},
@@ -658,14 +658,14 @@ func TestRecomputeTimestampRanges(t *testing.T) {
658658
parts: []*partWrapper{
659659
newPartWrapper(nil, &part{
660660
partMetadata: &partMetadata{
661-
ID: 1,
661+
ID: 1,
662662
MinTimestamp: nil,
663663
MaxTimestamp: nil,
664664
},
665665
}),
666666
newPartWrapper(nil, &part{
667667
partMetadata: &partMetadata{
668-
ID: 2,
668+
ID: 2,
669669
MinTimestamp: nil,
670670
MaxTimestamp: nil,
671671
},
@@ -681,7 +681,7 @@ func TestRecomputeTimestampRanges(t *testing.T) {
681681
parts: []*partWrapper{
682682
newPartWrapper(nil, &part{
683683
partMetadata: &partMetadata{
684-
ID: 1,
684+
ID: 1,
685685
MinTimestamp: intPtr(1000000000),
686686
MaxTimestamp: intPtr(2000000000),
687687
},
@@ -700,7 +700,7 @@ func TestRecomputeTimestampRanges(t *testing.T) {
700700
parts: []*partWrapper{
701701
newPartWrapper(nil, &part{
702702
partMetadata: &partMetadata{
703-
ID: 1,
703+
ID: 1,
704704
MinTimestamp: intPtr(1000000000),
705705
MaxTimestamp: intPtr(2000000000),
706706
},

banyand/internal/sidx/metadata.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,26 @@ import (
3535
)
3636

3737
// partMetadata contains metadata for an entire part (replaces timestamp-specific metadata from stream module).
38+
//
39+
//nolint:govet // struct layout optimized for readability; field alignment acceptable
3840
type partMetadata struct {
3941
// Size information
4042
CompressedSizeBytes uint64 `json:"compressedSizeBytes"`
4143
UncompressedSizeBytes uint64 `json:"uncompressedSizeBytes"`
4244
TotalCount uint64 `json:"totalCount"`
4345
BlocksCount uint64 `json:"blocksCount"`
4446

47+
// Identity
48+
ID uint64 `json:"id"` // Unique part identifier
49+
4550
// Key range
46-
MinKey int64 `json:"minKey"` // Minimum user key in part
47-
MaxKey int64 `json:"maxKey"` // Maximum user key in part
51+
MinKey int64 `json:"minKey"` // Minimum user key in part
52+
MaxKey int64 `json:"maxKey"` // Maximum user key in part
53+
SegmentID int64 `json:"segmentID"` // Segment identifier
4854

4955
// Timestamp range (optional, for time-based part selection)
5056
MinTimestamp *int64 `json:"min_timestamp,omitempty"` // Minimum timestamp in part (Unix nanoseconds)
5157
MaxTimestamp *int64 `json:"max_timestamp,omitempty"` // Maximum timestamp in part (Unix nanoseconds)
52-
53-
// Identity
54-
ID uint64 `json:"id"` // Unique part identifier
55-
SegmentID int64 `json:"segmentID"` // Segment identifier
5658
}
5759

5860
func validatePartMetadata(fileSystem fs.FileSystem, partPath string) error {

banyand/internal/sidx/metadata_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ func TestPartMetadata_Serialization(t *testing.T) {
455455

456456
func TestPartMetadata_SerializationWithTimestamps(t *testing.T) {
457457
tests := []struct {
458-
name string
459-
original *partMetadata
458+
original *partMetadata
459+
name string
460460
expectTimestamps bool
461461
}{
462462
{
@@ -567,7 +567,6 @@ func TestPartMetadata_SerializationWithTimestamps(t *testing.T) {
567567
}
568568
}
569569

570-
571570
func TestBlockMetadata_Serialization(t *testing.T) {
572571
original := &blockMetadata{
573572
seriesID: common.SeriesID(123),
@@ -678,8 +677,8 @@ func TestPartMetadata_JSONFormat(t *testing.T) {
678677

679678
func TestPartMetadata_JSONFormatWithTimestamps(t *testing.T) {
680679
tests := []struct {
681-
name string
682-
original *partMetadata
680+
original *partMetadata
681+
name string
683682
expectTimestampFields bool
684683
}{
685684
{

banyand/internal/sidx/part.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -752,31 +752,31 @@ func (mp *memPart) mustInitFromElements(es *elements) {
752752
// Process block when series changes, size limit reached, count limit reached, or at end
753753
seriesChanged := i < len(es.seriesIDs) && es.seriesIDs[i] != currentSeriesID
754754
if (i-blockStart) > maxBlockLength || accumulatedSize >= maxUncompressedBlockSize || i == len(es.seriesIDs) || seriesChanged {
755-
// Extract elements for current series
756-
seriesUserKeys := es.userKeys[blockStart:i]
757-
// Ensure timestamps slice has the same length as other slices
758-
var seriesTimestamps []int64
759-
if len(es.timestamps) > blockStart {
760-
// Use available timestamps starting from blockStart, up
761-
// to either i or the end of timestamps.
762-
upper := i
763-
if upper > len(es.timestamps) {
764-
upper = len(es.timestamps)
765-
}
766-
seriesTimestamps = es.timestamps[blockStart:upper]
767-
// If we don't have enough timestamps to cover the whole
768-
// block, pad with zeros
769-
if len(seriesTimestamps) < i-blockStart {
770-
padded := make([]int64, i-blockStart)
771-
copy(padded, seriesTimestamps)
772-
seriesTimestamps = padded
755+
// Extract elements for current series
756+
seriesUserKeys := es.userKeys[blockStart:i]
757+
// Ensure timestamps slice has the same length as other slices
758+
var seriesTimestamps []int64
759+
if len(es.timestamps) > blockStart {
760+
// Use available timestamps starting from blockStart, up
761+
// to either i or the end of timestamps.
762+
upper := i
763+
if upper > len(es.timestamps) {
764+
upper = len(es.timestamps)
765+
}
766+
seriesTimestamps = es.timestamps[blockStart:upper]
767+
// If we don't have enough timestamps to cover the whole
768+
// block, pad with zeros
769+
if len(seriesTimestamps) < i-blockStart {
770+
padded := make([]int64, i-blockStart)
771+
copy(padded, seriesTimestamps)
772+
seriesTimestamps = padded
773+
}
774+
} else {
775+
// Fallback: create empty slice if timestamps not populated (backward compatibility)
776+
seriesTimestamps = make([]int64, i-blockStart)
773777
}
774-
} else {
775-
// Fallback: create empty slice if timestamps not populated (backward compatibility)
776-
seriesTimestamps = make([]int64, i-blockStart)
777-
}
778-
seriesData := es.data[blockStart:i]
779-
seriesTags := es.tags[blockStart:i]
778+
seriesData := es.data[blockStart:i]
779+
seriesTags := es.tags[blockStart:i]
780780

781781
// Write elements for this series
782782
bw.MustWriteElements(currentSeriesID, seriesUserKeys, seriesTimestamps, seriesData, seriesTags)

banyand/internal/sidx/part_wrapper_test.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -577,13 +577,13 @@ func TestPartWrapper_OverlapsKeyRange_EdgeCases(t *testing.T) {
577577

578578
func TestPartWrapper_OverlapsTimeRange(t *testing.T) {
579579
tests := []struct {
580-
name string
581-
partMin *int64
582-
partMax *int64
583-
queryMin *int64
584-
queryMax *int64
585-
expected bool
586-
description string
580+
partMin *int64
581+
partMax *int64
582+
queryMin *int64
583+
queryMax *int64
584+
name string
585+
description string
586+
expected bool
587587
}{
588588
{
589589
name: "complete_overlap",
@@ -718,7 +718,7 @@ func TestPartWrapper_OverlapsTimeRange(t *testing.T) {
718718
p := &part{
719719
path: "/test/part/001",
720720
partMetadata: &partMetadata{
721-
ID: 1,
721+
ID: 1,
722722
MinTimestamp: tt.partMin,
723723
MaxTimestamp: tt.partMax,
724724
},
@@ -755,7 +755,7 @@ func TestPartWrapper_OverlapsTimeRange_EdgeCases(t *testing.T) {
755755
p := &part{
756756
path: "/test/part/001",
757757
partMetadata: &partMetadata{
758-
ID: 1,
758+
ID: 1,
759759
MinTimestamp: intPtr(1000000000),
760760
MaxTimestamp: intPtr(2000000000),
761761
},
@@ -770,7 +770,7 @@ func TestPartWrapper_OverlapsTimeRange_EdgeCases(t *testing.T) {
770770
p := &part{
771771
path: "/test/part/001",
772772
partMetadata: &partMetadata{
773-
ID: 1,
773+
ID: 1,
774774
MinTimestamp: intPtr(1000000000),
775775
MaxTimestamp: intPtr(2000000000),
776776
},
@@ -785,7 +785,7 @@ func TestPartWrapper_OverlapsTimeRange_EdgeCases(t *testing.T) {
785785
p := &part{
786786
path: "/test/part/001",
787787
partMetadata: &partMetadata{
788-
ID: 1,
788+
ID: 1,
789789
MinTimestamp: intPtr(1000000000),
790790
MaxTimestamp: intPtr(2000000000),
791791
},
@@ -796,4 +796,3 @@ func TestPartWrapper_OverlapsTimeRange_EdgeCases(t *testing.T) {
796796
pw.release()
797797
})
798798
}
799-

0 commit comments

Comments
 (0)