Skip to content

Commit

Permalink
slotmgr expvar
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Jan 14, 2025
1 parent 973d75b commit 200fe5d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/slotmgr/slotmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package slotmgr

import (
"context"
"expvar"
"fmt"
"net"

Check failure on line 7 in lib/slotmgr/slotmgr.go

View workflow job for this annotation

GitHub Actions / build-mainnet

"net" imported and not used

Check failure on line 7 in lib/slotmgr/slotmgr.go

View workflow job for this annotation

GitHub Actions / build-debug

"net" imported and not used

Check failure on line 7 in lib/slotmgr/slotmgr.go

View workflow job for this annotation

GitHub Actions / build-calibnet

"net" imported and not used

Check failure on line 7 in lib/slotmgr/slotmgr.go

View workflow job for this annotation

GitHub Actions / build-2k

"net" imported and not used

Check failure on line 7 in lib/slotmgr/slotmgr.go

View workflow job for this annotation

GitHub Actions / build-forest

"net" imported and not used

Check failure on line 7 in lib/slotmgr/slotmgr.go

View workflow job for this annotation

GitHub Actions / gen-check

"net" imported and not used

Check failure on line 7 in lib/slotmgr/slotmgr.go

View workflow job for this annotation

GitHub Actions / gen-check

"net" imported and not used

Check failure on line 7 in lib/slotmgr/slotmgr.go

View workflow job for this annotation

GitHub Actions / lint

"net" imported and not used (typecheck)

Check failure on line 7 in lib/slotmgr/slotmgr.go

View workflow job for this annotation

GitHub Actions / lint

"net" imported and not used) (typecheck)

Check failure on line 7 in lib/slotmgr/slotmgr.go

View workflow job for this annotation

GitHub Actions / lint

"net" imported and not used) (typecheck)

Check failure on line 7 in lib/slotmgr/slotmgr.go

View workflow job for this annotation

GitHub Actions / lint

"net" imported and not used) (typecheck)

Check failure on line 7 in lib/slotmgr/slotmgr.go

View workflow job for this annotation

GitHub Actions / test (test-itest-curio, ./itests/curio_test.go)

"net" imported and not used

Check failure on line 7 in lib/slotmgr/slotmgr.go

View workflow job for this annotation

GitHub Actions / test (test-all, `go list ./... | grep -v curio/itests`)

"net" imported and not used
"sync"
"time"

Expand Down Expand Up @@ -88,6 +90,32 @@ func NewSlotMgr(db *harmonydb.DB, machineHostAndPort string, slotOffs []uint64)
}
sm.cond = sync.NewCond(&sm.lk)

// Expose entire slotmgr as expvar
expvar.Publish("slotmgr", expvar.Func(func() interface{} {
sm.lk.Lock()
defer sm.lk.Unlock()

type jsonSlot struct {
SlotOffset uint64 `json:"slot_offset"`
Work bool `json:"work"`
Sectors []abi.SectorID `json:"sectors"`
}
type jsonSm struct {
Slots []jsonSlot `json:"slots"`
}

slc := make([]jsonSlot, len(sm.slots))
for i, slt := range sm.slots {
slc[i] = jsonSlot{
SlotOffset: slt.slotOffset,
Work: slt.work,
Sectors: lo.Keys(slt.sectors),
}
}

return jsonSm{Slots: slc}
}))

// Start a background watch loop
go sm.watchSlots()

Expand Down Expand Up @@ -159,6 +187,12 @@ func (s *SlotMgr) Get(ids []abi.SectorID) uint64 {
s.lk.Lock()
defer s.lk.Unlock()

if len(ids) == 0 {
panic("no ids")
}

log.Infow("acquiring slot", "sectors", ids)

for {
for _, slt := range s.slots {
// pick the first free slot
Expand Down

0 comments on commit 200fe5d

Please sign in to comment.