Documentation
¶
Index ¶
- Constants
- Variables
- func AttrIndexPrefix(shardID uint16, ns uint32, attrID uint32) []byte
- func CalculateShardID(uid uint64, numShards uint16) uint16
- func EdgePrefix(shardID uint16, ns uint32, attrID uint32, fromUID uint64) []byte
- func EncodeDataKey(shardID uint16, ns uint32, attrID uint32, uid uint64) []byte
- func EncodeEdgeKey(shardID uint16, ns uint32, attrID uint32, fromUID, toUID uint64) []byte
- func EncodeIndexKey(shardID uint16, ns uint32, attrID uint32, token []byte, uid uint64) []byte
- func EncodeListDataKey(shardID uint16, ns uint32, attrID uint32, uid uint64, itemHash uint64) []byte
- func EncodeReverseKey(shardID uint16, ns uint32, attrID uint32, toUID, fromUID uint64) []byte
- func EncodeSchemaKey(ns uint32, attrID uint32) []byte
- func IndexPrefix(shardID uint16, ns uint32, attrID uint32, token []byte) []byte
- func PredicatePrefixes(shardID uint16, ns uint32, attrID uint32) [][]byte
- func PredicateToAttrID(attr string) uint32
- func PrefixNext(b []byte) []byte
- func ReversePrefix(shardID uint16, ns uint32, attrID uint32, toUID uint64) []byte
- type DefaultEngine
- func (e *DefaultEngine) AddEdge(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, fromUID, toUID uint64, ...) error
- func (e *DefaultEngine) AddIndex(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, token []byte, ...) error
- func (e *DefaultEngine) AddListData(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, uid uint64, ...) error
- func (e *DefaultEngine) AddReverseEdge(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, toUID, fromUID uint64, ...) error
- func (e *DefaultEngine) DeleteAllData(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, uid uint64) error
- func (e *DefaultEngine) DeleteData(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, uid uint64) error
- func (e *DefaultEngine) DeleteEdge(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, fromUID, toUID uint64) error
- func (e *DefaultEngine) DeleteIndex(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, token []byte, ...) error
- func (e *DefaultEngine) DeleteListData(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, uid uint64, ...) error
- func (e *DefaultEngine) DeleteReverseEdge(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, toUID, fromUID uint64) error
- func (e *DefaultEngine) GetData(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, uid uint64) (byte, []byte, error)
- func (e *DefaultEngine) ScanData(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, uid uint64) ([]byte, [][]byte, error)
- func (e *DefaultEngine) ScanInEdges(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, toUID uint64) (EdgeIterator, error)
- func (e *DefaultEngine) ScanInEdgesFrom(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, toUID, afterUID uint64) (EdgeIterator, error)
- func (e *DefaultEngine) ScanInEdgesKeyOnly(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, toUID, afterUID uint64) (EdgeIterator, error)
- func (e *DefaultEngine) ScanIndex(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, token []byte) ([]uint64, error)
- func (e *DefaultEngine) ScanIndexExtremum(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, tokID byte, isMax bool) ([]byte, uint64, bool, error)
- func (e *DefaultEngine) ScanIndexWithContext(ctx context.Context, txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, ...) ([]uint64, error)
- func (e *DefaultEngine) ScanIndexWithOptions(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, token []byte, ...) ([]uint64, error)
- func (e *DefaultEngine) ScanOutEdges(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, fromUID uint64) (EdgeIterator, error)
- func (e *DefaultEngine) ScanOutEdgesFrom(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, ...) (EdgeIterator, error)
- func (e *DefaultEngine) ScanOutEdgesKeyOnly(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, ...) (EdgeIterator, error)
- func (e *DefaultEngine) SetData(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, uid uint64, ...) error
- type EdgeEntry
- type EdgeIterator
- type Engine
- type ParsedKey
Constants ¶
const ( KeyTypeSchema byte = 0x00 // Schema 元数据 KeyTypeData byte = 0x01 // 标量属性数据 (Scalar Attribute) KeyTypeEdge byte = 0x02 // 正向关系边 (Forward Edge) KeyTypeReverse byte = 0x03 // 反向关系边 (Reverse Edge) KeyTypeIndex byte = 0x04 // 二级索引项 (Secondary Index) )
KeyType 定义物理存储中的键分类(1 字节)
const ( // 固定长度常量 HeaderLen = 7 // ShardID(2B) + Namespace(4B) + KeyType(1B) DataKeyLen = 19 // Header(7B) + AttrID(4B) + SubjectUID(8B) ListDataKeyLen = 27 // Header(7B) + AttrID(4B) + SubjectUID(8B) + ItemHash(8B) EdgeKeyLen = 27 // Header(7B) + AttrID(4B) + SubjectUID(8B) + ObjectUID(8B) )
Variables ¶
var ( ErrInvalidKeyLength = errors.New("flat: invalid key length") ErrInvalidKeyType = errors.New("flat: invalid key type") )
Functions ¶
func AttrIndexPrefix ¶
AttrIndexPrefix 构造指定 Predicate 二级索引的属性前缀 (11 字节) 扫描该前缀可遍历当前属性的所有索引键(按 Token 字典序/数值序升序排列)
func CalculateShardID ¶
CalculateShardID 根据节点 UID 计算分片 ShardID 当 numShards <= 1 时(第一期单桶模式),恒返回 0
func EdgePrefix ¶
EdgePrefix 构造单节点出边扫描的前缀 (19 字节) 扫描该前缀即可顺序遍历 fromUID 的所有关系出边
func EncodeDataKey ¶
EncodeDataKey 编码标量属性键 (19 字节) 格式: ShardID(2B) || Namespace(4B) || 0x01 || AttrID(4B) || SubjectUID(8B)
func EncodeEdgeKey ¶
EncodeEdgeKey 编码正向关系边键 (27 字节) 格式: ShardID(2B) || Namespace(4B) || 0x02 || AttrID(4B) || SubjectUID(8B) || ObjectUID(8B)
func EncodeIndexKey ¶
EncodeIndexKey 编码二级索引键 格式: ShardID(2B) || Namespace(4B) || 0x04 || AttrID(4B) || TokenTerm[TokenType(1B) + Payload(变长)] || 0x00 || SubjectUID(8B)
func EncodeListDataKey ¶
func EncodeListDataKey(shardID uint16, ns uint32, attrID uint32, uid uint64, itemHash uint64) []byte
EncodeListDataKey 编码标量列表属性键 (27 字节) 格式: ShardID(2B) || Namespace(4B) || 0x01 || AttrID(4B) || SubjectUID(8B) || ItemHash(8B)
func EncodeReverseKey ¶
EncodeReverseKey 编码反向关系边键 (27 字节) 格式: ShardID(2B) || Namespace(4B) || 0x03 || AttrID(4B) || ObjectUID(8B) || SubjectUID(8B)
func EncodeSchemaKey ¶
EncodeSchemaKey 编码全局 Schema 元数据键 (11 字节) Schema 默认存放在 ShardID = 0x0000 的公共保留空间 格式: 0x0000(2B) || Namespace(4B) || 0x00 || AttrID(4B)
func IndexPrefix ¶
IndexPrefix 构造二级索引精确匹配扫描的前缀
func PredicatePrefixes ¶
PredicatePrefixes 生成指定 Predicate 在 Flat 存储下的所有前缀 (Data, Edge, Reverse, Index)
func PredicateToAttrID ¶
PredicateToAttrID 将 Predicate 字符串快速且确定性地映射为 32 位 AttrID
Types ¶
type DefaultEngine ¶
type DefaultEngine struct{}
DefaultEngine 默认扁平引擎实现
func (*DefaultEngine) AddListData ¶
func (*DefaultEngine) AddReverseEdge ¶
func (*DefaultEngine) DeleteAllData ¶
func (*DefaultEngine) DeleteData ¶
func (*DefaultEngine) DeleteEdge ¶
func (*DefaultEngine) DeleteIndex ¶
func (*DefaultEngine) DeleteListData ¶
func (*DefaultEngine) DeleteReverseEdge ¶
func (*DefaultEngine) ScanInEdges ¶
func (e *DefaultEngine) ScanInEdges(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, toUID uint64) (EdgeIterator, error)
func (*DefaultEngine) ScanInEdgesFrom ¶
func (e *DefaultEngine) ScanInEdgesFrom(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, toUID, afterUID uint64) (EdgeIterator, error)
func (*DefaultEngine) ScanInEdgesKeyOnly ¶
func (e *DefaultEngine) ScanInEdgesKeyOnly(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, toUID, afterUID uint64) (EdgeIterator, error)
func (*DefaultEngine) ScanIndexExtremum ¶
func (e *DefaultEngine) ScanIndexExtremum(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, tokID byte, isMax bool) ([]byte, uint64, bool, error)
ScanIndexExtremum 快速获取属性索引的极值(最小值或最大值),耗时为 O(1) 的单次 Seek tokID 为索引 tokenizer 的唯一标识字节(如 IdentExact、IdentInt 等);若为 0 则使用裸属性前缀 isMax 为 false 时 Seek 索引最前端获取最小值,为 true 时反向 Seek 获取最大值
func (*DefaultEngine) ScanIndexWithContext ¶
func (*DefaultEngine) ScanIndexWithOptions ¶
func (*DefaultEngine) ScanOutEdges ¶
func (e *DefaultEngine) ScanOutEdges(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, fromUID uint64) (EdgeIterator, error)
func (*DefaultEngine) ScanOutEdgesFrom ¶
func (e *DefaultEngine) ScanOutEdgesFrom(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, fromUID, afterUID uint64) (EdgeIterator, error)
func (*DefaultEngine) ScanOutEdgesKeyOnly ¶
func (e *DefaultEngine) ScanOutEdgesKeyOnly(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, fromUID, afterUID uint64) (EdgeIterator, error)
type EdgeIterator ¶
EdgeIterator 用于流式遍历边的迭代器
type Engine ¶
type Engine interface {
// 标量属性操作
SetData(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, uid uint64, valType byte, data []byte) error
GetData(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, uid uint64) (byte, []byte, error)
DeleteData(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, uid uint64) error
AddListData(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, uid uint64, itemHash uint64, valType byte, data []byte) error
DeleteListData(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, uid uint64, itemHash uint64) error
DeleteAllData(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, uid uint64) error
ScanData(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, uid uint64) ([]byte, [][]byte, error)
// 关系出边操作
AddEdge(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, fromUID, toUID uint64, facets []byte) error
DeleteEdge(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, fromUID, toUID uint64) error
ScanOutEdges(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, fromUID uint64) (EdgeIterator, error)
ScanOutEdgesFrom(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, fromUID, afterUID uint64) (EdgeIterator, error)
ScanOutEdgesKeyOnly(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, fromUID, afterUID uint64) (EdgeIterator, error)
// 反向入边操作
AddReverseEdge(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, toUID, fromUID uint64, facets []byte) error
DeleteReverseEdge(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, toUID, fromUID uint64) error
ScanInEdges(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, toUID uint64) (EdgeIterator, error)
ScanInEdgesFrom(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, toUID, afterUID uint64) (EdgeIterator, error)
ScanInEdgesKeyOnly(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, toUID, afterUID uint64) (EdgeIterator, error)
// 二级索引操作
AddIndex(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, token []byte, uid uint64) error
DeleteIndex(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, token []byte, uid uint64) error
ScanIndex(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, token []byte) ([]uint64, error)
ScanIndexWithOptions(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, token []byte, afterUID uint64, limit int) ([]uint64, error)
ScanIndexWithContext(ctx context.Context, txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, token []byte, afterUID uint64, limit int) ([]uint64, error)
ScanIndexExtremum(txn x.KVTxn, shardID uint16, ns uint32, attrID uint32, tokID byte, isMax bool) ([]byte, uint64, bool, error)
}
Engine 扁平图存储引擎接口