mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-04 20:32:12 +08:00
🎨 改进内核任务调度机制提升稳定性 https://github.com/siyuan-note/siyuan/issues/7113
This commit is contained in:
parent
492389470f
commit
c40355e47f
@ -37,6 +37,7 @@ 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"
|
||||||
@ -425,6 +426,7 @@ func Close(force bool, execInstallPkg int) (exitCode int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task.CloseWait()
|
||||||
Conf.Close()
|
Conf.Close()
|
||||||
sql.CloseDatabase()
|
sql.CloseDatabase()
|
||||||
treenode.SaveBlockTree(false)
|
treenode.SaveBlockTree(false)
|
||||||
|
@ -49,6 +49,7 @@ import (
|
|||||||
"github.com/siyuan-note/siyuan/kernel/cache"
|
"github.com/siyuan-note/siyuan/kernel/cache"
|
||||||
"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"
|
||||||
"github.com/studio-b12/gowebdav"
|
"github.com/studio-b12/gowebdav"
|
||||||
@ -501,16 +502,21 @@ func InitRepoKey() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var isCheckoutRepo bool
|
func CheckoutRepo(id string) {
|
||||||
|
task.PrependTask(task.RepoCheckout, checkoutRepo, id)
|
||||||
|
}
|
||||||
|
|
||||||
func CheckoutRepo(id string) (err error) {
|
func checkoutRepo(id string) {
|
||||||
|
var err error
|
||||||
if 1 > len(Conf.Repo.Key) {
|
if 1 > len(Conf.Repo.Key) {
|
||||||
err = errors.New(Conf.Language(26))
|
util.PushErrMsg(Conf.Language(26), 7000)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := newRepository()
|
repo, err := newRepository()
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
logging.LogErrorf("new repository failed: %s", err)
|
||||||
|
util.PushErrMsg(Conf.Language(141), 7000)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -525,23 +531,16 @@ func CheckoutRepo(id string) (err error) {
|
|||||||
Conf.Sync.Enabled = false
|
Conf.Sync.Enabled = false
|
||||||
Conf.Save()
|
Conf.Save()
|
||||||
|
|
||||||
if util.IsMutexLocked(&syncLock) {
|
|
||||||
err = errors.New("sync is running, please try again later")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
isCheckoutRepo = true
|
|
||||||
defer func() {
|
|
||||||
isCheckoutRepo = false
|
|
||||||
}()
|
|
||||||
|
|
||||||
_, _, err = repo.Checkout(id, map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBarAndProgress})
|
_, _, err = repo.Checkout(id, map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBarAndProgress})
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
logging.LogErrorf("checkout repository failed: %s", err)
|
||||||
util.PushClearProgress()
|
util.PushClearProgress()
|
||||||
|
util.PushErrMsg(Conf.Language(141), 7000)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
FullReindex()
|
FullReindex()
|
||||||
|
|
||||||
if syncEnabled {
|
if syncEnabled {
|
||||||
func() {
|
func() {
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -38,6 +37,7 @@ import (
|
|||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
"github.com/siyuan-note/siyuan/kernel/cache"
|
"github.com/siyuan-note/siyuan/kernel/cache"
|
||||||
"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"
|
||||||
)
|
)
|
||||||
@ -106,12 +106,7 @@ func AutoFlushTx() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var txLock = sync.Mutex{}
|
|
||||||
|
|
||||||
func flushTx() {
|
func flushTx() {
|
||||||
txLock.Lock()
|
|
||||||
defer txLock.Unlock()
|
|
||||||
|
|
||||||
defer logging.Recover()
|
defer logging.Recover()
|
||||||
|
|
||||||
currentTx = mergeTx()
|
currentTx = mergeTx()
|
||||||
@ -1224,7 +1219,7 @@ func updateRefText(refNode *ast.Node, changedDefNodes map[string]*ast.Node) (cha
|
|||||||
// AutoFixIndex 自动校验数据库索引 https://github.com/siyuan-note/siyuan/issues/7016
|
// AutoFixIndex 自动校验数据库索引 https://github.com/siyuan-note/siyuan/issues/7016
|
||||||
func AutoFixIndex() {
|
func AutoFixIndex() {
|
||||||
for {
|
for {
|
||||||
autoFixIndex()
|
task.AppendTask(task.DatabaseIndexFix, autoFixIndex)
|
||||||
time.Sleep(10 * time.Minute)
|
time.Sleep(10 * time.Minute)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1234,21 +1229,6 @@ var autoFixLock = sync.Mutex{}
|
|||||||
func autoFixIndex() {
|
func autoFixIndex() {
|
||||||
defer logging.Recover()
|
defer logging.Recover()
|
||||||
|
|
||||||
if isFullReindexing {
|
|
||||||
logging.LogInfof("skip check index caused by full reindexing")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if util.IsMutexLocked(&syncLock) {
|
|
||||||
logging.LogInfof("skip check index caused by sync lock")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if isCheckoutRepo {
|
|
||||||
logging.LogInfof("skip check index caused by checkout repo")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if util.IsMutexLocked(&autoFixLock) {
|
if util.IsMutexLocked(&autoFixLock) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1262,10 +1242,6 @@ func autoFixIndex() {
|
|||||||
boxPath := filepath.Join(util.DataDir, box.ID)
|
boxPath := filepath.Join(util.DataDir, box.ID)
|
||||||
var paths []string
|
var paths []string
|
||||||
filepath.Walk(boxPath, func(path string, info os.FileInfo, err error) error {
|
filepath.Walk(boxPath, func(path string, info os.FileInfo, err error) error {
|
||||||
if isFullReindexing {
|
|
||||||
return io.EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
if !info.IsDir() && filepath.Ext(path) == ".sy" {
|
if !info.IsDir() && filepath.Ext(path) == ".sy" {
|
||||||
p := path[len(boxPath):]
|
p := path[len(boxPath):]
|
||||||
p = filepath.ToSlash(p)
|
p = filepath.ToSlash(p)
|
||||||
@ -1278,19 +1254,11 @@ func autoFixIndex() {
|
|||||||
|
|
||||||
redundantPaths := treenode.GetRedundantPaths(box.ID, paths)
|
redundantPaths := treenode.GetRedundantPaths(box.ID, paths)
|
||||||
for _, p := range redundantPaths {
|
for _, p := range redundantPaths {
|
||||||
if isFullReindexing {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
treenode.RemoveBlockTreesByPath(p)
|
treenode.RemoveBlockTreesByPath(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
missingPaths := treenode.GetNotExistPaths(box.ID, paths)
|
missingPaths := treenode.GetNotExistPaths(box.ID, paths)
|
||||||
for i, p := range missingPaths {
|
for i, p := range missingPaths {
|
||||||
if isFullReindexing {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
id := path.Base(p)
|
id := path.Base(p)
|
||||||
id = strings.TrimSuffix(id, ".sy")
|
id = strings.TrimSuffix(id, ".sy")
|
||||||
if !ast.IsNodeIDPattern(id) {
|
if !ast.IsNodeIDPattern(id) {
|
||||||
@ -1308,10 +1276,6 @@ func autoFixIndex() {
|
|||||||
i := -1
|
i := -1
|
||||||
size := len(rootUpdatedMap)
|
size := len(rootUpdatedMap)
|
||||||
for rootID, updated := range rootUpdatedMap {
|
for rootID, updated := range rootUpdatedMap {
|
||||||
if isFullReindexing {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
i++
|
i++
|
||||||
|
|
||||||
rootUpdated := dbRootUpdatedMap[rootID]
|
rootUpdated := dbRootUpdatedMap[rootID]
|
||||||
@ -1341,10 +1305,6 @@ func autoFixIndex() {
|
|||||||
duplicatedRootIDs := sql.GetDuplicatedRootIDs()
|
duplicatedRootIDs := sql.GetDuplicatedRootIDs()
|
||||||
size := len(duplicatedRootIDs)
|
size := len(duplicatedRootIDs)
|
||||||
for i, rootID := range duplicatedRootIDs {
|
for i, rootID := range duplicatedRootIDs {
|
||||||
if isFullReindexing {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
root := sql.GetBlock(rootID)
|
root := sql.GetBlock(rootID)
|
||||||
if nil == root {
|
if nil == root {
|
||||||
continue
|
continue
|
||||||
@ -1359,10 +1319,6 @@ func autoFixIndex() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func reindexTreeByPath(box, p string, i, size int) {
|
func reindexTreeByPath(box, p string, i, size int) {
|
||||||
if isFullReindexing {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tree, err := LoadTree(box, p)
|
tree, err := LoadTree(box, p)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
return
|
||||||
@ -1372,10 +1328,6 @@ func reindexTreeByPath(box, p string, i, size int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func reindexTree(rootID string, i, size int) {
|
func reindexTree(rootID string, i, size int) {
|
||||||
if isFullReindexing {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
root := treenode.GetBlockTree(rootID)
|
root := treenode.GetBlockTree(rootID)
|
||||||
if nil == root {
|
if nil == root {
|
||||||
logging.LogWarnf("root block not found", rootID)
|
logging.LogWarnf("root block not found", rootID)
|
||||||
|
Loading…
Reference in New Issue
Block a user