feat: introduce global meta store and root store concept, and update CLI to manage active store
This commit is contained in:
@@ -187,14 +187,14 @@ Note: KV stores multiple heads per key to support DAG conflict resolution. Reads
|
||||
```
|
||||
Table Key Value Purpose
|
||||
─────────────────────────────────────────────────────────────────────────────
|
||||
stores UUID (store_id) StoreInfo Known stores this node participates in
|
||||
meta String Vec<u8> Global metadata (node_id, etc.)
|
||||
stores [u8; 16] (UUID) u64 (created_at_ms) Known stores
|
||||
meta "root_store" [u8; 16] (UUID) Root store ID (opened on startup)
|
||||
```
|
||||
|
||||
StoreInfo: `{ type: "manifest" | "data", name, created_at, ... }`
|
||||
- Manifest stores define mesh membership via KV entries (`/nodes/{pubkey}/...`)
|
||||
- **Root Store**: The primary/manifest store for this node, auto-opened on CLI startup
|
||||
- **Stores Table**: Tracks all stores this node participates in
|
||||
- Manifest stores define mesh membership via `/nodes/{pubkey}/...` entries
|
||||
- Data stores hold application data
|
||||
- Node's list of manifest store IDs = meshes it belongs to
|
||||
|
||||
#### In-Memory Structures
|
||||
|
||||
|
||||
+8
-9
@@ -21,16 +21,15 @@
|
||||
- Can replay log to reconstruct KV state
|
||||
- All operations survive restart
|
||||
|
||||
### Multi-KV Refactoring (before M2)
|
||||
### Multi-KV Refactoring (before M2) ✓
|
||||
|
||||
Current code assumes single store. Changes needed:
|
||||
- [ ] DataDir → support `stores/{uuid}/` subdirectories
|
||||
- [ ] SigChain → scoped to (store_id, author_id)
|
||||
- [ ] Store → per-store state.db, not global
|
||||
- [ ] Log paths → `stores/{uuid}/logs/{author}.log`
|
||||
- [ ] Add global meta.db for stores table
|
||||
- [ ] Proto: SignedEntry/messages need store_id (UUID)
|
||||
- [ ] CLI → `create-store`, `list-stores`, `use <store>`
|
||||
- [x] DataDir → `stores/{uuid}/` subdirectories
|
||||
- [x] Store → per-store state.db
|
||||
- [x] Log paths → `stores/{uuid}/logs/{author}.log`
|
||||
- [x] Proto: Entry has store_id (UUID)
|
||||
- [x] CLI → `init`, `create-store`, `list-stores`, `use`
|
||||
- [x] meta.db stores table (MetaStore)
|
||||
- [x] SigChain → validate entry.store_id
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
# Storage Format
|
||||
|
||||
## Directory Layout
|
||||
|
||||
```
|
||||
~/.local/share/lattice/
|
||||
├── identity.key # Ed25519 private key (not replicated)
|
||||
├── meta.db # Global metadata (redb)
|
||||
└── stores/{uuid}/
|
||||
├── logs/{author}.log # Append-only SignedEntry stream
|
||||
└── state.db # Per-store KV state (redb)
|
||||
```
|
||||
|
||||
## meta.db (redb)
|
||||
|
||||
| Table | Key | Value | Purpose |
|
||||
|---------|---------------|--------------------|------------------------------|
|
||||
| stores | UUID (16B) | created_at (u64) | Known stores |
|
||||
| meta | "root_store" | UUID (16B) | Auto-opened on CLI startup |
|
||||
|
||||
## state.db (redb, per store)
|
||||
|
||||
| Table | Key | Value | Purpose |
|
||||
|---------|----------|-------------|------------------------|
|
||||
| kv | String | Vec<u8> | Key-value data |
|
||||
| meta | String | Vec<u8> | last_seq, last_hash |
|
||||
|
||||
## Log Files
|
||||
|
||||
Each `{author}.log` contains length-delimited `LogRecord` messages:
|
||||
|
||||
```protobuf
|
||||
message LogRecord {
|
||||
bytes hash = 1; // BLAKE3 hash of entry_bytes
|
||||
bytes entry_bytes = 2; // Serialized SignedEntry
|
||||
}
|
||||
```
|
||||
|
||||
Hashes are verified on read; corruption causes `LogError::HashMismatch`.
|
||||
Reference in New Issue
Block a user