lib/logstorage: make linter happy

Signed-off-by: hagen1778 <roman@victoriametrics.com>
This commit is contained in:
hagen1778 2024-05-13 15:35:11 +02:00
parent 680b8c25c8
commit 17283fab6c
No known key found for this signature in database
GPG key ID: 3BF75F3741CA9640
6 changed files with 29 additions and 50 deletions

View file

@ -1512,7 +1512,7 @@ func (c *blockResultColumn) getFloatValueAtRow(rowIdx int) float64 {
} }
} }
func (c *blockResultColumn) getMaxValue(br *blockResult) float64 { func (c *blockResultColumn) getMaxValue(_ *blockResult) float64 {
if c.isConst { if c.isConst {
v := c.encodedValues[0] v := c.encodedValues[0]
f, ok := tryParseFloat64(v) f, ok := tryParseFloat64(v)
@ -1620,7 +1620,7 @@ func (c *blockResultColumn) getMaxValue(br *blockResult) float64 {
} }
} }
func (c *blockResultColumn) getMinValue(br *blockResult) float64 { func (c *blockResultColumn) getMinValue(_ *blockResult) float64 {
if c.isConst { if c.isConst {
v := c.encodedValues[0] v := c.encodedValues[0]
f, ok := tryParseFloat64(v) f, ok := tryParseFloat64(v)

View file

@ -19,7 +19,7 @@ func (po *pipeOffset) String() string {
func (po *pipeOffset) updateNeededFields(_, _ fieldsSet) { func (po *pipeOffset) updateNeededFields(_, _ fieldsSet) {
} }
func (po *pipeOffset) newPipeProcessor(workersCount int, _ <-chan struct{}, _ func(), ppBase pipeProcessor) pipeProcessor { func (po *pipeOffset) newPipeProcessor(_ int, _ <-chan struct{}, _ func(), ppBase pipeProcessor) pipeProcessor {
return &pipeOffsetProcessor{ return &pipeOffsetProcessor{
po: po, po: po,
ppBase: ppBase, ppBase: ppBase,

View file

@ -315,17 +315,17 @@ func (shard *pipeSortProcessorShard) createFloat64Values(values []string) []floa
return a return a
} }
func (psp *pipeSortProcessorShard) Len() int { func (shard *pipeSortProcessorShard) Len() int {
return len(psp.rowRefs) return len(shard.rowRefs)
} }
func (psp *pipeSortProcessorShard) Swap(i, j int) { func (shard *pipeSortProcessorShard) Swap(i, j int) {
rowRefs := psp.rowRefs rowRefs := shard.rowRefs
rowRefs[i], rowRefs[j] = rowRefs[j], rowRefs[i] rowRefs[i], rowRefs[j] = rowRefs[j], rowRefs[i]
} }
func (psp *pipeSortProcessorShard) Less(i, j int) bool { func (shard *pipeSortProcessorShard) Less(i, j int) bool {
return sortBlockLess(psp, i, psp, j) return sortBlockLess(shard, i, shard, j)
} }
func (psp *pipeSortProcessor) writeBlock(workerID uint, br *blockResult) { func (psp *pipeSortProcessor) writeBlock(workerID uint, br *blockResult) {

View file

@ -175,7 +175,6 @@ func (sup *statsCountUniqProcessor) updateStatsForAllRows(br *blockResult) int {
stateSizeIncrease += len(keyBuf) + int(unsafe.Sizeof("")) stateSizeIncrease += len(keyBuf) + int(unsafe.Sizeof(""))
} }
} }
keyBuf = sup.keyBuf
return stateSizeIncrease return stateSizeIncrease
} }
@ -308,7 +307,7 @@ func (sup *statsCountUniqProcessor) updateStatsForRow(br *blockResult, rowIdx in
m[string(keyBuf)] = struct{}{} m[string(keyBuf)] = struct{}{}
stateSizeIncrease += len(keyBuf) + int(unsafe.Sizeof("")) stateSizeIncrease += len(keyBuf) + int(unsafe.Sizeof(""))
} }
sup.keyBuf = keyBuf //sup.keyBuf = keyBuf
return stateSizeIncrease return stateSizeIncrease
} }
@ -325,7 +324,6 @@ func (sup *statsCountUniqProcessor) updateStatsForRow(br *blockResult, rowIdx in
m[string(keyBuf)] = struct{}{} m[string(keyBuf)] = struct{}{}
stateSizeIncrease += len(keyBuf) + int(unsafe.Sizeof("")) stateSizeIncrease += len(keyBuf) + int(unsafe.Sizeof(""))
} }
keyBuf = sup.keyBuf
return stateSizeIncrease return stateSizeIncrease
} }

View file

@ -164,32 +164,6 @@ func (c *BlockColumn) reset() {
c.Values = nil c.Values = nil
} }
func getBlockColumnIndex(columns []BlockColumn, columnName string) int {
for i, c := range columns {
if c.Name == columnName {
return i
}
}
return -1
}
func getBlockColumnValues(columns []BlockColumn, columnName string, rowsCount int) []string {
for _, c := range columns {
if c.Name == columnName {
return c.Values
}
}
return getEmptyStrings(rowsCount)
}
func appendBlockColumnValues(dst [][]string, columns []BlockColumn, fields []string, rowsCount int) [][]string {
for _, f := range fields {
values := getBlockColumnValues(columns, f, rowsCount)
dst = append(dst, values)
}
return dst
}
func getEmptyStrings(rowsCount int) []string { func getEmptyStrings(rowsCount int) []string {
p := emptyStrings.Load() p := emptyStrings.Load()
if p == nil { if p == nil {

View file

@ -89,7 +89,7 @@ func TestStorageRunQuery(t *testing.T) {
panic(fmt.Errorf("unexpected match for %d rows", len(timestamps))) panic(fmt.Errorf("unexpected match for %d rows", len(timestamps)))
} }
tenantIDs := []TenantID{tenantID} tenantIDs := []TenantID{tenantID}
s.RunQuery(context.Background(), tenantIDs, q, writeBlock) checkErr(t, s.RunQuery(context.Background(), tenantIDs, q, writeBlock))
}) })
t.Run("missing-message-text", func(_ *testing.T) { t.Run("missing-message-text", func(_ *testing.T) {
q := mustParseQuery(`foobar`) q := mustParseQuery(`foobar`)
@ -101,7 +101,7 @@ func TestStorageRunQuery(t *testing.T) {
panic(fmt.Errorf("unexpected match for %d rows", len(timestamps))) panic(fmt.Errorf("unexpected match for %d rows", len(timestamps)))
} }
tenantIDs := []TenantID{tenantID} tenantIDs := []TenantID{tenantID}
s.RunQuery(context.Background(), tenantIDs, q, writeBlock) checkErr(t, s.RunQuery(context.Background(), tenantIDs, q, writeBlock))
}) })
t.Run("matching-tenant-id", func(t *testing.T) { t.Run("matching-tenant-id", func(t *testing.T) {
q := mustParseQuery(`tenant.id:*`) q := mustParseQuery(`tenant.id:*`)
@ -135,7 +135,7 @@ func TestStorageRunQuery(t *testing.T) {
rowsCountTotal.Add(uint32(len(timestamps))) rowsCountTotal.Add(uint32(len(timestamps)))
} }
tenantIDs := []TenantID{tenantID} tenantIDs := []TenantID{tenantID}
s.RunQuery(context.Background(), tenantIDs, q, writeBlock) checkErr(t, s.RunQuery(context.Background(), tenantIDs, q, writeBlock))
expectedRowsCount := streamsPerTenant * blocksPerStream * rowsPerBlock expectedRowsCount := streamsPerTenant * blocksPerStream * rowsPerBlock
if n := rowsCountTotal.Load(); n != uint32(expectedRowsCount) { if n := rowsCountTotal.Load(); n != uint32(expectedRowsCount) {
@ -149,7 +149,7 @@ func TestStorageRunQuery(t *testing.T) {
writeBlock := func(_ uint, timestamps []int64, _ []BlockColumn) { writeBlock := func(_ uint, timestamps []int64, _ []BlockColumn) {
rowsCountTotal.Add(uint32(len(timestamps))) rowsCountTotal.Add(uint32(len(timestamps)))
} }
s.RunQuery(context.Background(), allTenantIDs, q, writeBlock) checkErr(t, s.RunQuery(context.Background(), allTenantIDs, q, writeBlock))
expectedRowsCount := tenantsCount * streamsPerTenant * blocksPerStream * rowsPerBlock expectedRowsCount := tenantsCount * streamsPerTenant * blocksPerStream * rowsPerBlock
if n := rowsCountTotal.Load(); n != uint32(expectedRowsCount) { if n := rowsCountTotal.Load(); n != uint32(expectedRowsCount) {
@ -162,7 +162,7 @@ func TestStorageRunQuery(t *testing.T) {
writeBlock := func(_ uint, timestamps []int64, _ []BlockColumn) { writeBlock := func(_ uint, timestamps []int64, _ []BlockColumn) {
rowsCountTotal.Add(uint32(len(timestamps))) rowsCountTotal.Add(uint32(len(timestamps)))
} }
s.RunQuery(context.Background(), allTenantIDs, q, writeBlock) checkErr(t, s.RunQuery(context.Background(), allTenantIDs, q, writeBlock))
expectedRowsCount := tenantsCount * streamsPerTenant * blocksPerStream * rowsPerBlock expectedRowsCount := tenantsCount * streamsPerTenant * blocksPerStream * rowsPerBlock
if n := rowsCountTotal.Load(); n != uint32(expectedRowsCount) { if n := rowsCountTotal.Load(); n != uint32(expectedRowsCount) {
@ -174,7 +174,7 @@ func TestStorageRunQuery(t *testing.T) {
writeBlock := func(_ uint, timestamps []int64, _ []BlockColumn) { writeBlock := func(_ uint, timestamps []int64, _ []BlockColumn) {
panic(fmt.Errorf("unexpected match for %d rows", len(timestamps))) panic(fmt.Errorf("unexpected match for %d rows", len(timestamps)))
} }
s.RunQuery(context.Background(), allTenantIDs, q, writeBlock) checkErr(t, s.RunQuery(context.Background(), allTenantIDs, q, writeBlock))
}) })
t.Run("matching-stream-id", func(t *testing.T) { t.Run("matching-stream-id", func(t *testing.T) {
for i := 0; i < streamsPerTenant; i++ { for i := 0; i < streamsPerTenant; i++ {
@ -208,7 +208,7 @@ func TestStorageRunQuery(t *testing.T) {
rowsCountTotal.Add(uint32(len(timestamps))) rowsCountTotal.Add(uint32(len(timestamps)))
} }
tenantIDs := []TenantID{tenantID} tenantIDs := []TenantID{tenantID}
s.RunQuery(context.Background(), tenantIDs, q, writeBlock) checkErr(t, s.RunQuery(context.Background(), tenantIDs, q, writeBlock))
expectedRowsCount := blocksPerStream * rowsPerBlock expectedRowsCount := blocksPerStream * rowsPerBlock
if n := rowsCountTotal.Load(); n != uint32(expectedRowsCount) { if n := rowsCountTotal.Load(); n != uint32(expectedRowsCount) {
@ -227,7 +227,7 @@ func TestStorageRunQuery(t *testing.T) {
rowsCountTotal.Add(uint32(len(timestamps))) rowsCountTotal.Add(uint32(len(timestamps)))
} }
tenantIDs := []TenantID{tenantID} tenantIDs := []TenantID{tenantID}
s.RunQuery(context.Background(), tenantIDs, q, writeBlock) checkErr(t, s.RunQuery(context.Background(), tenantIDs, q, writeBlock))
expectedRowsCount := streamsPerTenant * blocksPerStream * 2 expectedRowsCount := streamsPerTenant * blocksPerStream * 2
if n := rowsCountTotal.Load(); n != uint32(expectedRowsCount) { if n := rowsCountTotal.Load(); n != uint32(expectedRowsCount) {
@ -247,7 +247,7 @@ func TestStorageRunQuery(t *testing.T) {
rowsCountTotal.Add(uint32(len(timestamps))) rowsCountTotal.Add(uint32(len(timestamps)))
} }
tenantIDs := []TenantID{tenantID} tenantIDs := []TenantID{tenantID}
s.RunQuery(context.Background(), tenantIDs, q, writeBlock) checkErr(t, s.RunQuery(context.Background(), tenantIDs, q, writeBlock))
expectedRowsCount := streamsPerTenant * blocksPerStream expectedRowsCount := streamsPerTenant * blocksPerStream
if n := rowsCountTotal.Load(); n != uint32(expectedRowsCount) { if n := rowsCountTotal.Load(); n != uint32(expectedRowsCount) {
@ -267,7 +267,7 @@ func TestStorageRunQuery(t *testing.T) {
rowsCountTotal.Add(uint32(len(timestamps))) rowsCountTotal.Add(uint32(len(timestamps)))
} }
tenantIDs := []TenantID{tenantID} tenantIDs := []TenantID{tenantID}
s.RunQuery(context.Background(), tenantIDs, q, writeBlock) checkErr(t, s.RunQuery(context.Background(), tenantIDs, q, writeBlock))
expectedRowsCount := blocksPerStream expectedRowsCount := blocksPerStream
if n := rowsCountTotal.Load(); n != uint32(expectedRowsCount) { if n := rowsCountTotal.Load(); n != uint32(expectedRowsCount) {
@ -286,7 +286,7 @@ func TestStorageRunQuery(t *testing.T) {
panic(fmt.Errorf("unexpected match for %d rows", len(timestamps))) panic(fmt.Errorf("unexpected match for %d rows", len(timestamps)))
} }
tenantIDs := []TenantID{tenantID} tenantIDs := []TenantID{tenantID}
s.RunQuery(context.Background(), tenantIDs, q, writeBlock) checkErr(t, s.RunQuery(context.Background(), tenantIDs, q, writeBlock))
}) })
t.Run("missing-time-range", func(_ *testing.T) { t.Run("missing-time-range", func(_ *testing.T) {
minTimestamp := baseTimestamp + (rowsPerBlock+1)*1e9 minTimestamp := baseTimestamp + (rowsPerBlock+1)*1e9
@ -300,7 +300,7 @@ func TestStorageRunQuery(t *testing.T) {
panic(fmt.Errorf("unexpected match for %d rows", len(timestamps))) panic(fmt.Errorf("unexpected match for %d rows", len(timestamps)))
} }
tenantIDs := []TenantID{tenantID} tenantIDs := []TenantID{tenantID}
s.RunQuery(context.Background(), tenantIDs, q, writeBlock) checkErr(t, s.RunQuery(context.Background(), tenantIDs, q, writeBlock))
}) })
// Close the storage and delete its data // Close the storage and delete its data
@ -308,6 +308,13 @@ func TestStorageRunQuery(t *testing.T) {
fs.MustRemoveAll(path) fs.MustRemoveAll(path)
} }
func checkErr(t *testing.T, err error) {
t.Helper()
if err != nil {
t.Fatalf("unexpected err: %s", err)
}
}
func mustParseQuery(query string) *Query { func mustParseQuery(query string) *Query {
q, err := ParseQuery(query) q, err := ParseQuery(query)
if err != nil { if err != nil {