🎨 细化云端同步锁提升稳定性 Fix https://github.com/siyuan-note/siyuan/issues/5887

This commit is contained in:
Liang Ding 2022-09-15 23:24:23 +08:00
parent a942ae6a1b
commit b53cb6c78b
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
4 changed files with 20 additions and 2 deletions

View file

@ -918,9 +918,12 @@ func loadNodesByMode(node *ast.Node, inputIndex, mode, size int, isDoc, isHeadin
}
func writeJSONQueue(tree *parse.Tree) (err error) {
writingDataLock.Lock()
if err = filesys.WriteTree(tree); nil != err {
writingDataLock.Unlock()
return
}
writingDataLock.Unlock()
sql.UpsertTreeQueue(tree)
return
}
@ -931,9 +934,12 @@ func indexWriteJSONQueue(tree *parse.Tree) (err error) {
}
func renameWriteJSONQueue(tree *parse.Tree, oldHPath string) (err error) {
writingDataLock.Unlock()
if err = filesys.WriteTree(tree); nil != err {
writingDataLock.Unlock()
return
}
writingDataLock.Unlock()
sql.RenameTreeQueue(tree, oldHPath)
treenode.ReindexBlockTree(tree)
return

View file

@ -63,6 +63,9 @@ func SyncData(boot, exit, byHand bool) {
return
}
writingDataLock.Lock()
defer writingDataLock.Unlock()
if util.IsMutexLocked(&syncLock) {
logging.LogWarnf("sync is in progress")
planSyncAfter(30 * time.Second)

View file

@ -110,9 +110,12 @@ func AutoFlushTx() {
}
}
var txLock = sync.Mutex{}
func flushTx() {
writingDataLock.Lock()
defer writingDataLock.Unlock()
txLock.Lock()
defer txLock.Unlock()
defer logging.Recover()
currentTx = mergeTx()

View file

@ -34,6 +34,9 @@ import (
)
func InsertLocalAssets(id string, assetPaths []string) (succMap map[string]interface{}, err error) {
writingDataLock.Lock()
defer writingDataLock.Unlock()
succMap = map[string]interface{}{}
bt := treenode.GetBlockTree(id)
@ -101,6 +104,9 @@ func Upload(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(200, ret)
writingDataLock.Lock()
defer writingDataLock.Unlock()
form, err := c.MultipartForm()
if nil != err {
logging.LogErrorf("insert asset failed: %s", err)