国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

? ??? ?? Golang ???? LSM-?? ???? ?? ??

???? LSM-?? ???? ?? ??

Jan 03, 2025 am 07:37 AM

???

? ???? LSM-Tree(?? ?? ?? ??)? ?? ??? ??? ???? ??? ?????. ???? LSM-Tree? ???? ???? ???? ???? ??? ??? ? ?? ???.

LSM-??? ??????

?? ??

LSM-??(Log-Structured Merge-Tree)? ???? ?? ??? ???? ??? ?????. Cassandra, RocksDB, LevelDB ?? ?????? ? ???? ????? ?? ?????.

LSM-Tree? ?? ????? ?? ??? ? ??? ??(????? ?? ?? ?? AVL ??? ?? ??? ??? ??)? ??? ???? ????. ??? ??? ??? SSTable? ?? ???? ????? ???? ????? ?? I/O? ??????.

?? ??

Building an LSM-Tree Storage Engine from Scratch

LSM-Tree? ? ?? ?? ?? ??? ????.

  • ???? ????
    • ???? ?? ??? Memtable???.
    • ?? ?? ??(?: ??, ??)? ?? Memtable? ????, Memtable? ??? ??? ??? ??? ??(?: ?????? ??? ??)? ?????.
    • Memtable? ?? ?? ???? ???? SSTable(????? ???)? ???? ??????.
    • ? Memtable?? ??? ?? ??? ?????.
  • ??? ????
    • ??? ?????? WAL ? SSTable ??? ?????.
    • WAL(Write-Ahead Log)? ?????? ?? ? ?? ??(Memtable? ?????? ?? ???? ???? ??)? ???? ??? ?????. Memtable? ?? ?? ??? WAL? ?????. ??????? ?? ???? Memtable? ?? ?? ??? ???? ?? WAL? ??? ??? ? ????.
    • SSTable(Sorted String Table)? ??? ??? ??? ?-? ?? ???? ??? ?? ?????.
    • Memtable? ?? ???? ???? ? SSTable? ???? ?? ???? ?????. Memtable? ??? ? ??? ??? ??? ??? ????? SSTable? ??? ? ?? ??? ???? ????.
    • ???? SSTable? ?? ???? ?????. ?? ???? SSTable? ?? 0? ?????. ?? ?? ???? L0? SSTable? ?? 1 ? ?? ??
    • ?? ?????.
    • ?? ??? ???? ???? SSTable ?? ????? ??????. ???? ?? ?? ??? SSTable? ? ?? ???? ???? ? ?? ??? ??? ??? ?????. ??? ?? ???? ???? ?? ???? ?????.

????? SSTable? ???? ??? ??? ??? ?-? ?(??? ??) ??? ?????. ?? ??? ??, ????? ?? ? ?? ?? ??? ???? ????. ??? ?? ??? ?? ???? ????? ??? ????.

??? ??

??? ???? ??? ?-? ?? ????? ?? ?? ?????? ??? ?????. ????? ??? ?? ???? ?? ???? ?? ?-? ?? ?????.

???? ???? ?? Memtable?? ????, ??? ?-? ?? ??? ? ?? ??? ??? ?????. ??? ?? ??? WAL? ???? ???? ???? ?????? ?? ? ??? ??? ?????.

Memtable?? ??? ???(?? ?? ??)? ????. Memtable? ? ???? ???? ?? ?? ??? ???? ??? SSTable?? ??? ? ????? ?? 0?? ?????.

Memtable? SSTable? ????? ?? WAL ??? ???? ??? ? ????. ?? ?? ??? ? Memtable(? ? WAL)?? ?????.

??? ??

LSM-Tree??? ???? ?? ???? ????. ?? ??? ??(?? ??? ??)?? ????? ???? ?????. ?-? ?? ???? "?? ??"? ??? ? ??? ???? ?? ?-? ?? ?????? ?????. ?? ??? ?? ???? ?????.

? ?? ?? ?? ??? LSM-Tree? ?? ?? ??? ?????? ?? I/O? ???? ???? ??? ??? ?????.

??? ??

??? ?? ??? Memtable?? ???? ??? ?????. ?-? ?? ???? ?????? ?????. ?? ??? ?? ?-? ?? ???? ??? ???? ?????? ???? ? ??? ?????. Memtable?? ?? ?? ? ?? ?? ??? ?? 0?? ?? N

?? SSTable? ?????.

??? ???? ?? SSTable ?? ??? ??? ? ?? ??? ??? I/O? ??? ? ???? LSM-Tree? ????? ?? ???? ??????? ??? ?? ????? ? ?????.

?? ??? ?? ???? ??? ? ??? Bloom ??? ???? ????. Bloom ??? ?? SSTable? ?-? ?? ????? ???? ???? ???? ??? I/O? ?? ? ????. ?? SSTable? ??? ??? ?? ?? ??? ?? ???? ?? ????? ???? ? ?? ??? ??? ? ????.

??? ??

????? LevelDB? RocksDB?? ???? ?? ?? ??? ?????.

? ?? ???? ??? ?? ?? ?? ????, ? ??? ?? SSTable? ? ???? ? ? SSTable? ????? ?????.

?? ????? SSTable? ??? ??? ??? ??? ?????. ?? ?? ???? SSTable? ?? ??(?? 0?? ?? N??)? ?????.

?? 0?? SSTable? Memtable?? ?? ?????? ???? ? ??? ?? ? ????. ?, ?? 1~N??? ?? ?? ?? SSTable? ? ??? ???? ???, ?? ?? ??? SSTable ??? ? ?? ??? ?????.

???? (??? ????? ???) ??? ?? ????. ?? 0??? ? ??? ? ?? SSTable? ? ??? ??? ??, ?? 1 ? ?? 2??? ? ?? ?? SSTable? ?? ??? ? ??? ????. . ??? ?? ?? ??(?: ?? 0? ?? 1, ?? 1? ?? 2) ?? SSTable?? ???? ? ??? ?? ? ????.

Building an LSM-Tree Storage Engine from Scratch

?? Leveled Compaction ??? ??? ??? ?? ??? ????? ???????.

?? 0? ??? ????? ?? ?? ??? ? ???? ??????.

  • 0?? ~ 1?? ?? 0? SSTable ???? ?? ??? ?? ????? ??? ?? 0?? SSTable? ?? ? ??? ??? ?? 0? ?? ?? SSTable? ???? ?????. ????, ? ??? ??? ?? 1? ?? SSTable? ?????. ??? SSTable? ???? ??? ??? SSTable? ??? ? ?? 1? ?????. ?? ????? ??? ?? SSTable? ?? ?????.
  • ?? N ~ ?? N 1(N>0) ?? 1??? ??? ?? ?? SSTable? ? ??? ??? ????. ?? ?? ?? N?? SSTable? ????, ? ??? ??? ?? N 1? ?? SSTable? ?????. ??? SSTable? ?? ??? ??? SSTable? ?? ? ???? ?? N 1? ???? ?? SSTable? ?????.

?? 0?? ?? 1 ??? ?? N?? ?? N 1(N>0) ??? ?? ???? ?? ??(?? 0 ?? ?? N).

?? SSTable ?? ? ?? ????? ??? ???? ????. ?? ??? ? ?? ?? ?? ?????. ?? ?? "?? ??" ??? ??? ?? ?????. ????? k-way ?? ????? ???? ? ????? ?????.

Building an LSM-Tree Storage Engine from Scratch

?? ????? ?? ?? ??? ?? ??? ???? ????? ?? ???? ?? ?????. ?? ?? ?? ?? ?? ??? ???? ???.

?? ?? LevelDB?? ?? ?? ?? N 1? ?? ? SSTable? ??? ? ? SSTable? ?? N 2? 10? ??? SSTable? ??? ????? ?? SSTable ???? ?????. ?? ?? ??? ??? ??? ??? ?????.

??

?? LSM-Tree ??? ???? ?? LSM-Tree? ?? ???? ??? ??? ?? ? ?? ????? ?????? ????. ???? LSM-Tree? ???? ???? ??? ???? ???????. ????? ????? ???????. ?? ??? https://github.com/B1NARY-GR0UP/originium? ?????.

LSM-Tree? ??? ??? ?? ?? ????? ??? ??? ???????.

  • ?? ??
  • ?
  • ????
  • SS???
  • K-Way ??
  • ????
  • ?? ??

???? ??

??? ??? ???? ???? LSM-Tree? ?? ??? ? ??? ??? ??? ???? ??? ??????. ???? ??? ??? ??? ?? ??? ?? ???? ??? ????.

Data Structure Insert Delete Search Traverse
Skip List O(log?n) O(log?n) O(log?n) O(n)
AVL Tree O(log?n) O(log?n) O(log?n) O(n)
Red-Black Tree O(log?n) O(log?n) O(log?n) O(n)

??? ???? ??? ??? ??? ? ?????. ?? ? ?? ??? ? ????(KISS ??) ?? ?? ?? ??? ??? ??? ???? ??? ? ???? ???? ? ?? ??? ? ??? ????.

?? ??

?? ??? ?? ??? https://github.com/B1NARY-GR0UP/originium/blob/main/pkg/skiplist/skiplist.go?? ??? ? ????.

?? ??? ?? ?? ??? ? ?? ??? ?? ??? ???? ?????. ??? ??? ??? ?? ??? ???? ?? ??? ?? ?????.

?? ???? ???? ??? ?? ??? ??? ?? ?????.

type SkipList struct {
    maxLevel int
    p        float64
    level    int
    rand     *rand.Rand
    size     int
    head     *Element
}
  • maxLevel: ???? ??? ?? ?? ?(?? ?? ???? 1? ??? ??).
  • ??: ???? ??? ?? ?? ?.
  • p: ??? ? ?? ??? ??? ?????. ?? ?? p = 0.5? ?? ?? ??? 10?? ??? ?? ?? ??? ?? ??? ???? ? 5?? ??? ????.
  • rand: p? ???? ? ???? ?? ???
  • size: Skip List? ??? ?-? ?? ??, Memtable? ?? ???? ????? ???? ? ?????.
  • head: ? ??? ? ?? ??? ?? ??? ???? ?? ?????.

Skip List? ???? ??? ??? ??? ?? ?????.

type Element struct {
    types.Entry
    next []*Element
}

// https://github.com/B1NARY-GR0UP/originium/blob/main/pkg/types/entry.go
type Entry struct {
    Key       string
    Value     []byte
    Tombstone bool  
}
  • types.Entry? ?, ? ? ??? ?? ?? ???? ???? ???? ??? ?-? ?? ?????.

  • ??: ? ??? ?? ??? ?? ???? ?????.

? ??? ????? ?? ? ???? ?? ?? ???????.

Level 3:       3 ----------- 9 ----------- 21 --------- 26
Level 2:       3 ----- 6 ---- 9 ------ 19 -- 21 ---- 25 -- 26
Level 1:       3 -- 6 -- 7 -- 9 -- 12 -- 19 -- 21 -- 25 -- 26

next of head [ ->3, ->3, ->3 ]
next of Element 3 [ ->6, ->6, ->9 ]
next of Element 6 [ ->7, ->9 ]

? 3?? ???? ???? ?? ??? ?? ???? ? ??? ? ?? ??? ?????. ?? 3? 6? ? ??? ?? ??? ?????.

?? ?? ?? 2?? ?? 19? ?? ??? ???? e19.next[2-1]? ?????.

??

func (s *SkipList) Set(entry types.Entry)

LSM-Tree? ??? ???? ?? ?? ??? ????? ???? ?? ????? ?? ???? ???? ????. ??? ????? ??? Tombstone? true? ???? ???. ??? Set ???? ??? ?-? ? ??, ?? ? ???? ? ?? ??? ?????.

Set ???? ??? ???????. ?? ?? ??? ? ??? ??? ???? ??? ??? ?? ??? ??? ???? ????? ?????.

type SkipList struct {
    maxLevel int
    p        float64
    level    int
    rand     *rand.Rand
    size     int
    head     *Element
}

? ??? ??? curr? ??? ?? ???? ??? ??? ?? ??? ??? ?????. ??? curr? ?? ??? ??? ????? ?? ???? ????? ?? ???. ???? ??? ?? ??? ????. ?? ??? ?????? ?????.

type Element struct {
    types.Entry
    next []*Element
}

// https://github.com/B1NARY-GR0UP/originium/blob/main/pkg/types/entry.go
type Entry struct {
    Key       string
    Value     []byte
    Tombstone bool  
}

??? ?? ? ??? ? ??? ?????. RandomLevel? ???? ? ??? ??? ??? ?????. ???? ??? ?? ?? ?? ???? ?? ???? ????? ?? ??? ???? s.level? ? ?? ?? ???????.

Level 3:       3 ----------- 9 ----------- 21 --------- 26
Level 2:       3 ----- 6 ---- 9 ------ 19 -- 21 ---- 25 -- 26
Level 1:       3 -- 6 -- 7 -- 9 -- 12 -- 19 -- 21 -- 25 -- 26

next of head [ ->3, ->3, ->3 ]
next of Element 3 [ ->6, ->6, ->9 ]
next of Element 6 [ ->7, ->9 ]

???? ??? ??? ???? ? ??? ?? ???? ?????? ??? ?????.

func (s *SkipList) Set(entry types.Entry)

??

?? ??? ?? ??? ???? ???? ?? ?? ??? ??? ? ????. ???? ??? for ??? ??? ?? ?? ??? ?????. ????? ?? ??? ?? ??????? ???? ?????.

curr := s.head
update := make([]*Element, s.maxLevel)

for i := s.maxLevel - 1; i >= 0; i-- {
    for curr.next[i] != nil && curr.next[i].Key < entry.Key {
        curr = curr.next[i]
    }
    update[i] = curr
}

??

??? ?? ???? ??? ?? ? ??? ?? ?? ???? ???? ???? ??? ??? ?? ?????.

// update entry
if curr.next[0] != nil && curr.next[0].Key == entry.Key {
    s.size += len(entry.Value) - len(curr.next[0].Value)

    // update value and tombstone
    curr.next[0].Value = entry.Value
    curr.next[0].Tombstone = entry.Tombstone
    return
}

?

WAL? ?? ??? https://github.com/B1NARY-GR0UP/originium/blob/main/wal/wal.go?? ??? ? ????.

?? ????? WAL(Write-Ahead Logging)? ??? ?????? ??? ?? Memtable? ??? ??? ???? ????. ??? WAL? Memtable? ?? ??? ???? ??????? ?? ??? ? WAL ???? Memtable? ???? ???.

?? ??

WAL? ?? ??? ??? ????. ??? fd? WAL ??? ?? ???? ?????.

// add entry
level := s.randomLevel()

if level > s.level {
    for i := s.level; i < level; i++ {
        update[i] = s.head
    }
    s.level = level
}

??

Memtable? ??? ???? ??? ????? ? ??(??, ??)? WAL? ???? ???? ??? ?????. Write ???? ??? ??? ????.

e := &Element{
    Entry: types.Entry{
        Key:       entry.Key,
        Value:     entry.Value,
        Tombstone: entry.Tombstone,
    },
    next: make([]*Element, level),
}

for i := range level {
    e.next[i] = update[i].next[i]
    update[i].next[i] = e
}
s.size += len(entry.Key) + len(entry.Value) + int(unsafe.Sizeof(entry.Tombstone)) + len(e.next)*int(unsafe.Sizeof((*Element)(nil)))

??? ??? ??? ? ? WAL ?? ??? ????? ???. ??? ???? ??? ?? ??????. ?? Entry? ???? ?? ???? ???? ??? ???? ????? ??? ???? ???? ????? WAL ??? ???.

?? ??? ??? ????.

func (s *SkipList) Get(key types.Key) (types.Entry, bool) {
    curr := s.head

    for i := s.maxLevel - 1; i >= 0; i-- {
        for curr.next[i] != nil && curr.next[i].Key < key {
            curr = curr.next[i]
        }
    }

    curr = curr.next[0]

    if curr != nil && curr.Key == key {
        return types.Entry{
            Key:       curr.Key,
            Value:     curr.Value,
            Tombstone: curr.Tombstone,
        }, true
    }
    return types.Entry{}, false
}

??

WAL ?? ??? ?? ???? ???? ??? ?? ?? ?? 8???(int64)? ?? ???? ??? ?? ?? ? ??? ???? ???? ?? ???????. ??? ?????.

?? ??? ??? ????.

type SkipList struct {
    maxLevel int
    p        float64
    level    int
    rand     *rand.Rand
    size     int
    head     *Element
}

????

Memtable? ?? ??? https://github.com/B1NARY-GR0UP/originium/blob/main/memtable.go?? ??? ? ????.

Memtable? ????? ??? ???? ??? ???? ?? WAL? ???? ??? ?????. ??????? ??? ? WAL?? ???? ??? ?? ????.

?? ??

Memtable? ?? ??? Skiplist? wal? ? ?? ?? ?? ??? ???? ??? ????.

type Element struct {
    types.Entry
    next []*Element
}

// https://github.com/B1NARY-GR0UP/originium/blob/main/pkg/types/entry.go
type Entry struct {
    Key       string
    Value     []byte
    Tombstone bool  
}

??

Set ??? ??? ? ???? ??? WAL? ??? ?????? ???.

Level 3:       3 ----------- 9 ----------- 21 --------- 26
Level 2:       3 ----- 6 ---- 9 ------ 19 -- 21 ---- 25 -- 26
Level 1:       3 -- 6 -- 7 -- 9 -- 12 -- 19 -- 21 -- 25 -- 26

next of head [ ->3, ->3, ->3 ]
next of Element 3 [ ->6, ->6, ->9 ]
next of Element 6 [ ->7, ->9 ]

??

?? ????? ???? ??? Get ?? ??? ???? ???.

func (s *SkipList) Set(entry types.Entry)

?? ??

WAL ???? Memtable? ????? ?? WAL ??? ?? ?? WAL ??? Entry ???? Memtable? ????? ???? ????? ??? WAL ??? ???? ???.

WAL ?? ?? ??:

curr := s.head
update := make([]*Element, s.maxLevel)

for i := s.maxLevel - 1; i >= 0; i-- {
    for curr.next[i] != nil && curr.next[i].Key < entry.Key {
        curr = curr.next[i]
    }
    update[i] = curr
}

WAL? ?? Memtable? ?????.

// update entry
if curr.next[0] != nil && curr.next[0].Key == entry.Key {
    s.size += len(entry.Value) - len(curr.next[0].Value)

    // update value and tombstone
    curr.next[0].Value = entry.Value
    curr.next[0].Tombstone = entry.Tombstone
    return
}

SS???

LevelDB SSTable

?? ????? "SSTable(Sorted String Table)? ??? ???? ?-? ?? ???? ??? ?? ??"???? ??????. ???? SSTable? ??? ?? ? ? ??? ???????.

??DB?? SSTable? ??? ??? ?? ?? ???? ?????. ???? ??? ????.

Building an LSM-Tree Storage Engine from Scratch

  • ??? ??: ??? ??? ?-? ?? ???? ?????.
  • ?? ??: ??? ??? ? ?? ??? ?????. ?? ??? Bloom ??? ?? ???? ????, ?? ??? ??? ??? ?? ?? ??? ?????.
  • MetaIndex Block: ?? ??? ?? ??? ??? ?????.
  • ??? ??: ??? ??? ?? ??? ??? ?????.
  • ???: ??? ???? ??? MetaIndex Block? Index Block? ??? ??? ????? ?????.

??? ??? ????? BlockHandle??? ??? ???, ?? ??? ?? ? ???? ???? ???? ? ?? ??? ?????.

??? SSTable

SSTable ???? LevelDB SSTable ??? ???????. ???? ??? ????.

Building an LSM-Tree Storage Engine from Scratch

  • ??? ??: ??? ??? ?-? ?? ???? ?????.
  • ?? ??: SSTable? ?? ?? ?????? ?????.
  • ??? ??: ??? ??? ?? ??? ??? ?????.
  • ???: ??? ???? ?? ??? ??? ??? ??? ??? ?????.

SSTable? ?? ??? https://github.com/B1NARY-GR0UP/originium/tree/main/sstable?? ??? ? ????.

??? ??

??? ??? ??? ??? ?? ????, ???? ??? ?????.

type SkipList struct {
    maxLevel int
    p        float64
    level    int
    rand     *rand.Rand
    size     int
    head     *Element
}

??? ??? ??? ?? ? ?? ?? ??? ??????.

  • ???: ??? ??? ???? ???? ??????.
type Element struct {
    types.Entry
    next []*Element
}

// https://github.com/B1NARY-GR0UP/originium/blob/main/pkg/types/entry.go
type Entry struct {
    Key       string
    Value     []byte
    Tombstone bool  
}

??? ??? ???? ?-? ???? ??????. ???? ?? ???? ??, ???? ??, ??? ??, ?? ??, ?, "tombstone" ??? ????? ?????.

Level 3:       3 ----------- 9 ----------- 21 --------- 26
Level 2:       3 ----- 6 ---- 9 ------ 19 -- 21 ---- 25 -- 26
Level 1:       3 -- 6 -- 7 -- 9 -- 12 -- 19 -- 21 -- 25 -- 26

next of head [ ->3, ->3, ->3 ]
next of Element 3 [ ->6, ->6, ->9 ]
next of Element 6 [ ->7, ->9 ]

????? s2? ???? ???? ?????.

S2? Snappy ?? ????? ??? ?????.

func (s *SkipList) Set(entry types.Entry)
  • ???: ???? ???? ??? ???? ??????.
curr := s.head
update := make([]*Element, s.maxLevel)

for i := s.maxLevel - 1; i >= 0; i-- {
    for curr.next[i] != nil && curr.next[i].Key < entry.Key {
        curr = curr.next[i]
    }
    update[i] = curr
}

??? ??? ????? ??? ??? ?????. ?? ?-? ?? ???? ???? ???? ??????.

// update entry
if curr.next[0] != nil && curr.next[0].Key == entry.Key {
    s.size += len(entry.Value) - len(curr.next[0].Value)

    // update value and tombstone
    curr.next[0].Value = entry.Value
    curr.next[0].Tombstone = entry.Tombstone
    return
}
  • ??: ?? ??? ???? ?-? ?? ????.
// add entry
level := s.randomLevel()

if level > s.level {
    for i := s.level; i < level; i++ {
        update[i] = s.head
    }
    s.level = level
}

??? ??

??? ??? ??? ??? ?? ?????. ?? ??? ??? BlockHandle? ?? ? ??? ??? ? ?? ? ??? ?? ?????.

e := &Element{
    Entry: types.Entry{
        Key:       entry.Key,
        Value:     entry.Value,
        Tombstone: entry.Tombstone,
    },
    next: make([]*Element, level),
}

for i := range level {
    e.next[i] = update[i].next[i]
    update[i].next[i] = e
}
s.size += len(entry.Key) + len(entry.Value) + int(unsafe.Sizeof(entry.Tombstone)) + len(e.next)*int(unsafe.Sizeof((*Element)(nil)))

????? ??? ??? ???, ???, ??? ? ?? ?? ??? ?????. Encode ? Decode ???? ?? ????? ????? ????? Search ???

? ??? ?????.

??? ??? ?? ??? ?? ??? ??? ??? ??? ?-? ??? ??? ?? ?-? ?? ??? ???????. ??, Index Block? Search ???? ?? SSTable ??? ??? ?? ???? Data Block? ?? ? ?????.

func (s *SkipList) Get(key types.Key) (types.Entry, bool) {
    curr := s.head

    for i := s.maxLevel - 1; i >= 0; i-- {
        for curr.next[i] != nil && curr.next[i].Key < key {
            curr = curr.next[i]
        }
    }

    curr = curr.next[0]

    if curr != nil && curr.Key == key {
        return types.Entry{
            Key:       curr.Key,
            Value:     curr.Value,
            Tombstone: curr.Tombstone,
        }, true
    }
    return types.Entry{}, false
}

?? ?? ? ???

func (s *SkipList) All() []types.Entry {
    var all []types.Entry

    for curr := s.head.next[0]; curr != nil; curr = curr.next[0] {
        all = append(all, types.Entry{
            Key:       curr.Key,
            Value:     curr.Value,
            Tombstone: curr.Tombstone,
        })
    }

    return all
}

? ? ??? ??? ?? ???? ? ? Encode ? Decode ???? ?????.

??

SSTable? ?? ??? ??? ? SSTable? ????? ?-? ?? ???? ? ??? ???? ???? ???. ????? ???? ???? ???? SSTable? ?????.

type SkipList struct {
    maxLevel int
    p        float64
    level    int
    rand     *rand.Rand
    size     int
    head     *Element
}

K-?? ??

K-Way Merge? ?? ??? https://github.com/B1NARY-GR0UP/originium/tree/main/pkg/kway?? ??? ? ????.

?? ????? ?? SSTable? ???? ???? ??? ?????? ?? ?????. ? ????? k-way ?? ????? ???? ?????.

k-way ?? ????? k?? ??? ???? O(knlogk)? ?? ???? ?? ??? ???? ???? ?????.

? ????? ?? ? ??? ?? ?? ?? ??? ?????.

  • ? ???? ? ?? ??? ?? ?????.
  • ??? ?? ?? ?? ??? ?? ??? ?????. ?? ??? ???? ??? ? ?? ??? ?? ?? ?? ???? ?? ??? ?? ?????.
  • ?? ???? ?? ??? ??? ??? ? ??? ?????.

??

?? ?????? ????/??? ? ??? ?????. heap.Interface? ???? ?? ?? ??? ? ????.

  • ?? ???? ?? ??? ?????. ????? ??? ???? ? ?????. ? ???? ???? ??? ? ??? ?? ??? ????? ?????? ???? LI? ?????.
type Element struct {
    types.Entry
    next []*Element
}

// https://github.com/B1NARY-GR0UP/originium/blob/main/pkg/types/entry.go
type Entry struct {
    Key       string
    Value     []byte
    Tombstone bool  
}
  • ?? ??? ????? sort.Interface ???? ?????. Less ????? ??? ??? ?????. ??? LI? ???? ??? ??? ?? ?? ? ?? ???? ??? ?? ????? ???. ?? ??? ?? ??? ??? ? ?? ??? ???? ???. ? ?? ??? ?? k-way ?? ????? ??? ? ??? ???? ???? ??? ??? ?? ??? ????? ?? ?????.
Level 3:       3 ----------- 9 ----------- 21 --------- 26
Level 2:       3 ----- 6 ---- 9 ------ 19 -- 21 ---- 25 -- 26
Level 1:       3 -- 6 -- 7 -- 9 -- 12 -- 19 -- 21 -- 25 -- 26

next of head [ ->3, ->3, ->3 ]
next of Element 3 [ ->6, ->6, ->9 ]
next of Element 6 [ ->7, ->9 ]
  • ????? Push ? Pop ???? ?????. Push? ???? ?? ??? ???? ?? Pop? ?????? ??? ??? ?????.
func (s *SkipList) Set(entry types.Entry)

??

Merge ???? ?? ??:

curr := s.head
update := make([]*Element, s.maxLevel)

for i := s.maxLevel - 1; i >= 0; i-- {
    for curr.next[i] != nil && curr.next[i].Key < entry.Key {
        curr = curr.next[i]
    }
    update[i] = curr
}

k-way ?? ???? ????? ????.

  • ??, ??? ? ???? ? ?? ??? ?? ?? ?????.
type SkipList struct {
    maxLevel int
    p        float64
    level    int
    rand     *rand.Rand
    size     int
    head     *Element
}
  • ?? ??? ??? ????? ??? ?? ???? ?????. ?? ??? ???? ??? ? ?? ??? ?? ?? ?? ???? ?? ??? ?? ?????. ???? ?? ??? ?? ?? ?????. ?? ???? ?? ??? ???? ?? ?? ?? ?? ?? ?????.
type Element struct {
    types.Entry
    next []*Element
}

// https://github.com/B1NARY-GR0UP/originium/blob/main/pkg/types/entry.go
type Entry struct {
    Key       string
    Value     []byte
    Tombstone bool  
}

????? ?? ???? ?? ???? ??? ???? "?? ??"? ??? ?-? ?? ?????. ?? ??? ?? ??? ?? ?? ??? ?? ???? ???.

Level 3:       3 ----------- 9 ----------- 21 --------- 26
Level 2:       3 ----- 6 ---- 9 ------ 19 -- 21 ---- 25 -- 26
Level 1:       3 -- 6 -- 7 -- 9 -- 12 -- 19 -- 21 -- 25 -- 26

next of head [ ->3, ->3, ->3 ]
next of Element 3 [ ->6, ->6, ->9 ]
next of Element 6 [ ->7, ->9 ]

?? ??

?? ??? ?? ??? https://github.com/B1NARY-GR0UP/originium/blob/main/pkg/filter/filter.go?? ??? ? ????.

?? ??? ??? ??? ????? ??? ????? ???? ??? ?????.

  • ?? ??? ?? ?? ??? ?????.
  • ??? ??? ? ??? ?? ??? ?? ??? ???? ?? ??? 1? ???? ?? ?? ??? ???? ?????.
  • ?? ?? ?? ??? ?? ??? ?? ??? 1?? ?? ??? ??? ? ????. ??? 0?? ?? ??? ??? ???? ?? ????.

?? ? ?? ?? ??? ?? ???? O(k)???. ??? k? ?? ??? ?????. ??? ??? ? ????(?? ??? ??? ??? ??? ????? ??? ??). ??? ??? ??? ? ????(?? ??? ??? ??? ??? ?????). ??? ??? ???? ?????).

???(TP): ???? ???? "???"?? ???? ?? ??? ??????.
???(FP): ?????? ???? '??'?? ????? ???? ?????.
???(TN): ???? ???? "???"?? ???? ???? ??????.
False Negative(FN): ???? ???? "???"?? ????? ???? ??????.

?? ??

?? ??? ?? ???? ?? ??(uint8? ????? ??? ??)? ?? ?? ??? ?????.

func (s *SkipList) Set(entry types.Entry)

???

?? ?? ????? ???? ??? n(?? ?? ?)? p(??? ?????)? ? ?? ????? ?????.

?? ????? ?????. ?? ?? ?? ??? ???? ?? ??? ??(m)? ?? ??? ??(k)? ?????. ????? m? k? ???? ?? ??? ?? ??? ??????.

type SkipList struct {
    maxLevel int
    p        float64
    level    int
    rand     *rand.Rand
    size     int
    head     *Element
}

????

??? ??? ? ?? ?? ??? ?? ?? ?? ???? ? ?????. ?? ?? ? ?? ?? ??? ???? ???? ?? ??? true? ?????.

type Element struct {
    types.Entry
    next []*Element
}

// https://github.com/B1NARY-GR0UP/originium/blob/main/pkg/types/entry.go
type Entry struct {
    Key       string
    Value     []byte
    Tombstone bool  
}

??

?? ??? ??? ???? ?? ?? ??? ?? ?? ???? ?? ?? ??? ???? ?????. ??? ?? ? ???? true? ?? ?? ?? ??? ??? ???? ??? false? ?????.

Level 3:       3 ----------- 9 ----------- 21 --------- 26
Level 2:       3 ----- 6 ---- 9 ------ 19 -- 21 ---- 25 -- 26
Level 1:       3 -- 6 -- 7 -- 9 -- 12 -- 19 -- 21 -- 25 -- 26

next of head [ ->3, ->3, ->3 ]
next of Element 3 [ ->6, ->6, ->9 ]
next of Element 6 [ ->7, ->9 ]

?? ??

?? ??? ?? ??? https://github.com/B1NARY-GR0UP/originium/blob/main/level.go?? ??? ? ????.

K-Way Merge ? Bloom Filter? ?? ?? ??? ??? ? LSM-Tree ???? ???? ?? ??? SSTable ?? ????? ??? ??? ??? ??? ? ????. ? ??? "??? ??" ??? ??? ?? ?? ??? ????.

?? ?? ???? SSTable? ?? ??(?? 0 - ?? N)? ?????. ? ??? ???? ??? ???? SSTable? ???? ??? ?????.

??? ??? levelManager?? ??? ??????. []*list.List? ???? ? ??? ?? SSTable ??? ?????. ??? ????? ???? ??? ?????. ????? ? ??? ?? ??? ?? SSTable? ?? ??? ???? ?? ?? ??? list.List???.

func (s *SkipList) Set(entry types.Entry)

???LN

compactLN ??? ?? N?? ?? N 1(N>0) ??? ?????. LN?? ?? ??? SSTable? ? SSTable? ? ??? ??? LN 1? ?? SSTable? ?????.

curr := s.head
update := make([]*Element, s.maxLevel)

for i := s.maxLevel - 1; i >= 0; i-- {
    for curr.next[i] != nil && curr.next[i].Key < entry.Key {
        curr = curr.next[i]
    }
    update[i] = curr
}

??? SSTable? ?? ??? ??? ?? ? ??? ?????. ??? ??? ?-? ?? 2?? ????? ??? ?? K-Way ?? ????? ???? ?????.

// update entry
if curr.next[0] != nil && curr.next[0].Key == entry.Key {
    s.size += len(entry.Value) - len(curr.next[0].Value)

    // update value and tombstone
    curr.next[0].Value = entry.Value
    curr.next[0].Tombstone = entry.Tombstone
    return
}

??? ?-? ?? ???? ??? Bloom Filter? SSTable? ?????. ??? SSTable? ?? ?? ??? Level N 1? ??? ??? ?????.

// add entry
level := s.randomLevel()

if level > s.level {
    for i := s.level; i < level; i++ {
        update[i] = s.head
    }
    s.level = level
}

????? ?? SSTable? ???? ?? ??? SSTable? ???? ?????.

e := &Element{
    Entry: types.Entry{
        Key:       entry.Key,
        Value:     entry.Value,
        Tombstone: entry.Tombstone,
    },
    next: make([]*Element, level),
}

for i := range level {
    e.next[i] = update[i].next[i]
    update[i].next[i] = e
}
s.size += len(entry.Key) + len(entry.Value) + int(unsafe.Sizeof(entry.Tombstone)) + len(e.next)*int(unsafe.Sizeof((*Element)(nil)))

compactL0 ???? ?? 0?? ?? 1??? ??? ?????. CompactLN? ?? L0?? SSTable? ??? ???? ?? ??? L0?? ??? ?? SSTable? ?????. ??? ??? CompactLN? ?????.

??

?? ??? ?? SSTable?? ?? ?-? ?? ????. L0?? ???? LN?? ? ??? ?????. ?? ??? SSTable? ??? ??? ???? ??? ?-? ?? ???? ?? SSTable? ????? ??? ? ????.

type SkipList struct {
    maxLevel int
    p        float64
    level    int
    rand     *rand.Rand
    size     int
    head     *Element
}

DB

?? ?? LSM-Tree ?? ???? ??? ?? ?? ??? ?? ??????. LSM-Tree ??? ??? ?? ??? ?? ??? ???? ?????? ?????? ??? ? ????.

  • ?? ??: https://github.com/B1NARY-GR0UP/originium/blob/main/db.go

  • ??: https://github.com/B1NARY-GR0UP/originium?tab=readme-ov-file#usage

??

??? LSM-Tree? ???? ??? ???? ?? ?? ??? ????? ?? ?? ????? ??????. ????? ??? ???? ?? LSM-Tree ???? ??? ??????.

?? ? ??? ?????? ????. ????? ???? ???? ? ?? ?? ??? ???? ???. ORIGINIUM? ???? ???? ???? ??? ?? ?????. ? ??? ORIGINIUM? LSM-Tree? ?? ??? ??? ? ??? ??? ????.

???? ? ???? ??? ?? ??? ????. ??? ??? ?? ?? ???? ?? ???? ?? ????? ??? ?????. ?????!

??

  • https://github.com/B1NARY-GR0UP/originium
  • https://www.cnblogs.com/whuanle/p/16297025.html
  • https://vonng.gitbook.io/vonng/part-i/ch3#sstables-he-lsm-shu
  • https://github.com/google/leveldb/blob/main/doc/table_format.md

? ??? ???? LSM-?? ???? ?? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? ????? ??
? ?? ??? ????? ???? ??? ??????, ???? ?????? ????. ? ???? ?? ???? ?? ??? ?? ????. ???? ??? ???? ???? ??? ?? admin@php.cn?? ?????.

? AI ??

Undresser.AI Undress

Undresser.AI Undress

???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover

AI Clothes Remover

???? ?? ???? ??? AI ?????.

Video Face Swap

Video Face Swap

??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

???

??? ??

???++7.3.1

???++7.3.1

???? ?? ?? ?? ???

SublimeText3 ??? ??

SublimeText3 ??? ??

??? ??, ???? ?? ????.

???? 13.0.1 ???

???? 13.0.1 ???

??? PHP ?? ?? ??

???? CS6

???? CS6

??? ? ?? ??

SublimeText3 Mac ??

SublimeText3 Mac ??

? ??? ?? ?? ?????(SublimeText3)

???

??? ??

??? ????
1597
29
PHP ????
1488
72
???
Golang Frontend ?? ?????? Golang Frontend ?? ?????? Jul 08, 2025 am 01:44 AM

Golang? ?? ??? ??? ????? ??? ?? ???? ??? ? ??? ? ?? ????. ?? ??? ???, ?? ?? ? ??? ?? ?????? ????? API ??, ???? ???, ?? ???, ?????? ?? ? CLI ??? ?? ??? ?? ????? ???? ? ?????. Golang? ? ??? ??? ?? ??? ???? Gopherjs? ?? JavaScript? ?????? Tinygo? ?? WebAssembly?? ????? ??? ?? ??? ???? ?? ??? ???? HTML ???? ?? ? ? ????. ??? ???? ??? ?? ??? ??? ??JavaScript/TypeScript ? ???? ???????. ??? Golang? ??? ???? ???? ?? ?? ??? ? ?????.

Golang?? GraphQL API? ???? ?? Golang?? GraphQL API? ???? ?? Jul 08, 2025 am 01:03 AM

GO?? GraphQlapi? ????? GQLGEN ?????? ???? ?? ???? ????? ?? ????. 1. ?? ???? ???? ?? ?? ??? ???? GQLGEN? ?? ??? ?????? ??????. 2. ?? ?? GraphQLSchema? ???? POST ?? ? ?? ??? ??? ?? API ?? ? ?? ??? ??????. 3. ?? ?? ????? ????? ?? ??? ???? Resolver?? ???? ??? ?????. 4. ????? ??? Qlhandler? httpserver? ???? ?? ???? ?? API? ???????. ?? ?? ?? ??, ?? ??, ?? ??? ? ?? ??? ???? ???? ?? ??? ?????.

GO? ???? ?? GO? ???? ?? Jul 09, 2025 am 02:37 AM

GO? ???? ?? ??? ??? ???? ?? ??? ???? ??? ???? ????. 1. ?? ???? ?? ???? ??????? ?? ? ???? ??????. Windows? .msi ??? ???? MacOS? .pkg ??? ???? Linux? .tar.gz ??? ???? /usr /local ????? ??? ????. 2. Linux/MacOS?? ?? ??, ?? ~/.bashrc ?? ~/.zshrc? ???? ??? Gopath? ???? Windows Set ??? ??? ???? ?????. 3. ?? ??? ???? ??? ???? ??? ???? Hello.Go? ???? ?? ? ??? ???? ??????. ???? ???? ?? ?? ? ??

go sync.waitgroup ?? go sync.waitgroup ?? Jul 09, 2025 am 01:48 AM

sync.waitgroup? ?? ? ??? ??? ?? ? ??? ???? ? ?????. ??? ??? ? ?? ??? ?? ?? ??? ???? : ??, ?? ? ??. 1. Aadd (n) ?? ? ?? ? ?? ?????. 2. DONE ()? ? ? ??? ??? ???? ???? 1 ? ?? ???. 3. Wait ()? ?? ??? ?? ? ??? ?? ? ??? ?????. ?? ??? ?? ?? ?? : ADD? ?? ? ???? ????????. ?? ??? ??? DON? ????? ??????. ??? ?? ???? ?? ????. ? ???? ?? ???, ?? ??? ?? ? ?? ?????? ????? ??? ????? ????? ?? ? ? ????.

???/??? ??? ?????? ???/??? ??? ?????? Jul 20, 2025 am 04:14 AM

??? ? ??? ??? ??? ?? ???? ? ??? ??? ???? ? ????. 1. ?? ?????? ??, ???, ??, ??? ? ??? ???? ? ???? ??? ? ???? ????. 2. ??? ? ??? ??, ?? ??, ??? ???, ??? ?? ?? ?? ???? ??? ?? ??, ?? ???, ??? ?? ??, ?? ?? ?? ?? ?? ??? ? ????. 3. FFMPEG, OPENCV, WEBRTC, GSTREAMER ? ?? ??? ???? ??? ???? ?? ????. 4. ?? ?? ???? ???? ??, ???? ??? ??? ?? ??, ?? ??? ? ??? ?? ?????? ???????. ??? ?? ???? ????? ?? ???? ??? ??? ????? ? ??????.

?? ????? ?????? ?? ????? ?????? Jul 09, 2025 am 02:46 AM

Go? Embed ???? ???? ? ???? ??? HTML, CSS, ?? ? ?? ??? ???? ? ??? ?? ???? ????? ?? ???? ? ????. 1. ?? ? ???? ????? ??????. 2. ??/*? ?? ?? ????? ??? ? ??? embed.fs? ?? ?? ?? ??? ??? ? ????. 3. ?? ?? ?? ?? ??? ?? ??? ?? ??? ???? ???? ????? ?? ????. 4. ???? ???? ?? ???, ?? ?? ?? ? ?? ?? ?????????. Embed? ???? ??? ??? ????? ???? ??? ??? ? ? ????.

?? ?? ? ??? ???? ?? ?? ?? ? ??? ???? ?? Jul 15, 2025 am 03:05 AM

?? ?? ??? ? ??? ???? ?? ??? ????. ??? Net/HTTP ???? ???? ?? ???? ???? ? ????. 1. net/http? ???? ?? ??? ??? ??????. ?? ?? ??? ???? ? ?? ??? ?? ??? ????. 2. ??? ?? : Servemux? ???? ?? ??? ? ??? ?? ?? ????? ??? ?????. 3. ???? ?? : ?? ?? ? ?? ??? ? ?? ?????? ???? ??? ??? ?????. 4. ?? ?? ??? : http.fileserver? ?? HTML, CSS ? JS ??? ?????. 5. ?? ? ?? : HTTPS ???, ?? ??? ??? ???? ?? ? ??? ????? ?? ?? ??? ?????. ??? ?? ???? ????? ??? ???? ?? ? ?? ????.

?? ???? ?????? ?? ???? ?????? Jul 14, 2025 am 02:54 AM

Select Plus Default? ??? ?? ??? ???? ??? ?? ????? ??? ? Select? ?? ??? ????? ???? ????. 1. ???? ?? ???? ???? ?? ? ? ??? ?? ??? ?? ??? ?? ?????. 2. ??? ??. ?? ?? ?? ????? ???? ?????. ??? ?? ?? ???? ?? ?? ????. 3. ?? ??? ????, ??? ?? ??? ???? ?? ?? ????? ???? ???????. ?? ??? ?? ?? ??? ?? ???? ?? ? ? ??? ?? ? ??? ?? ????? ??? ???? ????.

See all articles