Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2026-02-07 10:45:37 +08:00
parent 81e1c40be0
commit 185a43a954
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -65,17 +65,15 @@ func WaitFlushTx() {
dbQueueLock.Lock()
defer dbQueueLock.Unlock()
var printLog bool
var lastPrintLog bool
var printLog, lastPrintLog bool
var i int
for len(operationQueue) > 0 || flushingTx.Load() {
// 使用条件变量等待,避免轮询浪费 CPU
if i == 0 {
// 第一次等待时使用较短的超时,与原逻辑保持一致
// 第一次等待时使用较短的超时
dbQueueCond.Wait()
} else {
// 后续等待添加超时检测,用于打印警告日志
// 后续等待添加超时检测用于打印警告日志
timer := time.AfterFunc(50*time.Millisecond, func() {
dbQueueCond.Broadcast()
})
@ -95,20 +93,6 @@ func WaitFlushTx() {
}
}
func isWritingDatabase(d time.Duration) bool {
// 等待指定时间后再检查状态
if d > 0 {
time.Sleep(d)
}
dbQueueLock.Lock()
defer dbQueueLock.Unlock()
if 0 < len(operationQueue) || flushingTx.Load() {
return true
}
return false
}
func ClearQueue() {
dbQueueLock.Lock()
defer dbQueueLock.Unlock()