@@ -5,9 +5,12 @@ import (
5
5
"sync"
6
6
7
7
pq "github.com/ipfs/go-ipfs-pq"
8
+ logging "github.com/ipfs/go-log/v2"
8
9
peer "github.com/libp2p/go-libp2p-core/peer"
9
10
)
10
11
12
+ var log = logging .Logger ("graphsync_allocator" )
13
+
11
14
type Allocator struct {
12
15
totalMemoryMax uint64
13
16
perPeerMax uint64
@@ -58,8 +61,10 @@ func (a *Allocator) AllocateBlockMemory(p peer.ID, amount uint64) <-chan error {
58
61
if (a .totalAllocatedAllPeers + amount <= a .totalMemoryMax ) && (status .totalAllocated + amount <= a .perPeerMax ) && len (status .pendingAllocations ) == 0 {
59
62
a .totalAllocatedAllPeers += amount
60
63
status .totalAllocated += amount
64
+ log .Debugw ("bytes allocated" , "amount" , amount , "peer" , p , "peer total" , status .totalAllocated , "global total" , a .totalAllocatedAllPeers )
61
65
responseChan <- nil
62
66
} 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 )
63
68
pendingAllocation := pendingAllocation {p , amount , responseChan , a .nextAllocIndex }
64
69
a .nextAllocIndex ++
65
70
status .pendingAllocations = append (status .pendingAllocations , pendingAllocation )
@@ -86,6 +91,7 @@ func (a *Allocator) ReleaseBlockMemory(p peer.ID, amount uint64) error {
86
91
} else {
87
92
a .totalAllocatedAllPeers = 0
88
93
}
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 )
89
95
a .peerStatusQueue .Update (status .Index ())
90
96
a .processPendingAllocations ()
91
97
return nil
@@ -104,6 +110,7 @@ func (a *Allocator) ReleasePeerMemory(p peer.ID) error {
104
110
pendingAllocation .response <- errors .New ("peer has been deallocated" )
105
111
}
106
112
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 )
107
114
a .processPendingAllocations ()
108
115
return nil
109
116
}
@@ -139,6 +146,7 @@ func (a *Allocator) processNextPendingAllocationForPeer(nextPeer *peerStatus) bo
139
146
a .totalAllocatedAllPeers += pendingAllocation .amount
140
147
nextPeer .totalAllocated += pendingAllocation .amount
141
148
nextPeer .pendingAllocations = nextPeer .pendingAllocations [1 :]
149
+ log .Debugw ("bytes allocated" , "amount" , pendingAllocation .amount , "peer" , nextPeer .p , "peer total" , nextPeer .totalAllocated , "global total" , a .totalAllocatedAllPeers )
142
150
pendingAllocation .response <- nil
143
151
return true
144
152
}
0 commit comments