Track the total size of the of the torrents map
This commit is contained in:
parent
f74ef67d08
commit
47613d4bbd
2 changed files with 9 additions and 1 deletions
|
@ -81,6 +81,7 @@ type Stats struct {
|
||||||
Announces uint64 `json:"Tracker.Announces"`
|
Announces uint64 `json:"Tracker.Announces"`
|
||||||
Scrapes uint64 `json:"Tracker.Scrapes"`
|
Scrapes uint64 `json:"Tracker.Scrapes"`
|
||||||
|
|
||||||
|
TorrentsSize uint64 `json:"Torrents.Size"`
|
||||||
TorrentsAdded uint64 `json:"Torrents.Added"`
|
TorrentsAdded uint64 `json:"Torrents.Added"`
|
||||||
TorrentsRemoved uint64 `json:"Torrents.Removed"`
|
TorrentsRemoved uint64 `json:"Torrents.Removed"`
|
||||||
TorrentsReaped uint64 `json:"Torrents.Reaped"`
|
TorrentsReaped uint64 `json:"Torrents.Reaped"`
|
||||||
|
@ -192,12 +193,15 @@ func (s *Stats) handleEvent(event int) {
|
||||||
|
|
||||||
case NewTorrent:
|
case NewTorrent:
|
||||||
s.TorrentsAdded++
|
s.TorrentsAdded++
|
||||||
|
s.TorrentsSize++
|
||||||
|
|
||||||
case DeletedTorrent:
|
case DeletedTorrent:
|
||||||
s.TorrentsRemoved++
|
s.TorrentsRemoved++
|
||||||
|
s.TorrentsSize--
|
||||||
|
|
||||||
case ReapedTorrent:
|
case ReapedTorrent:
|
||||||
s.TorrentsReaped++
|
s.TorrentsReaped++
|
||||||
|
s.TorrentsSize--
|
||||||
|
|
||||||
case AcceptedConnection:
|
case AcceptedConnection:
|
||||||
s.ConnectionsAccepted++
|
s.ConnectionsAccepted++
|
||||||
|
|
|
@ -44,6 +44,10 @@ func NewStorage(cfg *config.Config) *Storage {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Storage) Len() int {
|
||||||
|
return int(atomic.LoadInt32(&s.size))
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Storage) GetShardIndex(infohash string) uint32 {
|
func (s *Storage) GetShardIndex(infohash string) uint32 {
|
||||||
idx := fnv.New32()
|
idx := fnv.New32()
|
||||||
idx.Write([]byte(infohash))
|
idx.Write([]byte(infohash))
|
||||||
|
@ -198,7 +202,7 @@ func (s *Storage) PurgeInactivePeers(purgeEmptyTorrents bool, before time.Time)
|
||||||
|
|
||||||
// Build a list of keys to process.
|
// Build a list of keys to process.
|
||||||
index := 0
|
index := 0
|
||||||
maxkeys := int(atomic.LoadInt32(&s.size))
|
maxkeys := s.Len()
|
||||||
keys := make([]string, maxkeys)
|
keys := make([]string, maxkeys)
|
||||||
for i := range s.shards {
|
for i := range s.shards {
|
||||||
shard := &s.shards[i]
|
shard := &s.shards[i]
|
||||||
|
|
Loading…
Reference in a new issue