Move method DB.getSemaphoreForTable()

This commit is contained in:
Eric Lippmann 2021-09-30 15:27:15 +02:00
parent 44b45fc429
commit 16dd4663ad

View file

@ -496,6 +496,19 @@ func (db *DB) Delete(ctx context.Context, entityType contracts.Entity, ids []int
return db.DeleteStreamed(ctx, entityType, idsCh)
}
func (db *DB) getSemaphoreForTable(table string) *semaphore.Weighted {
db.tableSemaphoresMu.Lock()
defer db.tableSemaphoresMu.Unlock()
if sem, ok := db.tableSemaphores[table]; ok {
return sem
} else {
sem = semaphore.NewWeighted(int64(db.Options.MaxConnectionsPerTable))
db.tableSemaphores[table] = sem
return sem
}
}
// IsRetryable checks whether the given error is retryable.
func IsRetryable(err error) bool {
if errors.Is(err, driver.ErrBadConn) {
@ -520,16 +533,3 @@ func IsRetryable(err error) bool {
return false
}
func (db *DB) getSemaphoreForTable(table string) *semaphore.Weighted {
db.tableSemaphoresMu.Lock()
defer db.tableSemaphoresMu.Unlock()
if sem, ok := db.tableSemaphores[table]; ok {
return sem
} else {
sem = semaphore.NewWeighted(int64(db.Options.MaxConnectionsPerTable))
db.tableSemaphores[table] = sem
return sem
}
}