设计审查: Get API 必须返回 found 状态以支持空值确认约束 #21

Closed
opened 2026-06-12 08:28:49 +08:00 by dailz · 0 comments
Owner

来源: docs/design.md §3.2 WAL Oracle 架构审查

问题描述

设计中多处要求 API 层 Get 必须区分 "key exists with empty value" 与 "key not found":

  1. §3.2 Entry 合法性规则:"Put + Inline 允许 valLen = 0,表示 key 存在且 value 为空 bytes"
  2. §3.2 ErrCommitUnknown 确认约束:"Put(key, emptyValue) 必须依赖 API 区分 key exists with empty value 与 key not found"
  3. 明确要求:"Get 不能只返回 []byte;必须返回 found 或等价状态"

但在 §1.5 功能范围和 §3.4 读路径中没有定义 Get 的具体 API 签名。

需要明确

Get 的 API 签名。推荐方案:

// GetResult 表示 Get 操作的结果
type GetResult struct {
    Value []byte
    Found bool  // true = key 存在(value 可能为空);false = key 不存在
}

// Get 读取 key 的值
func (db *DB) Get(key []byte) (GetResult, error)

或者等价的:

func (db *DB) Get(key []byte) (value []byte, found bool, err error)

影响范围

  • 嵌入式 API 设计
  • ErrCommitUnknown 后的弱状态确认能力
  • 后续 MVCC 事务层的 read path
来源: docs/design.md §3.2 WAL Oracle 架构审查 ## 问题描述 设计中多处要求 API 层 `Get` 必须区分 "key exists with empty value" 与 "key not found": 1. §3.2 Entry 合法性规则:"`Put + Inline` 允许 `valLen = 0`,表示 key 存在且 value 为空 bytes" 2. §3.2 ErrCommitUnknown 确认约束:"`Put(key, emptyValue)` 必须依赖 API 区分 key exists with empty value 与 key not found" 3. 明确要求:"`Get` 不能只返回 `[]byte`;必须返回 `found` 或等价状态" 但在 §1.5 功能范围和 §3.4 读路径中没有定义 `Get` 的具体 API 签名。 ## 需要明确 `Get` 的 API 签名。推荐方案: ```go // GetResult 表示 Get 操作的结果 type GetResult struct { Value []byte Found bool // true = key 存在(value 可能为空);false = key 不存在 } // Get 读取 key 的值 func (db *DB) Get(key []byte) (GetResult, error) ``` 或者等价的: ```go func (db *DB) Get(key []byte) (value []byte, found bool, err error) ``` ## 影响范围 - 嵌入式 API 设计 - ErrCommitUnknown 后的弱状态确认能力 - 后续 MVCC 事务层的 read path
dailz added the design-reviewquestionWAL labels 2026-06-12 08:28:49 +08:00
dailz closed this issue 2026-06-12 09:35:51 +08:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dailz/go-kv#21