mirror of
https://github.com/LBRYFoundation/tracker.git
synced 2025-08-28 16:01:32 +00:00
tracker: stop exporting shard methods
This commit is contained in:
parent
6f742f29e1
commit
e02f1dd0ea
1 changed files with 14 additions and 14 deletions
|
@ -48,14 +48,14 @@ func (s *Storage) Len() int {
|
||||||
return int(atomic.LoadInt32(&s.size))
|
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))
|
||||||
return idx.Sum32() % uint32(len(s.shards))
|
return idx.Sum32() % uint32(len(s.shards))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) GetTorrentShard(infohash string, readonly bool) *Torrents {
|
func (s *Storage) getTorrentShard(infohash string, readonly bool) *Torrents {
|
||||||
shardindex := s.GetShardIndex(infohash)
|
shardindex := s.getShardIndex(infohash)
|
||||||
if readonly {
|
if readonly {
|
||||||
s.shards[shardindex].RLock()
|
s.shards[shardindex].RLock()
|
||||||
} else {
|
} else {
|
||||||
|
@ -65,7 +65,7 @@ func (s *Storage) GetTorrentShard(infohash string, readonly bool) *Torrents {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) TouchTorrent(infohash string) error {
|
func (s *Storage) TouchTorrent(infohash string) error {
|
||||||
shard := s.GetTorrentShard(infohash, false)
|
shard := s.getTorrentShard(infohash, false)
|
||||||
defer shard.Unlock()
|
defer shard.Unlock()
|
||||||
|
|
||||||
torrent, exists := shard.torrents[infohash]
|
torrent, exists := shard.torrents[infohash]
|
||||||
|
@ -79,7 +79,7 @@ func (s *Storage) TouchTorrent(infohash string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) FindTorrent(infohash string) (*models.Torrent, error) {
|
func (s *Storage) FindTorrent(infohash string) (*models.Torrent, error) {
|
||||||
shard := s.GetTorrentShard(infohash, true)
|
shard := s.getTorrentShard(infohash, true)
|
||||||
defer shard.RUnlock()
|
defer shard.RUnlock()
|
||||||
|
|
||||||
torrent, exists := shard.torrents[infohash]
|
torrent, exists := shard.torrents[infohash]
|
||||||
|
@ -91,7 +91,7 @@ func (s *Storage) FindTorrent(infohash string) (*models.Torrent, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) PutTorrent(torrent *models.Torrent) {
|
func (s *Storage) PutTorrent(torrent *models.Torrent) {
|
||||||
shard := s.GetTorrentShard(torrent.Infohash, false)
|
shard := s.getTorrentShard(torrent.Infohash, false)
|
||||||
defer shard.Unlock()
|
defer shard.Unlock()
|
||||||
|
|
||||||
_, exists := shard.torrents[torrent.Infohash]
|
_, exists := shard.torrents[torrent.Infohash]
|
||||||
|
@ -102,7 +102,7 @@ func (s *Storage) PutTorrent(torrent *models.Torrent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) DeleteTorrent(infohash string) {
|
func (s *Storage) DeleteTorrent(infohash string) {
|
||||||
shard := s.GetTorrentShard(infohash, false)
|
shard := s.getTorrentShard(infohash, false)
|
||||||
defer shard.Unlock()
|
defer shard.Unlock()
|
||||||
|
|
||||||
if _, exists := shard.torrents[infohash]; exists {
|
if _, exists := shard.torrents[infohash]; exists {
|
||||||
|
@ -112,7 +112,7 @@ func (s *Storage) DeleteTorrent(infohash string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) IncrementTorrentSnatches(infohash string) error {
|
func (s *Storage) IncrementTorrentSnatches(infohash string) error {
|
||||||
shard := s.GetTorrentShard(infohash, false)
|
shard := s.getTorrentShard(infohash, false)
|
||||||
defer shard.Unlock()
|
defer shard.Unlock()
|
||||||
|
|
||||||
torrent, exists := shard.torrents[infohash]
|
torrent, exists := shard.torrents[infohash]
|
||||||
|
@ -126,7 +126,7 @@ func (s *Storage) IncrementTorrentSnatches(infohash string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) PutLeecher(infohash string, p *models.Peer) error {
|
func (s *Storage) PutLeecher(infohash string, p *models.Peer) error {
|
||||||
shard := s.GetTorrentShard(infohash, false)
|
shard := s.getTorrentShard(infohash, false)
|
||||||
defer shard.Unlock()
|
defer shard.Unlock()
|
||||||
|
|
||||||
torrent, exists := shard.torrents[infohash]
|
torrent, exists := shard.torrents[infohash]
|
||||||
|
@ -140,7 +140,7 @@ func (s *Storage) PutLeecher(infohash string, p *models.Peer) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) DeleteLeecher(infohash string, p *models.Peer) error {
|
func (s *Storage) DeleteLeecher(infohash string, p *models.Peer) error {
|
||||||
shard := s.GetTorrentShard(infohash, false)
|
shard := s.getTorrentShard(infohash, false)
|
||||||
defer shard.Unlock()
|
defer shard.Unlock()
|
||||||
|
|
||||||
torrent, exists := shard.torrents[infohash]
|
torrent, exists := shard.torrents[infohash]
|
||||||
|
@ -154,7 +154,7 @@ func (s *Storage) DeleteLeecher(infohash string, p *models.Peer) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) PutSeeder(infohash string, p *models.Peer) error {
|
func (s *Storage) PutSeeder(infohash string, p *models.Peer) error {
|
||||||
shard := s.GetTorrentShard(infohash, false)
|
shard := s.getTorrentShard(infohash, false)
|
||||||
defer shard.Unlock()
|
defer shard.Unlock()
|
||||||
|
|
||||||
torrent, exists := shard.torrents[infohash]
|
torrent, exists := shard.torrents[infohash]
|
||||||
|
@ -168,7 +168,7 @@ func (s *Storage) PutSeeder(infohash string, p *models.Peer) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) DeleteSeeder(infohash string, p *models.Peer) error {
|
func (s *Storage) DeleteSeeder(infohash string, p *models.Peer) error {
|
||||||
shard := s.GetTorrentShard(infohash, false)
|
shard := s.getTorrentShard(infohash, false)
|
||||||
defer shard.Unlock()
|
defer shard.Unlock()
|
||||||
|
|
||||||
torrent, exists := shard.torrents[infohash]
|
torrent, exists := shard.torrents[infohash]
|
||||||
|
@ -182,7 +182,7 @@ func (s *Storage) DeleteSeeder(infohash string, p *models.Peer) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) PurgeInactiveTorrent(infohash string) error {
|
func (s *Storage) PurgeInactiveTorrent(infohash string) error {
|
||||||
shard := s.GetTorrentShard(infohash, false)
|
shard := s.getTorrentShard(infohash, false)
|
||||||
defer shard.Unlock()
|
defer shard.Unlock()
|
||||||
|
|
||||||
torrent, exists := shard.torrents[infohash]
|
torrent, exists := shard.torrents[infohash]
|
||||||
|
@ -223,7 +223,7 @@ func (s *Storage) PurgeInactivePeers(purgeEmptyTorrents bool, before time.Time)
|
||||||
// Process the keys while allowing other goroutines to run.
|
// Process the keys while allowing other goroutines to run.
|
||||||
for _, infohash := range keys {
|
for _, infohash := range keys {
|
||||||
runtime.Gosched()
|
runtime.Gosched()
|
||||||
shard := s.GetTorrentShard(infohash, false)
|
shard := s.getTorrentShard(infohash, false)
|
||||||
torrent := shard.torrents[infohash]
|
torrent := shard.torrents[infohash]
|
||||||
|
|
||||||
if torrent == nil {
|
if torrent == nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue