Переглянути джерело

:art: 改进内核任务调度机制提升稳定性 https://github.com/siyuan-note/siyuan/issues/7113

Liang Ding 2 роки тому
батько
коміт
e8fe3a77b3
3 змінених файлів з 23 додано та 12 видалено
  1. 0 2
      kernel/model/conf.go
  2. 23 0
      kernel/model/transaction.go
  3. 0 10
      kernel/task/queue.go

+ 0 - 2
kernel/model/conf.go

@@ -38,7 +38,6 @@ import (
 	"github.com/siyuan-note/logging"
 	"github.com/siyuan-note/logging"
 	"github.com/siyuan-note/siyuan/kernel/conf"
 	"github.com/siyuan-note/siyuan/kernel/conf"
 	"github.com/siyuan-note/siyuan/kernel/sql"
 	"github.com/siyuan-note/siyuan/kernel/sql"
-	"github.com/siyuan-note/siyuan/kernel/task"
 	"github.com/siyuan-note/siyuan/kernel/treenode"
 	"github.com/siyuan-note/siyuan/kernel/treenode"
 	"github.com/siyuan-note/siyuan/kernel/util"
 	"github.com/siyuan-note/siyuan/kernel/util"
 	"golang.org/x/text/language"
 	"golang.org/x/text/language"
@@ -422,7 +421,6 @@ func Close(force bool, execInstallPkg int) (exitCode int) {
 		}
 		}
 	}
 	}
 
 
-	task.CloseWait()
 	Conf.Close()
 	Conf.Close()
 	sql.CloseDatabase()
 	sql.CloseDatabase()
 	treenode.SaveBlockTree(false)
 	treenode.SaveBlockTree(false)

+ 23 - 0
kernel/model/transaction.go

@@ -1303,6 +1303,13 @@ func autoFixIndex() {
 			}
 			}
 
 
 			reindexTreeByPath(box.ID, p, i, size)
 			reindexTreeByPath(box.ID, p, i, size)
+			if util.IsExiting {
+				break
+			}
+		}
+
+		if util.IsExiting {
+			break
 		}
 		}
 	}
 	}
 
 
@@ -1347,6 +1354,10 @@ func autoFixIndex() {
 		logging.LogWarnf("exist more than one tree [%s], reindex it", rootID)
 		logging.LogWarnf("exist more than one tree [%s], reindex it", rootID)
 		sql.RemoveTreeQueue(root.Box, rootID)
 		sql.RemoveTreeQueue(root.Box, rootID)
 		reindexTree(rootID, i, size)
 		reindexTree(rootID, i, size)
+
+		if util.IsExiting {
+			break
+		}
 	}
 	}
 
 
 	util.PushStatusBar(Conf.Language(185))
 	util.PushStatusBar(Conf.Language(185))
@@ -1358,6 +1369,10 @@ func reindexTreeByUpdated(rootUpdatedMap, dbRootUpdatedMap map[string]string, bl
 	for rootID, updated := range rootUpdatedMap {
 	for rootID, updated := range rootUpdatedMap {
 		i++
 		i++
 
 
+		if util.IsExiting {
+			break
+		}
+
 		rootUpdated := dbRootUpdatedMap[rootID]
 		rootUpdated := dbRootUpdatedMap[rootID]
 		if "" == rootUpdated {
 		if "" == rootUpdated {
 			logging.LogWarnf("not found tree [%s] in database, reindex it", rootID)
 			logging.LogWarnf("not found tree [%s] in database, reindex it", rootID)
@@ -1378,6 +1393,10 @@ func reindexTreeByUpdated(rootUpdatedMap, dbRootUpdatedMap map[string]string, bl
 			reindexTree(rootID, i, size)
 			reindexTree(rootID, i, size)
 			continue
 			continue
 		}
 		}
+
+		if util.IsExiting {
+			break
+		}
 	}
 	}
 
 
 	for rootID, _ := range dbRootUpdatedMap {
 	for rootID, _ := range dbRootUpdatedMap {
@@ -1385,6 +1404,10 @@ func reindexTreeByUpdated(rootUpdatedMap, dbRootUpdatedMap map[string]string, bl
 			logging.LogWarnf("tree [%s] is not in block tree, remove it from [%s]", rootID, blocksTable)
 			logging.LogWarnf("tree [%s] is not in block tree, remove it from [%s]", rootID, blocksTable)
 			sql.DeleteTree(blocksTable, rootID)
 			sql.DeleteTree(blocksTable, rootID)
 		}
 		}
+
+		if util.IsExiting {
+			break
+		}
 	}
 	}
 }
 }
 
 

+ 0 - 10
kernel/task/queue.go

@@ -161,16 +161,6 @@ func Loop() {
 	}
 	}
 }
 }
 
 
-func CloseWait() {
-	taskQueueStatus = QueueStatusClosing
-	for {
-		time.Sleep(10 * time.Millisecond)
-		if 1 > len(taskQueue) {
-			break
-		}
-	}
-}
-
 func clearQueue() {
 func clearQueue() {
 	queueLock.Lock()
 	queueLock.Lock()
 	defer queueLock.Unlock()
 	defer queueLock.Unlock()