-
Notifications
You must be signed in to change notification settings - Fork 85
/
encoding.go
94 lines (85 loc) · 3.06 KB
/
encoding.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
// Licensed to Apache Software Foundation (ASF) under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Apache Software Foundation (ASF) licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package encoding
import (
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
var ErrEncodeEmpty = errors.New("encode an empty value")
var (
rawSize = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "banyand_encoding_raw_size",
Help: "The raw size of series",
ConstLabels: prometheus.Labels{"model": "encoding"},
}, []string{"name", "type"})
encodedSize = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "banyand_encoding_encoded_size",
Help: "The encoded size of series",
ConstLabels: prometheus.Labels{"model": "encoding"},
}, []string{"name", "type"})
itemsNum = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "banyand_encoding_items_num",
Help: "The number of items in a encoded series",
ConstLabels: prometheus.Labels{"model": "encoding"},
}, []string{"name", "type"})
)
type SeriesEncoderPool interface {
Get(metadata []byte) SeriesEncoder
Put(encoder SeriesEncoder)
}
// SeriesEncoder encodes time series data point
type SeriesEncoder interface {
// Append a data point
Append(ts uint64, value []byte)
// IsFull returns whether the encoded data reached its capacity
IsFull() bool
// Reset the underlying buffer
Reset(key []byte)
// Encode the time series data point to a binary
Encode() ([]byte, error)
// StartTime indicates the first entry's time
StartTime() uint64
}
type SeriesDecoderPool interface {
Get(metadata []byte) SeriesDecoder
Put(encoder SeriesDecoder)
}
// SeriesDecoder decodes encoded time series data
type SeriesDecoder interface {
// Decode the time series data
Decode(key, data []byte) error
// Len denotes the size of iterator
Len() int
// IsFull returns whether the encoded data reached its capacity
IsFull() bool
// Get the data point by its time
Get(ts uint64) ([]byte, error)
// Iterator returns a SeriesIterator
Iterator() SeriesIterator
}
// SeriesIterator iterates time series data
type SeriesIterator interface {
// Next scroll the cursor to the next
Next() bool
// Val returns the value of the current data point
Val() []byte
// Time returns the time of the current data point
Time() uint64
// Error might return an error indicates a decode failure
Error() error
}