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 f555428
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lib/slotmgr/slotmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package slotmgr

import (
"context"
"expvar"
"fmt"
"sync"
"time"
Expand Down Expand Up @@ -88,6 +89,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 +186,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 f555428

Please sign in to comment.