Skip to content

Commit

Permalink
🎨 Improve the stability of creating data snapshots siyuan-note/siyuan…
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Sep 16, 2023
1 parent 0674d36 commit eb22e98
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,9 @@ func (repo *Repo) putFileChunks(file *entity.File, context map[string]interface{
return
}

filelock.RWLock.Lock()
defer filelock.RWLock.Unlock()

reader, err := os.OpenFile(absPath, os.O_RDONLY, 0644)
if nil != err {
logging.LogErrorf("open file [%s] failed: %s", absPath, err)
Expand All @@ -497,13 +500,16 @@ func (repo *Repo) putFileChunks(file *entity.File, context map[string]interface{
chnkr := chunker.NewWithBoundaries(reader, repo.chunkPol, chunker.MinSize, chunker.MaxSize)
for {
buf := make([]byte, chunker.MaxSize)
var chnk chunker.Chunk
chnk, err = chnkr.Next(buf)
if io.EOF == err {
chnk, chnkErr := chnkr.Next(buf)
if io.EOF == chnkErr {
break
}
if nil != err {
logging.LogErrorf("chunk file [%s] failed: %s", absPath, err)
if nil != chnkErr {
err = chnkErr
logging.LogErrorf("chunk file [%s] failed: %s", absPath, chnkErr)
if closeErr := reader.Close(); nil != closeErr {
logging.LogErrorf("close file [%s] failed: %s", absPath, closeErr)
}
return
}

Expand All @@ -512,19 +518,20 @@ func (repo *Repo) putFileChunks(file *entity.File, context map[string]interface{
chunk := &entity.Chunk{ID: chunkHash, Data: chnk.Data}
if err = repo.store.PutChunk(chunk); nil != err {
logging.LogErrorf("put chunk [%s] failed: %s", chunkHash, err)
if closeErr := reader.Close(); nil != closeErr {
logging.LogErrorf("close file [%s] failed: %s", absPath, closeErr)
}
return
}
}

if closeErr := reader.Close(); nil != closeErr {
logging.LogErrorf("close file [%s] failed: %s", absPath, closeErr)
if err = reader.Close(); nil != err {
logging.LogErrorf("close file [%s] failed: %s", absPath, err)
return
}

eventbus.Publish(eventbus.EvtIndexUpsertFile, context, count, total)
err = repo.store.PutFile(file)
if nil != err {
return
}
return
}

Expand Down

0 comments on commit eb22e98

Please sign in to comment.