[#1] mclock: Add assert package
All checks were successful
DCO action / DCO (pull_request) Successful in 26s
Vulncheck / Vulncheck (pull_request) Successful in 29s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m9s
Tests and linters / gopls check (pull_request) Successful in 1m5s
Tests and linters / Tests (pull_request) Successful in 1m3s
Tests and linters / Lint (pull_request) Successful in 1m13s
Tests and linters / Run gofumpt (pull_request) Successful in 1m12s
Tests and linters / Staticcheck (pull_request) Successful in 1m13s
Tests and linters / Tests with -race (pull_request) Successful in 1m21s
Tests and linters / Run gofumpt (push) Successful in 32s
Vulncheck / Vulncheck (push) Successful in 36s
Tests and linters / Staticcheck (push) Successful in 49s
Pre-commit hooks / Pre-commit (push) Successful in 1m10s
Tests and linters / Lint (push) Successful in 1m12s
Tests and linters / Tests (push) Successful in 1m15s
Tests and linters / Tests with -race (push) Successful in 1m17s
Tests and linters / gopls check (push) Successful in 1m20s

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2025-01-28 11:35:54 +03:00
parent 9a48a50220
commit f4d8ebf13d
Signed by: dstepanov-yadro
GPG key ID: 237AF1A763293BC0
2 changed files with 19 additions and 24 deletions

9
internal/assert/cond.go Normal file
View file

@ -0,0 +1,9 @@
package assert
import "strings"
func Cond(cond bool, details ...string) {
if !cond {
panic(strings.Join(details, " "))
}
}

View file

@ -7,6 +7,8 @@ import (
"math"
"sync"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-qos/internal/assert"
)
const (
@ -172,9 +174,7 @@ func (q *MClock) dropRequest(req *request) {
select {
case <-req.scheduled:
if q.inProgress == 0 {
panic("invalid requests count")
}
assert.Cond(q.inProgress > 0, "invalid requests count")
q.inProgress--
default:
}
@ -199,9 +199,7 @@ func (q *MClock) pushRequest(tag string) (*request, ReleaseFunc, error) {
return nil, nil, ErrMClockSchedulerUnknownTag
}
prev, ok := q.previous[tag]
if !ok {
panic("undefined previous: " + tag)
}
assert.Cond(ok, "undefined previous:", tag)
if q.idleTimeout >= 0 && now-prev.ts > q.idleTimeout { // was inactive for q.idleTimeout
q.adjustTags(now, tag)
@ -321,9 +319,7 @@ func (q *MClock) scheduleByLimitAndWeight(now float64) {
q.removeFromQueues(next.r)
tagInfo, ok := q.tagInfo[next.r.tag]
if !ok {
panic("unknown tag: " + next.r.tag) // must be checked on top level
}
assert.Cond(ok, "unknown tag:", next.r.tag)
if tagInfo.ReservedIOPS != nil && hadReservation {
var updated bool
for _, i := range q.reservationQueue.items {
@ -390,24 +386,14 @@ func (q *MClock) requestCompleted() {
return
}
if q.inProgress == 0 {
panic("invalid requests count")
}
assert.Cond(q.inProgress > 0, "invalid requests count")
q.inProgress--
q.scheduleRequestUnsafe()
}
func assertIndexInvalid(r *request) {
if r.limitIdx != invalidIndex {
panic("limitIdx is not -1")
}
if r.sharesIdx != invalidIndex {
panic("sharesIdx is not -1")
}
if r.reservationIdx != invalidIndex {
panic("reservationIdx is not -1")
}
if r.readyIdx != invalidIndex {
panic("readyIdx is not -1")
}
assert.Cond(r.limitIdx == invalidIndex, "limitIdx is not -1")
assert.Cond(r.sharesIdx == invalidIndex, "sharesIdx is not -1")
assert.Cond(r.reservationIdx == invalidIndex, "reservationIdx is not -1")
assert.Cond(r.readyIdx == invalidIndex, "readyIdx is not -1")
}