⚡️ perf(fqapi): 移除缓存层全局串行锁
- 删除 cache_manager/audio_proxy/device_key_pool 中 21 处 cacheMutex:database/sql 连接池本身并发安全,SQLite 已配 WAL + busy_timeout,PostgreSQL 无并发写限制 - contentRequestCount 三函数由互斥锁改为 atomic.Int64 - cache_manager 中 config.GetConfig() 改为 GetAppConfig(),消除配置未初始化时 log.Fatal 崩溃整个进程的隐患 - VACUUM 与写操作的低频并发冲突由 busy_timeout 兜底(已注释说明) - 新增 TestConcurrentCacheAccess:8 goroutine 并发读写缓存,-race 验证无死锁无竞争
This commit is contained in:
1 parent
24c7e4b6fd
commit
f0d89b462b
4 files changed
+68
-68
No files matched your search
@@ -399,8 +399,6 @@ func (p *DeviceKeyPool) saveDeviceToDB(item *DeviceKeyItem) error {
|
||||
return fmt.Errorf("数据库未初始化")
|
||||
}
|
||||
|
||||
cacheMutex.Lock()
|
||||
defer cacheMutex.Unlock()
|
||||
|
||||
// RETURNING id 同时兼容 SQLite(3.35+) 与 PostgreSQL,替代 LastInsertId()
|
||||
err := cacheDB.QueryRow(q(`
|
||||
@@ -419,8 +417,6 @@ func (p *DeviceKeyPool) updateDeviceInDB(item *DeviceKeyItem) error {
|
||||
return fmt.Errorf("数据库未初始化")
|
||||
}
|
||||
|
||||
cacheMutex.Lock()
|
||||
defer cacheMutex.Unlock()
|
||||
|
||||
_, err := cacheDB.Exec(q(`
|
||||
UPDATE device_pool
|
||||
@@ -438,8 +434,6 @@ func (p *DeviceKeyPool) removeInvalidFromDB() error {
|
||||
return fmt.Errorf("数据库未初始化")
|
||||
}
|
||||
|
||||
cacheMutex.Lock()
|
||||
defer cacheMutex.Unlock()
|
||||
|
||||
result, err := cacheDB.Exec(`DELETE FROM device_pool WHERE is_valid = 0`)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user