-
Notifications
You must be signed in to change notification settings - Fork 1
14 Lifecycle.md
cyclonedll edited this page Jun 2, 2026
·
1 revision
stateDiagram-v2
[*] --> Created: new MyDb(options)
Created --> Active: InitializeSets() + open existing v4 file (if any)
Active --> Active: Add / Search / ...
Active --> Saving: SaveAsync() full snapshot / compaction
Active --> Appending: AppendAsync() segment append
Active --> TombstoneFlush: FlushTombstonesAsync() delete-only
Saving --> Active: Save complete
Appending --> Active: Footer rewritten
Appending --> Saving: EnableBackgroundMerge → MaybeAutoMergeAsync
TombstoneFlush --> Active: Footer rewritten
Active --> Disposing_Async: DisposeAsync()
Disposing_Async --> Saving_Final: SaveOnDispose=true -> SaveAsync()
Saving_Final --> Disposed: Release every QuiverSet
Disposing_Async --> Disposed: SaveOnDispose=false (default)
Active --> Disposed: Dispose() (no save)
Disposed --> [*]
| Disposal Method | Auto-Save | Behavior | Recommended Scenario |
|---|---|---|---|
Dispose() |
❌ No save | Releases resources only | Manual save timing control |
DisposeAsync() |
❌ No save (default) | Releases resources only unless SaveOnDispose = true
|
Explicit SaveAsync() before disposal or AppendAsync batched ingest |
⚠️ Default: no auto-save on disposal —DisposeAsync()does not automatically callSaveAsync()unlessQuiverDbOptions.SaveOnDispose = true. This avoids the trap where a batch-ingest loop that doesAppendAsync(); Clear();followed byawait usingdisposal would overwrite the file with an empty snapshot when auto-save is enabled. Always callSaveAsync()explicitly when you need the data persisted.
// ✅ Read-mostly / mixed workloads: explicit save before disposal
await using var db = new MyDocumentDb();
await db.LoadAsync();
db.Documents.Add(new Document { ... });
await db.SaveAsync();
// Scope ends -> DisposeAsync -> release
// ✅ Streaming / batched ingest: synchronous using + explicit AppendAsync
using var ingest = new MyDocumentDb();
await ingest.LoadAsync();
foreach (var batch in batches)
{
foreach (var doc in batch) ingest.Documents.Add(doc);
await ingest.AppendAsync(); // segment append, O(Δ)
ingest.Documents.Clear(); // free memory before next batch
}
// Dispose() releases resources WITHOUT a final SaveAsync
// ✅ Delete-heavy workload
await using var deleter = new MyDocumentDb();
await deleter.LoadAsync();
foreach (var key in stale) deleter.Documents.RemoveByKey(key);
await deleter.FlushTombstonesAsync(); // only tombstone segment appendedQuiverSet implements IDisposable, releasing the internal ReaderWriterLockSlim. All operations throw ObjectDisposedException after disposal.
| # | 章节 |
|---|---|
| 01 | 版本说明 |
| 02 | 产品概述 |
| 03 | 架构概述 |
| 04 | 快速开始 |
| 05 | 核心概念 |
| 06 | 距离度量 |
| 07 | 索引类型 |
| 08 | CRUD 操作 |
| 09 | 向量搜索 |
| 10 | 持久化存储 |
| 11 | 迁移系统 |
| 11a | 模式迁移 |
| 12 | 多向量字段支持 |
| 13 | 线程安全与并发 |
| 14 | 生命周期管理 |
| 15 | 配置选项 |
| 16 | 内部实现细节 |
| 17 | 完整示例 |
| 18 | API 参考速查表 |
| 19 | 使用建议 |