VictoriaMetrics——indexdb源码分析1

2024-07-11  本文已影响0人  七秒钟回忆待续

victoriametrics版本: v1.100.0-cluster

indexdb写入流程

逻辑大致流程

image.png

源码大致流程

image.png

结构体介绍

indexItems

lib/storage/index_db.go
type indexItems struct {
    B     []byte
    Items [][]byte

    start int
}

inmemoryBlock

lib/mergeset/encoding.go
type inmemoryBlock struct {
    // commonPrefix contains common prefix for all the items stored in the inmemoryBlock
    commonPrefix []byte

    // data contains source data for items
    data []byte

    // items contains items stored in inmemoryBlock.
    // Every item contains the prefix specified at commonPrefix.
    items []Item
}

lib/mergeset/encoding.go
type Item struct {
    // Start is start offset for the item in data.
    Start uint32

    // End is end offset for the item in data.
    End uint32
}

索引先写入inmemoryBlock 原始索引数据——没压缩

rawItemsShards

lib/mergeset/table.go
type rawItemsShards struct {
    flushDeadlineMs atomic.Int64

    shardIdx atomic.Uint32

    // shards reduce lock contention when adding rows on multi-CPU systems.
    shards []rawItemsShard

    ibsToFlushLock sync.Mutex
    ibsToFlush     []*inmemoryBlock
}
上一篇 下一篇

猜你喜欢

热点阅读