in bulk_indexer_pool.go [152:176]
func (p *BulkIndexerPool) Put(id string, indexer *BulkIndexer) {
if indexer == nil {
return // No indexer to store, nothing to do.
}
p.mu.RLock()
defer p.mu.RUnlock()
entry, exists := p.entries[id]
if !exists {
return // unknown id, discard indexer
}
defer func() { // Always decrement the count and signal the condition.
entry.leased.Add(-1)
p.leased.Add(-1)
p.cond.Broadcast() // Signal waiting goroutines
}()
if indexer.Items() > 0 {
entry.nonEmpty <- indexer // Never discard non-empty indexers.
return
}
select {
case p.indexers <- indexer: // Return to the pool for later reuse.
default:
indexer = nil // If the pool is full, discard the indexer.
}
}