Files
seqlog/example/webapp/README.md
bourdon de39339620 重构:统一使用索引(Index)替代位置(Position)进行状态判断
## 主要变更

### 架构改进
- 明确索引(Index)与偏移(Offset)的职责分离
  - Index: 记录序号(逻辑概念),用于状态判断
  - Offset: 文件字节位置(物理概念),仅用于 I/O 操作

### API 变更
- 删除所有 Position 相关方法:
  - `LogCursor.StartPos()/EndPos()`
  - `LogTailer.GetStartPos()/GetEndPos()`
  - `TopicProcessor.GetProcessingPosition()/GetReadPosition()`
  - `Seqlog.GetProcessingPosition()/GetReadPosition()`

- 新增索引方法:
  - `LogCursor.StartIndex()/EndIndex()`
  - `LogTailer.GetStartIndex()/GetEndIndex()`
  - `TopicProcessor.GetProcessingIndex()/GetReadIndex()`
  - `Seqlog.GetProcessingIndex()/GetReadIndex()`
  - `Seqlog.GetProcessor()` - 获取 processor 实例以访问 Index

### 查询接口变更
- `RecordQuery.QueryOldest(startIndex, count, startIdx, endIdx)` - 使用索引参数
- `RecordQuery.QueryNewest(endIndex, count, startIdx, endIdx)` - 使用索引参数
- `RecordQuery.QueryAt(position, direction, count, startIdx, endIdx)` - startIdx/endIdx 用于状态判断

### 性能优化
- 状态判断改用整数比较,不再需要计算偏移量
- 减少不必要的索引到偏移的转换
- 只在实际文件 I/O 时才获取 offset

### 测试更新
- 更新所有测试用例使用新的 Index API
- 更新示例代码(topic_processor_example.go, webapp/main.go)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-03 23:50:53 +08:00

66 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Seqlog Web 演示
一个简单的 Web 应用,展示 Seqlog 的实际使用场景。
## 功能
### 后端模拟业务
- 每 2 秒自动生成业务日志
- 随机生成不同 topicapp、api、database、cache
- 随机生成不同操作(查询、插入、更新、删除、备份、恢复、同步等)
- **随机日志大小**2KB ~ 10MB
- 80% 小日志2KB - 100KB
- 15% 中日志100KB - 1MB
- 5% 大日志1MB - 10MB
### Web 查询界面
- 查看所有 topics
- 查看每个 topic 的统计信息(显示实际字节数)
- 查询日志(支持向前/向后翻页)
- 实时自动刷新
- 日志状态标注(已处理/处理中/待处理)
## 快速启动
```bash
cd example/webapp
go run main.go
```
访问: http://localhost:8080
## 使用说明
1. **选择 Topic**: 点击左侧的 topic 列表
2. **查看统计**: 左侧会显示该 topic 的统计信息(包括总字节数)
3. **查看日志**: 右侧显示日志内容,带状态标注
4. **刷新**: 点击"刷新日志"按钮或等待自动刷新
5. **翻页**: 使用"向前翻页"和"向后翻页"按钮
6. **自定义范围**: 修改显示范围的数字,控制查询条数
## 界面说明
- **绿色边框**: 已处理的日志
- **黄色边框**: 正在处理的日志
- **灰色边框**: 待处理的日志
## 性能测试
由于日志大小范围很大2KB ~ 10MB可以观察到
- 小日志处理速度很快
- 大日志会占用更多存储空间
- 统计信息会显示真实的字节数增长
## API 接口
- `GET /api/topics` - 获取所有 topics
- `GET /api/stats?topic=<name>` - 获取统计信息
- `GET /api/query?topic=<name>&backward=10&forward=10` - 查询日志
- `POST /api/write` - 手动写入日志
## 技术栈
- 后端: Go + Seqlog
- 前端: 原生 HTML/CSS/JavaScript
- 无需额外依赖