-
Notifications
You must be signed in to change notification settings - Fork 679
/
commitlogger_parser_collection.go
107 lines (88 loc) · 2.09 KB
/
commitlogger_parser_collection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// _ _
// __ _____ __ ___ ___ __ _| |_ ___
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
// \ V V / __/ (_| |\ V /| | (_| | || __/
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
//
// Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
//
// CONTACT: hello@weaviate.io
//
package lsmkv
import (
"encoding/binary"
"fmt"
"io"
"github.com/pkg/errors"
)
func (p *commitloggerParser) doCollection() error {
for {
var commitType CommitType
err := binary.Read(p.checksumReader, binary.LittleEndian, &commitType)
if errors.Is(err, io.EOF) {
break
}
if err != nil {
return errors.Wrap(err, "read commit type")
}
if !CommitTypeCollection.Is(commitType) {
return errors.Errorf("found a %s commit on a collection bucket", commitType.String())
}
var version uint8
err = binary.Read(p.checksumReader, binary.LittleEndian, &version)
if err != nil {
return errors.Wrap(err, "read commit version")
}
switch version {
case 0:
{
err = p.parseCollectionNodeV0()
}
case 1:
{
err = p.parseCollectionNodeV1()
}
default:
{
return fmt.Errorf("unsupported commit version %d", version)
}
}
if err != nil {
return err
}
}
return nil
}
func (p *commitloggerParser) parseCollectionNodeV0() error {
return p.parseCollectionNode(p.reader)
}
func (p *commitloggerParser) parseCollectionNodeV1() error {
reader, err := p.doRecord()
if err != nil {
return err
}
return p.parseCollectionNode(reader)
}
func (p *commitloggerParser) parseCollectionNode(reader io.Reader) error {
n, err := ParseCollectionNode(reader)
if err != nil {
return err
}
if p.strategy == StrategyMapCollection {
return p.parseMapNode(n)
}
return p.memtable.append(n.primaryKey, n.values)
}
func (p *commitloggerParser) parseMapNode(n segmentCollectionNode) error {
for _, val := range n.values {
mp := MapPair{}
if err := mp.FromBytes(val.value, false); err != nil {
return err
}
mp.Tombstone = val.tombstone
if err := p.memtable.appendMapSorted(n.primaryKey, mp); err != nil {
return err
}
}
return nil
}