Files
srdb/examples/webui/commands/inspect_all_sst.go
bourdon 23843493b8 重构代码结构并添加完整功能
主要改动:
- 重构目录结构:合并子目录到根目录,简化项目结构
- 添加完整的查询 API:支持复杂条件查询、字段选择、游标模式
- 实现 LSM-Tree Compaction:7层结构、Score-based策略、后台异步合并
- 添加 Web UI:基于 Lit 的现代化管理界面,支持数据浏览和 Manifest 查看
- 完善文档:添加 README.md 和 examples/webui/README.md

新增功能:
- Query Builder:链式查询 API,支持 Eq/Lt/Gt/In/Between/Contains 等操作符
- Web UI 组件:srdb-app、srdb-table-list、srdb-data-view、srdb-manifest-view 等
- 列选择持久化:自动保存到 localStorage
- 刷新按钮:一键刷新当前视图
- 主题切换:深色/浅色主题支持

代码优化:
- 使用 Go 1.24 新特性:range 7、min()、maps.Copy()、slices.Sort()
- 统一组件命名:所有 Web Components 使用 srdb-* 前缀
- CSS 优化:提取共享样式,减少重复代码
- 清理遗留代码:删除未使用的方法和样式
2025-10-08 23:04:47 +08:00

73 lines
1.7 KiB
Go

package commands
import (
"fmt"
"log"
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"code.tczkiot.com/srdb"
)
// InspectAllSST 检查所有 SST 文件
func InspectAllSST(sstDir string) {
// List all SST files
files, err := os.ReadDir(sstDir)
if err != nil {
log.Fatal(err)
}
var sstFiles []string
for _, file := range files {
if strings.HasSuffix(file.Name(), ".sst") {
sstFiles = append(sstFiles, file.Name())
}
}
sort.Strings(sstFiles)
fmt.Printf("Found %d SST files\n\n", len(sstFiles))
// Inspect each file
for _, filename := range sstFiles {
sstPath := filepath.Join(sstDir, filename)
reader, err := srdb.NewSSTableReader(sstPath)
if err != nil {
fmt.Printf("%s: ERROR - %v\n", filename, err)
continue
}
header := reader.GetHeader()
allKeys := reader.GetAllKeys()
// Extract file number
numStr := strings.TrimPrefix(filename, "000")
numStr = strings.TrimPrefix(numStr, "00")
numStr = strings.TrimPrefix(numStr, "0")
numStr = strings.TrimSuffix(numStr, ".sst")
fileNum, _ := strconv.Atoi(numStr)
fmt.Printf("File #%d (%s):\n", fileNum, filename)
fmt.Printf(" Header: MinKey=%d MaxKey=%d RowCount=%d\n", header.MinKey, header.MaxKey, header.RowCount)
fmt.Printf(" Actual: %d keys", len(allKeys))
if len(allKeys) > 0 {
fmt.Printf(" [%d ... %d]", allKeys[0], allKeys[len(allKeys)-1])
}
fmt.Printf("\n")
// Check if header matches actual keys
if len(allKeys) > 0 {
if header.MinKey != allKeys[0] || header.MaxKey != allKeys[len(allKeys)-1] {
fmt.Printf(" *** MISMATCH: Header says %d-%d but file has %d-%d ***\n",
header.MinKey, header.MaxKey, allKeys[0], allKeys[len(allKeys)-1])
}
}
reader.Close()
}
}