Skip to content

Commit 2687228

Browse files
authored
feat(allocator): add debug logging (#213)
Add debug logs to track behavior of allocator to check for errors
1 parent 07afd15 commit 2687228

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

allocator/allocator.go

+8
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import (
55
"sync"
66

77
pq "github.com/ipfs/go-ipfs-pq"
8+
logging "github.com/ipfs/go-log/v2"
89
peer "github.com/libp2p/go-libp2p-core/peer"
910
)
1011

12+
var log = logging.Logger("graphsync_allocator")
13+
1114
type Allocator struct {
1215
totalMemoryMax uint64
1316
perPeerMax uint64
@@ -58,8 +61,10 @@ func (a *Allocator) AllocateBlockMemory(p peer.ID, amount uint64) <-chan error {
5861
if (a.totalAllocatedAllPeers+amount <= a.totalMemoryMax) && (status.totalAllocated+amount <= a.perPeerMax) && len(status.pendingAllocations) == 0 {
5962
a.totalAllocatedAllPeers += amount
6063
status.totalAllocated += amount
64+
log.Debugw("bytes allocated", "amount", amount, "peer", p, "peer total", status.totalAllocated, "global total", a.totalAllocatedAllPeers)
6165
responseChan <- nil
6266
} else {
67+
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)
6368
pendingAllocation := pendingAllocation{p, amount, responseChan, a.nextAllocIndex}
6469
a.nextAllocIndex++
6570
status.pendingAllocations = append(status.pendingAllocations, pendingAllocation)
@@ -86,6 +91,7 @@ func (a *Allocator) ReleaseBlockMemory(p peer.ID, amount uint64) error {
8691
} else {
8792
a.totalAllocatedAllPeers = 0
8893
}
94+
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)
8995
a.peerStatusQueue.Update(status.Index())
9096
a.processPendingAllocations()
9197
return nil
@@ -104,6 +110,7 @@ func (a *Allocator) ReleasePeerMemory(p peer.ID) error {
104110
pendingAllocation.response <- errors.New("peer has been deallocated")
105111
}
106112
a.totalAllocatedAllPeers -= status.totalAllocated
113+
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)
107114
a.processPendingAllocations()
108115
return nil
109116
}
@@ -139,6 +146,7 @@ func (a *Allocator) processNextPendingAllocationForPeer(nextPeer *peerStatus) bo
139146
a.totalAllocatedAllPeers += pendingAllocation.amount
140147
nextPeer.totalAllocated += pendingAllocation.amount
141148
nextPeer.pendingAllocations = nextPeer.pendingAllocations[1:]
149+
log.Debugw("bytes allocated", "amount", pendingAllocation.amount, "peer", nextPeer.p, "peer total", nextPeer.totalAllocated, "global total", a.totalAllocatedAllPeers)
142150
pendingAllocation.response <- nil
143151
return true
144152
}

0 commit comments

Comments
 (0)