xdb verify desc and docs

This commit is contained in:
lion 2025-09-07 18:09:57 +08:00
parent 7cc7d4d9cf
commit beb0e452ce
2 changed files with 15 additions and 1 deletions

View File

@ -22,6 +22,19 @@ version = xdb.IPv6
// 备注:以下演示直接使用 dbPath 和 version 变量
```
### 文件验证
建议您主动去验证 xdb 文件的适用性,因为后期的一些新功能可能会导致目前的 Searcher 版本无法适用当前的 xdb 文件,验证可以避免运行过程中的一些不可预测的错误。
你不需要每次都去验证,例如在服务启动的时候,或者手动调用命令验证确认版本匹配即可,不要在每次创建的 Searcher 的时候运行验证,这样会影响查询的响应速度,尤其是高并发的使用场景。
```golang
err := xdb.VerifyFromFile(dbPath)
if err != nil {
// err 包含的验证的错误
return fmt.Errorf("xdb file verify: %w", err)
}
// 当前使用的 Searcher 可以安全的用于对 dbPath 指向的 xdb 的查询操作
```
### 完全基于文件的查询
```golang

View File

@ -236,7 +236,8 @@ func createSearcher(dbPath string, cachePolicy string) (*xdb.Searcher, error) {
}
// verify the xdb file
// @see the util.Verify function for details
// @Note: do NOT call it every time you create a searcher since this will slow down the search response.
// @see the util.Verify function for details.
err = xdb.Verify(handle)
if err != nil {
return nil, fmt.Errorf("xdb verify: %w", err)