🐛 重建索引可能会导致内核崩溃 https://github.com/siyuan-note/siyuan/issues/7238

This commit is contained in:
Liang Ding 2023-02-02 18:14:00 +08:00
parent f28955283e
commit 7d2369ba28
No known key found for this signature in database
GPG key ID: 136F30F901A2231D

View file

@ -26,6 +26,7 @@ import (
"regexp"
"runtime"
"strings"
"sync"
"time"
"unicode/utf8"
@ -59,7 +60,12 @@ func init() {
})
}
var initDatabaseLock = sync.Mutex{}
func InitDatabase(forceRebuild bool) (err error) {
initDatabaseLock.Lock()
defer initDatabaseLock.Unlock()
ClearBlockCache()
DisableCache()
defer EnableCache()
@ -102,56 +108,83 @@ func InitDatabase(forceRebuild bool) (err error) {
}
func initDBTables() {
db.Exec("DROP TABLE stat")
_, err := db.Exec("CREATE TABLE stat (key, value)")
_, err := db.Exec("DROP TABLE IF EXISTS stat")
if nil != err {
logging.LogFatalf("drop table [stat] failed: %s", err)
}
_, err = db.Exec("CREATE TABLE stat (key, value)")
if nil != err {
logging.LogFatalf("create table [stat] failed: %s", err)
}
setDatabaseVer()
db.Exec("DROP TABLE blocks")
_, err = db.Exec("DROP TABLE IF EXISTS blocks")
if nil != err {
logging.LogFatalf("drop table [blocks] failed: %s", err)
}
_, err = db.Exec("CREATE TABLE blocks (id, parent_id, root_id, hash, box, path, hpath, name, alias, memo, tag, content, fcontent, markdown, length, type, subtype, ial, sort, created, updated)")
if nil != err {
logging.LogFatalf("create table [blocks] failed: %s", err)
}
db.Exec("DROP TABLE blocks_fts")
_, err = db.Exec("DROP TABLE IF EXISTS blocks_fts")
if nil != err {
logging.LogFatalf("drop table [blocks_fts] failed: %s", err)
}
_, err = db.Exec("CREATE VIRTUAL TABLE blocks_fts USING fts5(id UNINDEXED, parent_id UNINDEXED, root_id UNINDEXED, hash UNINDEXED, box UNINDEXED, path UNINDEXED, hpath, name, alias, memo, tag, content, fcontent, markdown UNINDEXED, length UNINDEXED, type UNINDEXED, subtype UNINDEXED, ial, sort UNINDEXED, created UNINDEXED, updated UNINDEXED, tokenize=\"siyuan\")")
if nil != err {
logging.LogFatalf("create table [blocks_fts] failed: %s", err)
}
db.Exec("DROP TABLE blocks_fts_case_insensitive")
_, err = db.Exec("DROP TABLE IF EXISTS blocks_fts_case_insensitive")
if nil != err {
logging.LogFatalf("drop table [blocks_fts_case_insensitive] failed: %s", err)
}
_, err = db.Exec("CREATE VIRTUAL TABLE blocks_fts_case_insensitive USING fts5(id UNINDEXED, parent_id UNINDEXED, root_id UNINDEXED, hash UNINDEXED, box UNINDEXED, path UNINDEXED, hpath, name, alias, memo, tag, content, fcontent, markdown UNINDEXED, length UNINDEXED, type UNINDEXED, subtype UNINDEXED, ial, sort UNINDEXED, created UNINDEXED, updated UNINDEXED, tokenize=\"siyuan case_insensitive\")")
if nil != err {
logging.LogFatalf("create table [blocks_fts_case_insensitive] failed: %s", err)
}
db.Exec("DROP TABLE spans")
_, err = db.Exec("DROP TABLE IF EXISTS spans")
if nil != err {
logging.LogFatalf("drop table [spans] failed: %s", err)
}
_, err = db.Exec("CREATE TABLE spans (id, block_id, root_id, box, path, content, markdown, type, ial)")
if nil != err {
logging.LogFatalf("create table [spans] failed: %s", err)
}
db.Exec("DROP TABLE assets")
_, err = db.Exec("DROP TABLE IF EXISTS assets")
if nil != err {
logging.LogFatalf("drop table [assets] failed: %s", err)
}
_, err = db.Exec("CREATE TABLE assets (id, block_id, root_id, box, docpath, path, name, title, hash)")
if nil != err {
logging.LogFatalf("create table [assets] failed: %s", err)
}
db.Exec("DROP TABLE attributes")
_, err = db.Exec("DROP TABLE IF EXISTS attributes")
if nil != err {
logging.LogFatalf("drop table [attributes] failed: %s", err)
}
_, err = db.Exec("CREATE TABLE attributes (id, name, value, type, block_id, root_id, box, path)")
if nil != err {
logging.LogFatalf("create table [attributes] failed: %s", err)
}
db.Exec("DROP TABLE refs")
_, err = db.Exec("DROP TABLE IF EXISTS refs")
if nil != err {
logging.LogFatalf("drop table [refs] failed: %s", err)
}
_, err = db.Exec("CREATE TABLE refs (id, def_block_id, def_block_parent_id, def_block_root_id, def_block_path, block_id, root_id, box, path, content, markdown, type)")
if nil != err {
logging.LogFatalf("create table [refs] failed: %s", err)
}
db.Exec("DROP TABLE file_annotation_refs")
_, err = db.Exec("DROP TABLE IF EXISTS file_annotation_refs")
if nil != err {
logging.LogFatalf("drop table [refs] failed: %s", err)
}
_, err = db.Exec("CREATE TABLE file_annotation_refs (id, file_path, annotation_id, block_id, root_id, box, path, content, type)")
if nil != err {
logging.LogFatalf("create table [refs] failed: %s", err)