Documentation
¶
Index ¶
- Constants
- func GetDyAllocNum(i int) int
- func IndexMerge(indexA, indexB ReadOnlyIndex, indexC WriteOnlyIndex) error
- type DBBuilder
- func (this *DBBuilder) AllocID(outID OutIdType) (InIdType, error)
- func (this *DBBuilder) Init(fPath string, MaxTermCnt int, Maxid InIdType, valueSz uint32, ...) error
- func (this *DBBuilder) Sync() error
- func (this *DBBuilder) WriteData(InID InIdType, d Data) error
- func (this *DBBuilder) WriteIndex(InID InIdType, termlist []TermInDoc) error
- func (this *DBBuilder) WriteValue(InID InIdType, v Value) error
- type DBSearcher
- func (this *DBSearcher) AllocID(outID OutIdType) (InIdType, error)
- func (this *DBSearcher) GetOutID(inId InIdType) (OutIdType, error)
- func (this *DBSearcher) Init(fPath string) error
- func (this *DBSearcher) ReadData(inId InIdType, buf *Data) error
- func (this *DBSearcher) ReadIndex(t TermSign) (*InvList, error)
- func (this *DBSearcher) ReadValue(inId InIdType) (Value, error)
- func (this *DBSearcher) Sync() error
- func (this *DBSearcher) WriteData(InID InIdType, d Data) error
- func (this *DBSearcher) WriteIndex(InID InIdType, termlist []TermInDoc) error
- func (this *DBSearcher) WriteValue(InID InIdType, v Value) error
- type DataBaseReader
- type DataBaseWriter
- type DataManager
- func (this *DataManager) Append(inId InIdType, d Data) error
- func (this *DataManager) Close() error
- func (this *DataManager) Init(path string, maxId InIdType, maxFileSz uint32) error
- func (this *DataManager) Open(path string) error
- func (this *DataManager) ReadData(inId InIdType, buf *Data) error
- func (this *DataManager) Sync() error
- type DataManagerStatus
- type DataReader
- type DataWriter
- type DiskIndex
- func (this *DiskIndex) Close()
- func (this *DiskIndex) GetTermCount() int64
- func (this *DiskIndex) Init(path string, name string, maxFileSz uint32, MaxTermCnt int64) error
- func (this *DiskIndex) NewIterator() IndexIterator
- func (this *DiskIndex) Open(path string, name string) error
- func (this *DiskIndex) ReadIndex(t TermSign) (*InvList, error)
- func (this *DiskIndex) WriteIndex(t TermSign, l *InvList) error
- type DiskIndexIterator
- type DiskIndexStatus
- type IdManager
- func (this *IdManager) AllocID(outId OutIdType) (InIdType, error)
- func (this *IdManager) Close() error
- func (this *IdManager) GetOutID(inId InIdType) (OutIdType, error)
- func (this *IdManager) Init(path string, maxId InIdType) error
- func (this *IdManager) Open(path string) error
- func (this *IdManager) Sync() error
- type IdManagerStatus
- type IndexIterator
- type IndexReader
- type IndexTransform
- type IndexTransformManager
- type IndexWriter
- type InvList
- func (l *InvList) Append(i ...Index)
- func (l InvList) Cap() int
- func (l *InvList) Concat(lst InvList)
- func (l *InvList) IncCap(newCap int)
- func (l InvList) IsFull() bool
- func (l *InvList) KMerge(list [](*InvList), MaxSize ...int)
- func (l InvList) Len() int
- func (l *InvList) Merge(src InvList, MaxSize ...int)
- type InvListMinHeap
- type InvListMinHeapItem
- type MemoryIndex
- type MemoryIndexIterator
- type ReadOnlyIndex
- type StaticIndex
- type ValueManager
- func (this *ValueManager) Init(path string, maxId InIdType, valueSz uint32) error
- func (this *ValueManager) Open(path string) error
- func (this *ValueManager) ReadValue(inId InIdType) (Value, error)
- func (this *ValueManager) Sync() error
- func (this *ValueManager) WriteValue(inId InIdType, v Value) error
- type ValueManagerStatus
- type ValueReader
- type ValueWriter
- type VarIndex
- type VarIndexStatus
- type WriteOnlyIndex
- Bugs
Constants ¶
const ( DiskIndexInit = "DiskIndexInit" DiskIndexReadOnly = "DiskIndexReadOnly" DiskIndexWriteOnly = "DiskIndexWriteOnly" DiskIndexClose = "DiskIndexClose" )
DiskIndex 的两种状态路线.
- 打开后只读 : DiskIndexInit --> DiskIndexReadOnly --> DiskIndexClose.
- 打开后只写 : DiskIndexInit --> DiskIndexWriteOnly --> DiskIndexClose.
const (
// DiskIndex中一级索引块大小
Index1BolckNum = 1024
)
Variables ¶
This section is empty.
Functions ¶
func GetDyAllocNum ¶
func IndexMerge ¶
func IndexMerge(indexA, indexB ReadOnlyIndex, indexC WriteOnlyIndex) error
两路合并索引库A/B,写入到索引库C.外部调用IndexMerge应该是指针传递进来
Types ¶
type DBBuilder ¶
type DBBuilder struct {
// contains filtered or unexported fields
}
静态索引生成器.并发不安全,内部不加锁浪费性能.调用者需要保证不并发使用.
func NewDBBuilder ¶
func NewDBBuilder() *DBBuilder
func (*DBBuilder) Init ¶
func (this *DBBuilder) Init(fPath string, MaxTermCnt int, Maxid InIdType, valueSz uint32, maxIndexFileSz uint32, maxDataFileSz uint32) error
初始化工作. fPath:工作目录. MaxTermCnt:内部正排转倒排一次在内存中写入的最大term数量. Maxid:内部id最大上限. valueSz:value数据固定大小. maxIndexFileSz:index数据分文件每个文件的最大大小. maxDataFileSz:data数据分文件每个文件的最大大小.
func (*DBBuilder) WriteIndex ¶
写入索引,不可并发写入
func (*DBBuilder) WriteValue ¶
写入Value数据,可并发写入
type DBSearcher ¶
type DBSearcher struct {
// contains filtered or unexported fields
}
func NewDBSearcher ¶
func NewDBSearcher() *DBSearcher
func (*DBSearcher) AllocID ¶
func (this *DBSearcher) AllocID(outID OutIdType) (InIdType, error)
根据唯一外部ID,分配内部ID,可并发内部有锁控制按顺序分配
func (*DBSearcher) GetOutID ¶
func (this *DBSearcher) GetOutID(inId InIdType) (OutIdType, error)
func (*DBSearcher) ReadData ¶
func (this *DBSearcher) ReadData(inId InIdType, buf *Data) error
读取Data数据,可并发调用.
func (*DBSearcher) ReadIndex ¶
func (this *DBSearcher) ReadIndex(t TermSign) (*InvList, error)
读取索引,可并发
func (*DBSearcher) ReadValue ¶
func (this *DBSearcher) ReadValue(inId InIdType) (Value, error)
读取Value数据,可并发读.value只能进行读操作,任何写操作都是非法的
func (*DBSearcher) WriteData ¶
func (this *DBSearcher) WriteData(InID InIdType, d Data) error
写入Data数据,可并发调用.
func (*DBSearcher) WriteIndex ¶
func (this *DBSearcher) WriteIndex(InID InIdType, termlist []TermInDoc) error
写入索引,不可并发写入.
func (*DBSearcher) WriteValue ¶
func (this *DBSearcher) WriteValue(InID InIdType, v Value) error
写入Value数据,可并发写入.
type DataBaseReader ¶
type DataBaseReader interface { // 查询外部ID GetOutID(inId InIdType) (OutIdType, error) // 支持索引写入 IndexReader // 支持Value读取 ValueReader // 支持Data读取 DataReader }
读索引接口
type DataBaseWriter ¶
type DataBaseWriter interface { // 根据唯一外部ID,分配内部ID AllocID(outID OutIdType) (InIdType, error) // 支持索引写入 IndexWriter // 支持Value写入 ValueWriter // 支持Data写入 DataWriter // 进行一次同步 Sync() error }
可写入数据库接口
type DataManager ¶
type DataManager struct { JsonStatusFile // contains filtered or unexported fields }
data数据管理,每个结果的data可以是变长的,数据结构需要设计为二级索引. 并发安全性问题:读操作可并发,写操作不可并发. 全部data数据合起来会非常大,需要多文件存储 一级索引(定长): [fileno,offset,length][fileno,offset,length] ... [fileno,offset,length] 二级索引(变长): [data][data][data] ... [data] 分隔存储到多个文件
func NewDataManager ¶
func NewDataManager() *DataManager
func (*DataManager) Append ¶
func (this *DataManager) Append(inId InIdType, d Data) error
追加数据文件.不可并发写入,使用者应该自己做好并发控制. 同一个InId多次写入会进行覆盖操作,只有最后一次写操作数据有效,而且之前的写入的 数据会变成垃圾数据占用磁盘空间,无法删除.
func (*DataManager) Close ¶
func (this *DataManager) Close() error
func (*DataManager) Init ¶
func (this *DataManager) Init(path string, maxId InIdType, maxFileSz uint32) error
全新初始化数据文件
func (*DataManager) ReadData ¶
func (this *DataManager) ReadData(inId InIdType, buf *Data) error
读取Data数据,可以并发.
func (*DataManager) Sync ¶
func (this *DataManager) Sync() error
type DataManagerStatus ¶
type DataManagerStatus struct {
// 最大id
MaxInId InIdType
}
data磁盘数据文件自描述所需的字段
type DataReader ¶
type DataReader interface { // 读取Data ReadData(inId InIdType, buf *Data) error }
type DataWriter ¶
type DataWriter interface { // 写入Data WriteData(InID InIdType, d Data) error }
type DiskIndex ¶
type DiskIndex struct { JsonStatusFile // contains filtered or unexported fields }
磁盘索引.只支持一次性写入后只读操作.
func (*DiskIndex) Init ¶
创建全新的磁盘索引,初始化后只允许进行索引写入. maxFileSz 索引大文件单个文件的最大大小. MaxTermCnt 是预期要写入的term的总数量.
func (*DiskIndex) NewIterator ¶
func (this *DiskIndex) NewIterator() IndexIterator
创建新的迭代器.在返回的迭代器生命有效期间,DiskIndex必须有效
func (*DiskIndex) WriteIndex ¶
写入索引,内部加锁保证顺序写入. 同一个term多次写入,会进行覆盖,只有最后一次写有效,其它变成垃圾数据. 索引写入要求按term的升序写入,乱序写入索引结构破坏.
type DiskIndexIterator ¶
type DiskIndexIterator struct {
// contains filtered or unexported fields
}
磁盘索引一级索引遍历器
type DiskIndexStatus ¶
磁盘索引的一些附加信息.
type IdManager ¶
type IdManager struct { JsonStatusFile // contains filtered or unexported fields }
在goose设计解决百万级别的doc数. 1千万个文档id,每个id使用4个字节存储 1000*10000*4/1024/1024 = 38MB . 索引量达到一千万,所有id的存储用一个文件就可以存储.
func NewIdManager ¶
func NewIdManager() *IdManager
type IdManagerStatus ¶
type IdManagerStatus struct { // 当前未分配id CurId InIdType // 最大id MaxInId InIdType }
id磁盘数据文件自描述所需的字段
type IndexReader ¶
type IndexTransform ¶
type IndexTransform struct {
// contains filtered or unexported fields
}
IndexTransform 模块完成将正排转成倒排拉链的工作.
- 不支持并发
- 占用大量内存
func (*IndexTransform) AddOneDoc ¶
func (this *IndexTransform) AddOneDoc(id InIdType, termList []TermInDoc) error
增加一个doc. id是doc的内部id. termList是doc中切词得到的全部term.
func (*IndexTransform) Dump ¶
func (this *IndexTransform) Dump(db WriteOnlyIndex) error
将已经构建好的索引全部写入索引库中.
func (*IndexTransform) GetInvListSize ¶
func (this *IndexTransform) GetInvListSize() int
拉链数量,也就是总共的term数量
type IndexTransformManager ¶
type IndexTransformManager struct {
// contains filtered or unexported fields
}
IndexTransform的管理器.当IndexTransform无法再写入的时候,进行写入到磁盘操作. 当全部工作完成后,进行把已写入磁盘的索引合并成一个大索引.
func NewIndexTransformManager ¶
func NewIndexTransformManager() *IndexTransformManager
IndexTransformManager构造函数. 如果内存中的索引数超过了,就会先把全部索引暂时写入磁盘,等最终再合并全部索引.
func (*IndexTransformManager) Dump ¶
func (this *IndexTransformManager) Dump(dstdb WriteOnlyIndex) error
结束写入索引,把已暂存磁盘的全部索引以及在内存中的索引进行合并成大的索引
func (*IndexTransformManager) GetTermCount ¶
func (this *IndexTransformManager) GetTermCount() int64
func (*IndexTransformManager) Init ¶
func (this *IndexTransformManager) Init(fPath string, MaxTermCnt int) error
MaxTermCnt指的是在内存中最多的索引数(非拉链数). fPath是工作目录
func (*IndexTransformManager) WriteIndex ¶
func (this *IndexTransformManager) WriteIndex(InID InIdType, termlist []TermInDoc) error
写入索引.不支持并发写入,调用者需要自己控制.
type IndexWriter ¶
type IndexWriter interface { // 写入索引 WriteIndex(InID InIdType, termlist []TermInDoc) error }
type InvList ¶
type InvList []Index
倒排拉链.实现保证轻量级,可任意拷贝保证不损耗性能
func NewInvListPointer ¶
type InvListMinHeap ¶
type InvListMinHeap []InvListMinHeapItem
type InvListMinHeapItem ¶
type InvListMinHeapItem struct {
// contains filtered or unexported fields
}
InvList最小堆元素
type MemoryIndex ¶
type MemoryIndex struct {
// contains filtered or unexported fields
}
内存索引.并发模式支持多读一写.
func (*MemoryIndex) Clear ¶
func (this *MemoryIndex) Clear()
func (*MemoryIndex) NewIterator ¶
func (this *MemoryIndex) NewIterator() IndexIterator
需要注意: 创建新的迭代器.在返回的迭代器生命有效期间,MemoryIndex必须有效. 迭代器能够访问到的term列表是执行这次的快照. NewIterator返回后再写入MemoryIndex的拉链MemoryIndexIterator不一定能够访问到. 因此在MemoryIndexIterator遍历整个内存库的时候,应该暂停写入,但是可以读取. 暂停写入需要外部调用者自行控制.
func (*MemoryIndex) ReadIndex ¶
func (this *MemoryIndex) ReadIndex(t TermSign) (*InvList, error)
读取索引,每次查询在内部分配一块内存返回
func (*MemoryIndex) WriteIndex ¶
func (this *MemoryIndex) WriteIndex(t TermSign, l *InvList) error
写入索引,内部加锁进行写入. 同一个term多次写入,会进行append操作.
type MemoryIndexIterator ¶
type MemoryIndexIterator struct {
// contains filtered or unexported fields
}
内存索引遍历器
func (*MemoryIndexIterator) Next ¶
func (this *MemoryIndexIterator) Next() TermSign
获取下一个term,遍历结束返回0
type ReadOnlyIndex ¶
type ReadOnlyIndex interface { // 创建遍历器 NewIterator() IndexIterator // 索引读取接口 ReadIndex(t TermSign) (*InvList, error) }
可合并只读索引库
type StaticIndex ¶
type StaticIndex struct {
// contains filtered or unexported fields
}
StaticIndex是静态索引的读取接口.只允许打开磁盘已存在的索引后进行读操作.
func (*StaticIndex) ReadIndex ¶
func (this *StaticIndex) ReadIndex(t TermSign) (*InvList, error)
读取索引
type ValueManager ¶
type ValueManager struct { JsonStatusFile // contains filtered or unexported fields }
基于mmap的value管理. value设计为定长,在goose中value的长度应该在100字节以内比较好. 假设配置制定value定长32字节,1千万个文档占用mmap空间. 32*1000*10000 /1024/1024 = 306MB.
func NewValueManager ¶
func NewValueManager() *ValueManager
func (*ValueManager) Init ¶
func (this *ValueManager) Init(path string, maxId InIdType, valueSz uint32) error
func (*ValueManager) Open ¶
func (this *ValueManager) Open(path string) error
func (*ValueManager) ReadValue ¶
func (this *ValueManager) ReadValue(inId InIdType) (Value, error)
读取value的引用,value只能进行读操作,任何写操作都是非法的
func (*ValueManager) Sync ¶
func (this *ValueManager) Sync() error
func (*ValueManager) WriteValue ¶
func (this *ValueManager) WriteValue(inId InIdType, v Value) error
写入Value.可并发写
type ValueManagerStatus ¶
type ValueManagerStatus struct { // 最大id MaxInId InIdType // 一个value的大小,单位(byte) ValueSize uint32 }
data磁盘数据文件自描述所需的字段
type ValueReader ¶
type ValueReader interface { // 读取Value ReadValue(InID InIdType) (Value, error) }
type ValueWriter ¶
type ValueWriter interface { // 写入Value WriteValue(InID InIdType, v Value) error }
type VarIndex ¶
type VarIndex struct { JsonStatusFile // contains filtered or unexported fields }
VarIndex利用内存索引和磁盘索引组成. 支持检索的时候进行插入索引操作.
func (*VarIndex) WriteIndex ¶
往动态库写入索引
type VarIndexStatus ¶
type VarIndexStatus struct { // 当前使用哪个磁盘索引 CurrDisk int }
type WriteOnlyIndex ¶
可合并只写索引库
Notes ¶
Bugs ¶
把TermSign强制转成int64了
每次写都更新状态文件,是否有必要,会不会影响性能
实际测试发现占用内存严重大于该估算,需要进一步测试验证