-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsntable.go
More file actions
60 lines (47 loc) · 1.65 KB
/
Copy pathsntable.go
File metadata and controls
60 lines (47 loc) · 1.65 KB
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
package sntable
import (
"errors"
"github.com/klauspost/compress/zstd"
)
// magic terminates a v1 footer (16 bytes: indexOffset uint64 + magic).
var magic = []byte{71, 39, 134, 190, 31, 122, 101, 219}
// magicBloom terminates a v2 footer (24 bytes: indexOffset uint64 +
// bloomOffset uint64 + magicBloom). A v2 footer is only written when a bloom
// filter is present, so files without a filter stay byte-identical to v1 and
// older readers keep working.
var magicBloom = []byte{71, 39, 134, 190, 31, 122, 101, 220}
const (
blockNoCompression = 0
blockSnappyCompression = 1
blockZstdCompression = 2
)
// Shared, concurrency-safe zstd codec instances for the block EncodeAll/DecodeAll APIs.
var (
zstdEnc, _ = zstd.NewWriter(nil, zstd.WithEncoderLevel(zstd.SpeedDefault))
zstdDec, _ = zstd.NewReader(nil)
)
// ErrNotFound is returned by the reader when a key cannot be found.
var ErrNotFound = errors.New("sntable: not found")
var (
errClosed = errors.New("sntable: is closed")
errBadMagic = errors.New("sntable: bad magic byte sequence")
errBadCompression = errors.New("sntable: bad compression codec")
errReleased = errors.New("sntable: iterator was released")
)
type blockInfo struct {
MaxKey uint64 // maximum key in the block
Offset int64 // block offset position
}
// --------------------------------------------------------------------
// Compression is the compression codec
type Compression byte
func (c Compression) isValid() bool {
return c >= SnappyCompression && c < unknownCompression
}
// Supported compression codecs
const (
SnappyCompression Compression = iota
NoCompression
ZstdCompression
unknownCompression
)