Skip to content

Commit

Permalink
feat(allocator): add debug logging (#213)
Browse files Browse the repository at this point in the history
Add debug logs to track behavior of allocator to check for errors
  • Loading branch information
hannahhoward authored Sep 10, 2021
1 parent 07afd15 commit 2687228
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions allocator/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import (
"sync"

pq "github.com/ipfs/go-ipfs-pq"
logging "github.com/ipfs/go-log/v2"
peer "github.com/libp2p/go-libp2p-core/peer"
)

var log = logging.Logger("graphsync_allocator")

type Allocator struct {
totalMemoryMax uint64
perPeerMax uint64
Expand Down Expand Up @@ -58,8 +61,10 @@ func (a *Allocator) AllocateBlockMemory(p peer.ID, amount uint64) <-chan error {
if (a.totalAllocatedAllPeers+amount <= a.totalMemoryMax) && (status.totalAllocated+amount <= a.perPeerMax) && len(status.pendingAllocations) == 0 {
a.totalAllocatedAllPeers += amount
status.totalAllocated += amount
log.Debugw("bytes allocated", "amount", amount, "peer", p, "peer total", status.totalAllocated, "global total", a.totalAllocatedAllPeers)
responseChan <- nil
} else {
log.Debugw("byte allocation deferred pending memory release", "amount", amount, "peer", p, "peer total", status.totalAllocated, "global total", a.totalAllocatedAllPeers, "max per peer", a.perPeerMax, "global max", a.totalMemoryMax)
pendingAllocation := pendingAllocation{p, amount, responseChan, a.nextAllocIndex}
a.nextAllocIndex++
status.pendingAllocations = append(status.pendingAllocations, pendingAllocation)
Expand All @@ -86,6 +91,7 @@ func (a *Allocator) ReleaseBlockMemory(p peer.ID, amount uint64) error {
} else {
a.totalAllocatedAllPeers = 0
}
log.Debugw("memory released", "amount", amount, "peer", p, "peer total", status.totalAllocated, "global total", a.totalAllocatedAllPeers, "max per peer", a.perPeerMax, "global max", a.totalMemoryMax)
a.peerStatusQueue.Update(status.Index())
a.processPendingAllocations()
return nil
Expand All @@ -104,6 +110,7 @@ func (a *Allocator) ReleasePeerMemory(p peer.ID) error {
pendingAllocation.response <- errors.New("peer has been deallocated")
}
a.totalAllocatedAllPeers -= status.totalAllocated
log.Debugw("memory released", "amount", status.totalAllocated, "peer", p, "peer total", 0, "global total", a.totalAllocatedAllPeers, "max per peer", a.perPeerMax, "global max", a.totalMemoryMax)
a.processPendingAllocations()
return nil
}
Expand Down Expand Up @@ -139,6 +146,7 @@ func (a *Allocator) processNextPendingAllocationForPeer(nextPeer *peerStatus) bo
a.totalAllocatedAllPeers += pendingAllocation.amount
nextPeer.totalAllocated += pendingAllocation.amount
nextPeer.pendingAllocations = nextPeer.pendingAllocations[1:]
log.Debugw("bytes allocated", "amount", pendingAllocation.amount, "peer", nextPeer.p, "peer total", nextPeer.totalAllocated, "global total", a.totalAllocatedAllPeers)
pendingAllocation.response <- nil
return true
}
Expand Down

0 comments on commit 2687228

Please sign in to comment.