-
Notifications
You must be signed in to change notification settings - Fork 277
/
doc.go
142 lines (123 loc) · 10.9 KB
/
doc.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package tsdb
/*
━━━━━━━━━━━━━━━━━━━━━━━━━━Layout of Shard━━━━━━━━━━━━━━━━━━━━━━━━
Each shard contains a MemoryDatabase.
┌──────────────────┬──────────────────┐
│ Shard │ Shard │
├──────────────────┼──────────────────┤
│ Memory Database │ Memory Database │
└──────────────────┴──────────────────┘
━━━━━━━━━━━━━━━━━━━━━━━━━━Layout of memDB━━━━━━━━━━━━━━━━━━━━━━━━
+--------------+ +--------------+
| |------>| |
| |-+ | |-+
| Memory | | | Metric | |
| Database | |-+ | Store | |-+
| RwMutex | | | | RWMutex | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
+-+------------+ | | +--------------+ | |
+--------------+ | +-----|--------+ |
+--------------+ +---|----------+
|
V
+--------------+ +--------------+
| |<------| |
| |-+ | |-+
| | | | | |
| Field | |-+ | TimeSeries | |-+
| Store | | | | Store | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | SpinLock | | |
+--------------+ | | +--------------+ | |
+----|---------+ | +--------------+ |
+--|-----------+ +--------------+
|
V
+--------------+
| |
| |-+
| | |
| Segment | |-+
| Store | | |
| | | |
| | | |
| | | |
| | | |
| | | |
+--------------+ | |
+--------------+ |
+--------------+
━━━━━━━━━━━━━━━━━━━━━━━━━━Layout of ssTable━━━━━━━━━━━━━━━━━━━━━━━━
Level1
+---------+---------+---------+---------+---------+---------+
| Metric | Metric | Metric | Metric | Metric | Footer |
| Block | Block | Block | Offset | Index | |
+---------+---------+---------+---------+---------+---------+
/ \ \ |\ +-------------------------------+
/ \ \ | +--------------------------------+ \
/ \ \ +-----------------------------+ \ \
/ \ +--------------+ \ \ \
+-----------+ +--------------------------+ \ \ \ \
/ Level2 \ \ \ \ \
v--------+--------+-----------------+--------+--------+--------v v--------+---+--------v v-------v
| Series | Series | Series | Series | Series | Fields | Footer | | Offset |...| Offset | | Metric|
| Entry | Entry | Entry | Offset | Index | Meta | | | | | | | Bitmap|
+--------+--------+--------+--------+--------+--------+--------+ +--------+---+--------+ +-------+
| \ \ |\ \
| \ \ | \ +-----------------------------------------------+
| \ \ | +----------------------------------------------+ \
| \ \ +---------------------------------------------+ \ \
| \ +-----------------------------+ \ \ \
| +------------------------------------+ \ \ \ \
| Level3 \ \ \ \ \
v--------+--------+--------+--------+--------+--------v v--------+---+-------v v---------v
| Fields | Data | Data | Data | Data | Data | | Offset |...| Offset| |seriesID |
| Info | | | | | | | | | | | Bitmap |
+--------+--------+--------+--------+--------+--------+ +--------+---+-------+ +---------+
Level1(KV table: MetricBlocks, Offset, Keys)
┌───────────────────────────────────────────┬───────────────────────────────────────────┐
│ Metric Blocks │ Offset And Keys │
├──────────┬──────────┬──────────┬──────────┼──────────┬──────────┬──────────┬──────────┤
│ length │ Metric │ length │ Metric │ length │ Offset │ length │ Keys │
│ │ Block1 │ │ Block2 │ │ │ │ │
├──────────┼──────────┼──────────┼──────────┼──────────┼──────────┼──────────┼──────────┤
│ uvariant │ N Bytes │ uvariant │ N Bytes │ uvariant │ N Bytes │ uvariant │ N Bytes │
└──────────┴──────────┴──────────┴──────────^──────────┴──────────^──────────┴──────────┘
| |
posOfOffset posOfKeys
Level1(KV table: Footer)
┌──────────────────────────────────────────────────────┐
│ Footer │
├──────────┬──────────┬──────────┬──────────┬──────────┤
│ length │ position │ position │ Version │ Magic │
│ │ OfOffset │ OfKeys │ │ Number │
├──────────┼──────────┼──────────┼──────────┼──────────┤
│ 1 Byte │ 4 Bytes │ 4 Bytes │ 1 Bytes │ 8 Bytes │
└──────────┴──────────┴──────────┴──────────┴──────────┘
Level2(Fields Meta, Fields Footer)
┌─────────────────────────────────────────────────────────────────┬───────────────────────────────────────────┐
│ Fields Meta │ Fields Footer │
├──────────┬──────────┬──────────┬──────────┬──────────┬──────────┼──────────┬──────────┬──────────┬──────────┤
│StartTime │ EndTime │ Count │ FieldID │ Field │ │ OffsetOf │ OffsetOf │ OffsetOf │ CRC32 │
│ (delta) │ (delta) │ │ (uint16) │ Type │ ...... │ TSOffset │ TSIndex │FieldsMeta│ Checksum │
├──────────┼──────────┼──────────┼──────────┼──────────┼──────────┼──────────┼──────────┼──────────┼──────────┤
│ uvariant │ uvariant │ uvariant │ 2 Bytes │ 1 Byte │ 3N Bytes │ 4 Bytes │ 4 Bytes │ 4 Bytes │ 4 Bytes │
└──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┘
Level3(Fields Info, Fields Data)
┌─────────────────────────────────────────────────────────────────┬─────────────────────┐
│ Fields Info │ Fields Data │
├──────────┬──────────┬──────────┬──────────┬──────────┬──────────┼──────────┬──────────┤
│StartTime │ EndTime │ Length │ BitArray │ Data1 │ Data2 │ Data1 │ Data2 │
│ variant │ variant │ variant │ │ Length │ Length │ │ │
├──────────┼──────────┼──────────┼──────────┼──────────┼──────────┼──────────┼──────────┤
│ uvariant │ uvariant │ uvariant │ N Bytes │ uvariant │ uvariant │ N Bytes │ N Bytes │
└──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┘
bit array example(10101001, 0001)
*/