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

This commit is contained in:
Liang Ding 2023-01-26 17:50:21 +08:00
parent 3c79a226be
commit f8ef5639c0
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
12 changed files with 40 additions and 29 deletions

View File

@ -980,7 +980,7 @@
"90": "[%d/%d] Created [%d] of search indexes of block-level elements [%s]",
"91": "Reading block tree data...",
"92": "Parsing document tree [%s]",
"93": "TODO",
"93": "[%d/%d] Cleaned up the index related to document [%s]",
"94": "Upload failed: %s",
"95": "Exiting...",
"96": "Synchronization failed when exiting. Please manually perform a synchronization to ensure that the local data is consistent with the cloud data",

View File

@ -980,7 +980,7 @@
"90": "[%d/%d] Creado [%d] de índices de búsqueda de elementos a nivel de bloque [%s]",
"91": "Leyendo datos del árbol de bloques...",
"92": "Analizando el árbol del documento [%s]",
"93": "TODO",
"93": "[%d/%d] ha limpiado el índice relacionado con el documento [%s]",
"94": "Carga fallida: %s",
"95": "Saliendo...",
"96": "La sincronización falló al salir. Por favor, realice manualmente una sincronización para asegurarse de que los datos locales son coherentes con los datos de la nube",

View File

@ -980,7 +980,7 @@
"90": "[%d/%d] Création de [%d] index de recherche d'éléments de niveau bloc [%s]",
"91": "Lecture des données de l'arborescence des blocs...",
"92": "Analyse de l'arborescence du document [%s]",
"93": "TODO",
"93": "[%d/%d] a nettoyé l'index lié au document [%s]",
"94": "Échec du téléchargement : %s",
"95": "Quitter le programme...",
"96": "La synchronisation a échoué lors de la sortie. Veuillez effectuer une synchronisation manuellement pour vous assurer que les données locales sont cohérentes avec les données du cloud",

View File

@ -980,7 +980,7 @@
"90": "[%d/%d] 已經建立 [%d] 個塊級元素的搜索索引 [%s]",
"91": "正在讀取塊樹數據...",
"92": "正在解析文檔樹 [%s]",
"93": "TODO",
"93": "[%d/%d] 已經清理文檔 [%s] 相關的索引",
"94": "上傳失敗:%s",
"95": "正在退出...",
"96": "退出時同步失敗,請手動執行一次同步以確保本地資料和雲端資料一致",

View File

@ -980,7 +980,7 @@
"90": "[%d/%d] 已经建立 [%d] 个块级元素的搜索索引 [%s]",
"91": "正在读取块树数据...",
"92": "正在解析文档树 [%s]",
"93": "TODO",
"93": "[%d/%d] 已经删除文档 [%s] 相关的索引",
"94": "上传失败:%s",
"95": "正在退出...",
"96": "退出时同步失败,请手动执行一次同步以确保本地数据和云端数据一致",

View File

@ -41,7 +41,7 @@ require (
github.com/shirou/gopsutil/v3 v3.22.12
github.com/siyuan-note/dejavu v0.0.0-20230117131301-821aa3adc1e7
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75
github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da
github.com/siyuan-note/eventbus v0.0.0-20230126092943-c6bf51e65ae2
github.com/siyuan-note/filelock v0.0.0-20221117095924-e1947438a35e
github.com/siyuan-note/httpclient v0.0.0-20230116125720-ee36ddf6f223
github.com/siyuan-note/logging v0.0.0-20221031125421-9b7234d79d8a

View File

@ -377,6 +377,8 @@ github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 h1:Bi7/7f29
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw=
github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da h1:/jNhl7LC+9BhkWvNxuJDdsNfA/2wvfuj9mqWx4CbV90=
github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da/go.mod h1:Sqo4FYX5lAXu7gWkbEdJF0e6P57tNNVV4WDKYDctokI=
github.com/siyuan-note/eventbus v0.0.0-20230126092943-c6bf51e65ae2 h1:njoj0265FOHRjF/O1aWDzdwEdYdLTZwhbuPd/hoLJT0=
github.com/siyuan-note/eventbus v0.0.0-20230126092943-c6bf51e65ae2/go.mod h1:Sqo4FYX5lAXu7gWkbEdJF0e6P57tNNVV4WDKYDctokI=
github.com/siyuan-note/filelock v0.0.0-20221117095924-e1947438a35e h1:i3RKrdrddr4AuaHJtoWYAEVNuR7Y9wIsEqPmuFFbJC4=
github.com/siyuan-note/filelock v0.0.0-20221117095924-e1947438a35e/go.mod h1:NmpSIVtIGy8eNWapjDIiiCw5+5r5wxC76k40oG+WRXQ=
github.com/siyuan-note/httpclient v0.0.0-20230116125720-ee36ddf6f223 h1:hG+gucj92x4Dl4lIe2G0WkPgBdlEBnnQCmYpghHeW54=

View File

@ -253,4 +253,16 @@ func init() {
util.SetBootDetails(msg)
util.ContextPushMsg(context, msg)
})
eventbus.Subscribe(eventbus.EvtSQLDeleteBlocks, func(context map[string]interface{}, rootID string) {
if util.ContainerAndroid == util.Container || util.ContainerIOS == util.Container {
// Android/iOS 端不显示数据索引和搜索索引状态提示 https://github.com/siyuan-note/siyuan/issues/6392
return
}
current := context["current"].(int) + 1
total := context["total"]
msg := fmt.Sprintf(Conf.Language(93), current, total, rootID)
util.SetBootDetails(msg)
util.ContextPushMsg(context, msg)
})
}

View File

@ -69,6 +69,7 @@ func autoFixIndex() {
for _, root := range roots {
rootMap[root.ID] = root
}
var deletes int
for _, rootID := range duplicatedRootIDs {
root := rootMap[rootID]
if nil == root {
@ -77,13 +78,13 @@ func autoFixIndex() {
//logging.LogWarnf("exist more than one tree [%s], reindex it", rootID)
sql.RemoveTreeQueue(root.Box, rootID)
deletes++
if util.IsExiting {
break
}
}
if 0 < len(duplicatedRootIDs) {
logging.LogWarnf("exist more than one tree duplicated [%d], reindex it", len(duplicatedRootIDs))
if 0 < deletes {
logging.LogWarnf("exist more than one tree duplicated [%d], reindex it", deletes)
}
util.PushStatusBar(Conf.Language(58))

View File

@ -17,7 +17,7 @@
package sql
import (
"runtime/debug"
"runtime"
"time"
"github.com/88250/lute/ast"
@ -45,7 +45,7 @@ func DisableCache() {
func ClearBlockCache() {
memCache.Clear()
debug.FreeOSMemory()
runtime.GC()
}
func putBlockCache(block *Block) {

View File

@ -34,6 +34,7 @@ import (
"github.com/88250/lute/parse"
"github.com/mattn/go-sqlite3"
_ "github.com/mattn/go-sqlite3"
"github.com/siyuan-note/eventbus"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
@ -947,7 +948,7 @@ func deleteFileAnnotationRefsByBoxTx(tx *sql.Tx, box string) (err error) {
return
}
func deleteByRootID(tx *sql.Tx, rootID string) (err error) {
func deleteByRootID(tx *sql.Tx, rootID string, context map[string]interface{}) (err error) {
stmt := "DELETE FROM blocks WHERE root_id = ?"
if err = execStmtTx(tx, stmt, rootID); nil != err {
return
@ -969,6 +970,7 @@ func deleteByRootID(tx *sql.Tx, rootID string) (err error) {
return
}
ClearBlockCache()
eventbus.Publish(eventbus.EvtSQLDeleteBlocks, context, rootID)
return
}

View File

@ -147,7 +147,7 @@ func execOp(op *dbQueueOperation, tx *sql.Tx, context map[string]interface{}) (e
case "delete":
err = batchDeleteByPathPrefix(tx, op.removeTreeBox, op.removeTreePath)
case "delete_id":
err = deleteByRootID(tx, op.removeTreeID)
err = deleteByRootID(tx, op.removeTreeID, context)
case "rename":
err = batchUpdateHPath(tx, op.renameTree.Box, op.renameTree.ID, op.renameTreeOldHPath, op.renameTree.HPath)
if nil != err {
@ -285,16 +285,13 @@ func RemoveTreeQueue(box, rootID string) {
dbQueueLock.Lock()
defer dbQueueLock.Unlock()
var tmp []*dbQueueOperation
// 将已有的 upsert 操作去重
for _, op := range operationQueue {
if "upsert" == op.action && op.upsertTree.ID != rootID {
tmp = append(tmp, op)
newOp := &dbQueueOperation{removeTreeIDBox: box, removeTreeID: rootID, inQueueTime: time.Now(), action: "delete_id"}
for i, op := range operationQueue {
if "delete_id" == op.action && op.removeTreeIDBox == box && op.removeTreeID == rootID {
operationQueue[i] = newOp
return
}
}
operationQueue = tmp
newOp := &dbQueueOperation{removeTreeIDBox: box, removeTreeID: rootID, inQueueTime: time.Now(), action: "delete_id"}
operationQueue = append(operationQueue, newOp)
}
@ -302,15 +299,12 @@ func RemoveTreePathQueue(treeBox, treePathPrefix string) {
dbQueueLock.Lock()
defer dbQueueLock.Unlock()
var tmp []*dbQueueOperation
// 将已有的 upsert 操作去重
for _, op := range operationQueue {
if "upsert" == op.action && (op.removeTreeBox != treeBox || op.upsertTree.Path != treePathPrefix) {
tmp = append(tmp, op)
newOp := &dbQueueOperation{removeTreeBox: treeBox, removeTreePath: treePathPrefix, inQueueTime: time.Now(), action: "delete"}
for i, op := range operationQueue {
if "delete" == op.action && (op.removeTreeBox == treeBox && op.removeTreePath == treePathPrefix) {
operationQueue[i] = newOp
return
}
}
operationQueue = tmp
newOp := &dbQueueOperation{removeTreeBox: treeBox, removeTreePath: treePathPrefix, inQueueTime: time.Now(), action: "delete"}
operationQueue = append(operationQueue, newOp)
}