Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doodoocoder
prometheus
提交
1ddedf2b
P
prometheus
项目概览
doodoocoder
/
prometheus
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
prometheus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1ddedf2b
编写于
9月 04, 2017
作者:
F
Fabian Reinartz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change series ID from uint32 to uint64
上级
af2c2f96
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
198 addition
and
181 deletion
+198
-181
block.go
block.go
+1
-1
compact.go
compact.go
+4
-4
head.go
head.go
+38
-22
head_test.go
head_test.go
+4
-4
index.go
index.go
+10
-7
index_test.go
index_test.go
+12
-12
postings.go
postings.go
+23
-23
postings_test.go
postings_test.go
+69
-69
querier_test.go
querier_test.go
+9
-9
tombstones.go
tombstones.go
+13
-13
tombstones_test.go
tombstones_test.go
+3
-3
wal.go
wal.go
+11
-13
wal_test.go
wal_test.go
+1
-1
未找到文件。
block.go
浏览文件 @
1ddedf2b
...
...
@@ -225,7 +225,7 @@ func (pb *persistedBlock) Delete(mint, maxt int64, ms ...labels.Matcher) error {
ir
:=
pb
.
indexr
// Choose only valid postings which have chunks in the time-range.
stones
:=
map
[
uint
32
]
Intervals
{}
stones
:=
map
[
uint
64
]
Intervals
{}
var
lset
labels
.
Labels
var
chks
[]
ChunkMeta
...
...
compact.go
浏览文件 @
1ddedf2b
...
...
@@ -477,9 +477,9 @@ func (c *LeveledCompactor) populateBlock(blocks []BlockReader, meta *BlockMeta,
// We fully rebuild the postings list index from merged series.
var
(
postings
=
&
memPostings
{
m
:
make
(
map
[
term
][]
uint
32
,
512
)}
postings
=
&
memPostings
{
m
:
make
(
map
[
term
][]
uint
64
,
512
)}
values
=
map
[
string
]
stringset
{}
i
=
uint
32
(
0
)
i
=
uint
64
(
0
)
)
if
err
:=
indexw
.
AddSymbols
(
allSymbols
);
err
!=
nil
{
...
...
@@ -568,9 +568,9 @@ func (c *LeveledCompactor) populateBlock(blocks []BlockReader, meta *BlockMeta,
}
}
// Write a postings list containing all series.
all
:=
make
([]
uint
32
,
i
)
all
:=
make
([]
uint
64
,
i
)
for
i
:=
range
all
{
all
[
i
]
=
uint
32
(
i
)
all
[
i
]
=
uint
64
(
i
)
}
if
err
:=
indexw
.
WritePostings
(
""
,
""
,
newListPostings
(
all
));
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"write 'all' postings"
)
...
...
head.go
浏览文件 @
1ddedf2b
...
...
@@ -55,11 +55,11 @@ type Head struct {
appendPool
sync
.
Pool
minTime
,
maxTime
int64
lastSeriesID
uint
32
lastSeriesID
uint
64
// descs holds all chunk descs for the head block. Each chunk implicitly
// is assigned the index as its ID.
series
map
[
uint
32
]
*
memSeries
series
map
[
uint
64
]
*
memSeries
// hashes contains a collision map of label set hashes of chunks
// to their chunk descs.
hashes
map
[
uint64
][]
*
memSeries
...
...
@@ -178,11 +178,11 @@ func NewHead(r prometheus.Registerer, l log.Logger, wal WAL, chunkRange int64) (
chunkRange
:
chunkRange
,
minTime
:
math
.
MaxInt64
,
maxTime
:
math
.
MinInt64
,
series
:
map
[
uint
32
]
*
memSeries
{},
series
:
map
[
uint
64
]
*
memSeries
{},
hashes
:
map
[
uint64
][]
*
memSeries
{},
values
:
map
[
string
]
stringset
{},
symbols
:
map
[
string
]
struct
{}{},
postings
:
&
memPostings
{
m
:
make
(
map
[
term
][]
uint
32
)},
postings
:
&
memPostings
{
m
:
make
(
map
[
term
][]
uint
64
)},
tombstones
:
newEmptyTombstoneReader
(),
}
h
.
metrics
=
newHeadMetrics
(
h
,
r
)
...
...
@@ -201,7 +201,7 @@ func (h *Head) readWAL() error {
}
samplesFunc
:=
func
(
samples
[]
RefSample
)
error
{
for
_
,
s
:=
range
samples
{
ms
,
ok
:=
h
.
series
[
uint32
(
s
.
Ref
)
]
ms
,
ok
:=
h
.
series
[
s
.
Ref
]
if
!
ok
{
return
errors
.
Errorf
(
"unknown series reference %d; abort WAL restore"
,
s
.
Ref
)
}
...
...
@@ -424,13 +424,13 @@ func (a *headAppender) AddFast(ref string, t int64, v float64) error {
}
var
(
refn
=
binary
.
BigEndian
.
Uint64
(
yoloBytes
(
ref
))
id
=
uint32
(
refn
)
id
=
(
refn
<<
1
)
>>
1
inTx
=
refn
&
(
1
<<
63
)
!=
0
)
// Distinguish between existing series and series created in
// this transaction.
if
inTx
{
if
id
>
uint
32
(
len
(
a
.
newSeries
)
-
1
)
{
if
id
>
uint
64
(
len
(
a
.
newSeries
)
-
1
)
{
return
errors
.
Wrap
(
ErrNotFound
,
"transaction series ID too high"
)
}
// TODO(fabxc): we also have to validate here that the
...
...
@@ -527,7 +527,7 @@ func (a *headAppender) Commit() error {
total
:=
uint64
(
len
(
a
.
samples
))
for
_
,
s
:=
range
a
.
samples
{
series
,
ok
:=
a
.
head
.
series
[
uint32
(
s
.
Ref
)
]
series
,
ok
:=
a
.
head
.
series
[
s
.
Ref
]
if
!
ok
{
return
errors
.
Errorf
(
"series with ID %d not found"
,
s
.
Ref
)
}
...
...
@@ -614,7 +614,7 @@ func (h *Head) gc() {
// Only data strictly lower than this timestamp must be deleted.
mint
:=
h
.
MinTime
()
deletedHashes
:=
map
[
uint64
][]
uint
32
{}
deletedHashes
:=
map
[
uint64
][]
uint
64
{}
h
.
mtx
.
RLock
()
...
...
@@ -630,7 +630,7 @@ func (h *Head) gc() {
}
}
deletedIDs
:=
make
(
map
[
uint
32
]
struct
{},
len
(
deletedHashes
))
deletedIDs
:=
make
(
map
[
uint
64
]
struct
{},
len
(
deletedHashes
))
h
.
mtx
.
RUnlock
()
...
...
@@ -639,7 +639,7 @@ func (h *Head) gc() {
for
hash
,
ids
:=
range
deletedHashes
{
inIDs
:=
func
(
id
uint
32
)
bool
{
inIDs
:=
func
(
id
uint
64
)
bool
{
for
_
,
o
:=
range
ids
{
if
o
==
id
{
return
true
...
...
@@ -675,7 +675,7 @@ func (h *Head) gc() {
}
for
t
,
p
:=
range
h
.
postings
.
m
{
repl
:=
make
([]
uint
32
,
0
,
len
(
p
))
repl
:=
make
([]
uint
64
,
0
,
len
(
p
))
for
_
,
id
:=
range
p
{
if
_
,
ok
:=
deletedIDs
[
id
];
!
ok
{
...
...
@@ -761,16 +761,32 @@ func (h *headChunkReader) Close() error {
return
nil
}
// packChunkID packs a seriesID and a chunkID within it into a global 8 byte ID.
// It panicks if the seriesID exceeds 5 bytes or the chunk ID 3 bytes.
func
packChunkID
(
seriesID
,
chunkID
uint64
)
uint64
{
if
seriesID
>
(
1
<<
40
)
-
1
{
panic
(
"series ID exceeds 5 bytes"
)
}
if
chunkID
>
(
1
<<
24
)
-
1
{
panic
(
"chunk ID exceeds 3 bytes"
)
}
return
(
seriesID
<<
24
)
|
chunkID
}
func
unpackChunkID
(
id
uint64
)
(
seriesID
,
chunkID
uint64
)
{
return
id
>>
24
,
(
id
<<
40
)
>>
40
}
// Chunk returns the chunk for the reference number.
func
(
h
*
headChunkReader
)
Chunk
(
ref
uint64
)
(
chunks
.
Chunk
,
error
)
{
h
.
head
.
mtx
.
RLock
()
defer
h
.
head
.
mtx
.
RUnlock
()
s
:=
h
.
head
.
series
[
uint32
(
ref
>>
32
)]
sid
,
cid
:=
unpackChunkID
(
ref
)
s
:=
h
.
head
.
series
[
sid
]
s
.
mtx
.
RLock
()
cid
:=
int
((
ref
<<
32
)
>>
32
)
c
:=
s
.
chunk
(
cid
)
c
:=
s
.
chunk
(
int
(
cid
))
s
.
mtx
.
RUnlock
()
// Do not expose chunks that are outside of the specified range.
...
...
@@ -780,7 +796,7 @@ func (h *headChunkReader) Chunk(ref uint64) (chunks.Chunk, error) {
return
&
safeChunk
{
Chunk
:
c
.
chunk
,
s
:
s
,
cid
:
cid
,
cid
:
int
(
cid
)
,
},
nil
}
...
...
@@ -860,7 +876,7 @@ func (h *headIndexReader) SortedPostings(p Postings) Postings {
h
.
head
.
mtx
.
RLock
()
defer
h
.
head
.
mtx
.
RUnlock
()
ep
:=
make
([]
uint
32
,
0
,
1024
)
ep
:=
make
([]
uint
64
,
0
,
1024
)
for
p
.
Next
()
{
ep
=
append
(
ep
,
p
.
At
())
...
...
@@ -890,7 +906,7 @@ func (h *headIndexReader) SortedPostings(p Postings) Postings {
}
// Series returns the series for the given reference.
func
(
h
*
headIndexReader
)
Series
(
ref
uint
32
,
lbls
*
labels
.
Labels
,
chks
*
[]
ChunkMeta
)
error
{
func
(
h
*
headIndexReader
)
Series
(
ref
uint
64
,
lbls
*
labels
.
Labels
,
chks
*
[]
ChunkMeta
)
error
{
h
.
head
.
mtx
.
RLock
()
defer
h
.
head
.
mtx
.
RUnlock
()
...
...
@@ -913,7 +929,7 @@ func (h *headIndexReader) Series(ref uint32, lbls *labels.Labels, chks *[]ChunkM
*
chks
=
append
(
*
chks
,
ChunkMeta
{
MinTime
:
c
.
minTime
,
MaxTime
:
c
.
maxTime
,
Ref
:
(
uint64
(
ref
)
<<
32
)
|
uint64
(
s
.
chunkID
(
i
)),
Ref
:
packChunkID
(
s
.
ref
,
uint64
(
s
.
chunkID
(
i
)
)),
})
}
...
...
@@ -949,7 +965,7 @@ func (h *Head) create(hash uint64, lset labels.Labels) *memSeries {
h
.
metrics
.
series
.
Inc
()
h
.
metrics
.
seriesCreated
.
Inc
()
id
:=
atomic
.
AddUint
32
(
&
h
.
lastSeriesID
,
1
)
id
:=
atomic
.
AddUint
64
(
&
h
.
lastSeriesID
,
1
)
s
:=
newMemSeries
(
lset
,
id
,
h
.
chunkRange
)
h
.
series
[
id
]
=
s
...
...
@@ -983,7 +999,7 @@ type sample struct {
type
memSeries
struct
{
mtx
sync
.
RWMutex
ref
uint
32
ref
uint
64
lset
labels
.
Labels
chunks
[]
*
memChunk
chunkRange
int64
...
...
@@ -1020,7 +1036,7 @@ func (s *memSeries) cut(mint int64) *memChunk {
return
c
}
func
newMemSeries
(
lset
labels
.
Labels
,
id
uint
32
,
chunkRange
int64
)
*
memSeries
{
func
newMemSeries
(
lset
labels
.
Labels
,
id
uint
64
,
chunkRange
int64
)
*
memSeries
{
s
:=
&
memSeries
{
lset
:
lset
,
ref
:
id
,
...
...
head_test.go
浏览文件 @
1ddedf2b
...
...
@@ -134,10 +134,10 @@ func TestHead_Truncate(t *testing.T) {
postingsC1
,
_
:=
expandPostings
(
h
.
postings
.
get
(
term
{
"c"
,
"1"
}))
postingsAll
,
_
:=
expandPostings
(
h
.
postings
.
get
(
term
{
""
,
""
}))
require
.
Equal
(
t
,
[]
uint
32
{
s1
.
ref
},
postingsA1
)
require
.
Equal
(
t
,
[]
uint
32
{
s2
.
ref
},
postingsA2
)
require
.
Equal
(
t
,
[]
uint
32
{
s1
.
ref
,
s2
.
ref
},
postingsB1
)
require
.
Equal
(
t
,
[]
uint
32
{
s1
.
ref
,
s2
.
ref
},
postingsAll
)
require
.
Equal
(
t
,
[]
uint
64
{
s1
.
ref
},
postingsA1
)
require
.
Equal
(
t
,
[]
uint
64
{
s2
.
ref
},
postingsA2
)
require
.
Equal
(
t
,
[]
uint
64
{
s1
.
ref
,
s2
.
ref
},
postingsB1
)
require
.
Equal
(
t
,
[]
uint
64
{
s1
.
ref
,
s2
.
ref
},
postingsAll
)
require
.
Nil
(
t
,
postingsB2
)
require
.
Nil
(
t
,
postingsC1
)
...
...
index.go
浏览文件 @
1ddedf2b
...
...
@@ -99,7 +99,7 @@ type IndexWriter interface {
// their labels.
// The reference numbers are used to resolve entries in postings lists that
// are added later.
AddSeries
(
ref
uint
32
,
l
labels
.
Labels
,
chunks
...
ChunkMeta
)
error
AddSeries
(
ref
uint
64
,
l
labels
.
Labels
,
chunks
...
ChunkMeta
)
error
// WriteLabelIndex serializes an index from label names to values.
// The passed in values chained tuples of strings of the length of names.
...
...
@@ -130,7 +130,7 @@ type indexWriter struct {
uint32s
[]
uint32
symbols
map
[
string
]
uint32
// symbol offsets
seriesOffsets
map
[
uint
32
]
uint64
// offsets of series
seriesOffsets
map
[
uint
64
]
uint64
// offsets of series
labelIndexes
[]
hashEntry
// label index offsets
postings
[]
hashEntry
// postings lists offsets
...
...
@@ -175,7 +175,7 @@ func newIndexWriter(dir string) (*indexWriter, error) {
// Caches.
symbols
:
make
(
map
[
string
]
uint32
,
1
<<
13
),
seriesOffsets
:
make
(
map
[
uint
32
]
uint64
,
1
<<
16
),
seriesOffsets
:
make
(
map
[
uint
64
]
uint64
,
1
<<
16
),
crc32
:
newCRC32
(),
}
if
err
:=
iw
.
writeMeta
();
err
!=
nil
{
...
...
@@ -260,7 +260,7 @@ func (w *indexWriter) writeMeta() error {
return
w
.
write
(
w
.
buf1
.
get
())
}
func
(
w
*
indexWriter
)
AddSeries
(
ref
uint
32
,
lset
labels
.
Labels
,
chunks
...
ChunkMeta
)
error
{
func
(
w
*
indexWriter
)
AddSeries
(
ref
uint
64
,
lset
labels
.
Labels
,
chunks
...
ChunkMeta
)
error
{
if
err
:=
w
.
ensureStage
(
idxStageSeries
);
err
!=
nil
{
return
err
}
...
...
@@ -457,7 +457,10 @@ func (w *indexWriter) WritePostings(name, value string, it Postings) error {
if
!
ok
{
return
errors
.
Errorf
(
"%p series for reference %d not found"
,
w
,
it
.
At
())
}
refs
=
append
(
refs
,
uint32
(
offset
))
// XXX(fabxc): get uint64 vs uint32 sorted out.
if
offset
>
(
1
<<
32
)
-
1
{
return
errors
.
Errorf
(
"series offset %d exceeds 4 bytes"
,
offset
)
}
refs
=
append
(
refs
,
uint32
(
offset
))
}
if
err
:=
it
.
Err
();
err
!=
nil
{
return
err
...
...
@@ -524,7 +527,7 @@ type IndexReader interface {
// Series populates the given labels and chunk metas for the series identified
// by the reference.
Series
(
ref
uint
32
,
lset
*
labels
.
Labels
,
chks
*
[]
ChunkMeta
)
error
Series
(
ref
uint
64
,
lset
*
labels
.
Labels
,
chks
*
[]
ChunkMeta
)
error
// LabelIndices returns the label pairs for which indices exist.
LabelIndices
()
([][]
string
,
error
)
...
...
@@ -740,7 +743,7 @@ func (r *indexReader) LabelIndices() ([][]string, error) {
return
res
,
nil
}
func
(
r
*
indexReader
)
Series
(
ref
uint
32
,
lbls
*
labels
.
Labels
,
chks
*
[]
ChunkMeta
)
error
{
func
(
r
*
indexReader
)
Series
(
ref
uint
64
,
lbls
*
labels
.
Labels
,
chks
*
[]
ChunkMeta
)
error
{
d1
:=
r
.
decbufAt
(
int
(
ref
))
d2
:=
d1
.
decbuf
(
int
(
d1
.
uvarint
()))
...
...
index_test.go
浏览文件 @
1ddedf2b
...
...
@@ -33,7 +33,7 @@ type series struct {
}
type
mockIndex
struct
{
series
map
[
uint
32
]
series
series
map
[
uint
64
]
series
labelIndex
map
[
string
][]
string
postings
*
memPostings
symbols
map
[
string
]
struct
{}
...
...
@@ -41,9 +41,9 @@ type mockIndex struct {
func
newMockIndex
()
mockIndex
{
return
mockIndex
{
series
:
make
(
map
[
uint
32
]
series
),
series
:
make
(
map
[
uint
64
]
series
),
labelIndex
:
make
(
map
[
string
][]
string
),
postings
:
&
memPostings
{
m
:
make
(
map
[
term
][]
uint
32
)},
postings
:
&
memPostings
{
m
:
make
(
map
[
term
][]
uint
64
)},
symbols
:
make
(
map
[
string
]
struct
{}),
}
}
...
...
@@ -52,7 +52,7 @@ func (m mockIndex) Symbols() (map[string]struct{}, error) {
return
m
.
symbols
,
nil
}
func
(
m
mockIndex
)
AddSeries
(
ref
uint
32
,
l
labels
.
Labels
,
chunks
...
ChunkMeta
)
error
{
func
(
m
mockIndex
)
AddSeries
(
ref
uint
64
,
l
labels
.
Labels
,
chunks
...
ChunkMeta
)
error
{
if
_
,
ok
:=
m
.
series
[
ref
];
ok
{
return
errors
.
Errorf
(
"series with reference %d already added"
,
ref
)
}
...
...
@@ -125,7 +125,7 @@ func (m mockIndex) SortedPostings(p Postings) Postings {
return
newListPostings
(
ep
)
}
func
(
m
mockIndex
)
Series
(
ref
uint
32
,
lset
*
labels
.
Labels
,
chks
*
[]
ChunkMeta
)
error
{
func
(
m
mockIndex
)
Series
(
ref
uint
64
,
lset
*
labels
.
Labels
,
chks
*
[]
ChunkMeta
)
error
{
s
,
ok
:=
m
.
series
[
ref
]
if
!
ok
{
return
ErrNotFound
...
...
@@ -202,7 +202,7 @@ func TestIndexRW_Postings(t *testing.T) {
require
.
NoError
(
t
,
iw
.
AddSeries
(
3
,
series
[
2
]))
require
.
NoError
(
t
,
iw
.
AddSeries
(
4
,
series
[
3
]))
err
=
iw
.
WritePostings
(
"a"
,
"1"
,
newListPostings
([]
uint
32
{
1
,
2
,
3
,
4
}))
err
=
iw
.
WritePostings
(
"a"
,
"1"
,
newListPostings
([]
uint
64
{
1
,
2
,
3
,
4
}))
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
iw
.
Close
())
...
...
@@ -274,16 +274,16 @@ func TestPersistence_index_e2e(t *testing.T) {
// Population procedure as done by compaction.
var
(
postings
=
&
memPostings
{
m
:
make
(
map
[
term
][]
uint
32
,
512
)}
postings
=
&
memPostings
{
m
:
make
(
map
[
term
][]
uint
64
,
512
)}
values
=
map
[
string
]
stringset
{}
)
mi
:=
newMockIndex
()
for
i
,
s
:=
range
input
{
err
=
iw
.
AddSeries
(
uint
32
(
i
),
s
.
labels
,
s
.
chunks
...
)
err
=
iw
.
AddSeries
(
uint
64
(
i
),
s
.
labels
,
s
.
chunks
...
)
require
.
NoError
(
t
,
err
)
mi
.
AddSeries
(
uint
32
(
i
),
s
.
labels
,
s
.
chunks
...
)
mi
.
AddSeries
(
uint
64
(
i
),
s
.
labels
,
s
.
chunks
...
)
for
_
,
l
:=
range
s
.
labels
{
valset
,
ok
:=
values
[
l
.
Name
]
...
...
@@ -293,7 +293,7 @@ func TestPersistence_index_e2e(t *testing.T) {
}
valset
.
set
(
l
.
Value
)
postings
.
add
(
uint
32
(
i
),
term
{
name
:
l
.
Name
,
value
:
l
.
Value
})
postings
.
add
(
uint
64
(
i
),
term
{
name
:
l
.
Name
,
value
:
l
.
Value
})
}
i
++
}
...
...
@@ -305,9 +305,9 @@ func TestPersistence_index_e2e(t *testing.T) {
require
.
NoError
(
t
,
mi
.
WriteLabelIndex
([]
string
{
k
},
vals
))
}
all
:=
make
([]
uint
32
,
len
(
lbls
))
all
:=
make
([]
uint
64
,
len
(
lbls
))
for
i
:=
range
all
{
all
[
i
]
=
uint
32
(
i
)
all
[
i
]
=
uint
64
(
i
)
}
err
=
iw
.
WritePostings
(
""
,
""
,
newListPostings
(
all
))
require
.
NoError
(
t
,
err
)
...
...
postings.go
浏览文件 @
1ddedf2b
...
...
@@ -20,7 +20,7 @@ import (
)
type
memPostings
struct
{
m
map
[
term
][]
uint
32
m
map
[
term
][]
uint
64
}
type
term
struct
{
...
...
@@ -38,7 +38,7 @@ func (p *memPostings) get(t term) Postings {
// add adds a document to the index. The caller has to ensure that no
// term argument appears twice.
func
(
p
*
memPostings
)
add
(
id
uint
32
,
terms
...
term
)
{
func
(
p
*
memPostings
)
add
(
id
uint
64
,
terms
...
term
)
{
for
_
,
t
:=
range
terms
{
p
.
m
[
t
]
=
append
(
p
.
m
[
t
],
id
)
}
...
...
@@ -51,10 +51,10 @@ type Postings interface {
// Seek advances the iterator to value v or greater and returns
// true if a value was found.
Seek
(
v
uint
32
)
bool
Seek
(
v
uint
64
)
bool
// At returns the value at the current iterator position.
At
()
uint
32
At
()
uint
64
// Err returns the last error of the iterator.
Err
()
error
...
...
@@ -66,8 +66,8 @@ type errPostings struct {
}
func
(
e
errPostings
)
Next
()
bool
{
return
false
}
func
(
e
errPostings
)
Seek
(
uint
32
)
bool
{
return
false
}
func
(
e
errPostings
)
At
()
uint
32
{
return
0
}
func
(
e
errPostings
)
Seek
(
uint
64
)
bool
{
return
false
}
func
(
e
errPostings
)
At
()
uint
64
{
return
0
}
func
(
e
errPostings
)
Err
()
error
{
return
e
.
err
}
var
emptyPostings
=
errPostings
{}
...
...
@@ -88,18 +88,18 @@ func Intersect(its ...Postings) Postings {
type
intersectPostings
struct
{
a
,
b
Postings
aok
,
bok
bool
cur
uint
32
cur
uint
64
}
func
newIntersectPostings
(
a
,
b
Postings
)
*
intersectPostings
{
return
&
intersectPostings
{
a
:
a
,
b
:
b
}
}
func
(
it
*
intersectPostings
)
At
()
uint
32
{
func
(
it
*
intersectPostings
)
At
()
uint
64
{
return
it
.
cur
}
func
(
it
*
intersectPostings
)
doNext
(
id
uint
32
)
bool
{
func
(
it
*
intersectPostings
)
doNext
(
id
uint
64
)
bool
{
for
{
if
!
it
.
b
.
Seek
(
id
)
{
return
false
...
...
@@ -125,7 +125,7 @@ func (it *intersectPostings) Next() bool {
return
it
.
doNext
(
it
.
a
.
At
())
}
func
(
it
*
intersectPostings
)
Seek
(
id
uint
32
)
bool
{
func
(
it
*
intersectPostings
)
Seek
(
id
uint
64
)
bool
{
if
!
it
.
a
.
Seek
(
id
)
{
return
false
}
...
...
@@ -155,14 +155,14 @@ type mergedPostings struct {
a
,
b
Postings
initialized
bool
aok
,
bok
bool
cur
uint
32
cur
uint
64
}
func
newMergedPostings
(
a
,
b
Postings
)
*
mergedPostings
{
return
&
mergedPostings
{
a
:
a
,
b
:
b
}
}
func
(
it
*
mergedPostings
)
At
()
uint
32
{
func
(
it
*
mergedPostings
)
At
()
uint
64
{
return
it
.
cur
}
...
...
@@ -204,7 +204,7 @@ func (it *mergedPostings) Next() bool {
return
true
}
func
(
it
*
mergedPostings
)
Seek
(
id
uint
32
)
bool
{
func
(
it
*
mergedPostings
)
Seek
(
id
uint
64
)
bool
{
if
it
.
cur
>=
id
{
return
true
}
...
...
@@ -225,15 +225,15 @@ func (it *mergedPostings) Err() error {
// listPostings implements the Postings interface over a plain list.
type
listPostings
struct
{
list
[]
uint
32
cur
uint
32
list
[]
uint
64
cur
uint
64
}
func
newListPostings
(
list
[]
uint
32
)
*
listPostings
{
func
newListPostings
(
list
[]
uint
64
)
*
listPostings
{
return
&
listPostings
{
list
:
list
}
}
func
(
it
*
listPostings
)
At
()
uint
32
{
func
(
it
*
listPostings
)
At
()
uint
64
{
return
it
.
cur
}
...
...
@@ -247,7 +247,7 @@ func (it *listPostings) Next() bool {
return
false
}
func
(
it
*
listPostings
)
Seek
(
x
uint
32
)
bool
{
func
(
it
*
listPostings
)
Seek
(
x
uint
64
)
bool
{
// If the current value satisfies, then return.
if
it
.
cur
>=
x
{
return
true
...
...
@@ -281,8 +281,8 @@ func newBigEndianPostings(list []byte) *bigEndianPostings {
return
&
bigEndianPostings
{
list
:
list
}
}
func
(
it
*
bigEndianPostings
)
At
()
uint
32
{
return
it
.
cur
func
(
it
*
bigEndianPostings
)
At
()
uint
64
{
return
uint64
(
it
.
cur
)
}
func
(
it
*
bigEndianPostings
)
Next
()
bool
{
...
...
@@ -294,15 +294,15 @@ func (it *bigEndianPostings) Next() bool {
return
false
}
func
(
it
*
bigEndianPostings
)
Seek
(
x
uint
32
)
bool
{
if
it
.
cur
>=
x
{
func
(
it
*
bigEndianPostings
)
Seek
(
x
uint
64
)
bool
{
if
uint64
(
it
.
cur
)
>=
x
{
return
true
}
num
:=
len
(
it
.
list
)
/
4
// Do binary search between current position and end.
i
:=
sort
.
Search
(
num
,
func
(
i
int
)
bool
{
return
binary
.
BigEndian
.
Uint32
(
it
.
list
[
i
*
4
:
])
>=
x
return
binary
.
BigEndian
.
Uint32
(
it
.
list
[
i
*
4
:
])
>=
uint32
(
x
)
})
if
i
<
num
{
j
:=
i
*
4
...
...
postings_test.go
浏览文件 @
1ddedf2b
...
...
@@ -23,17 +23,17 @@ import (
type
mockPostings
struct
{
next
func
()
bool
seek
func
(
uint
32
)
bool
value
func
()
uint
32
seek
func
(
uint
64
)
bool
value
func
()
uint
64
err
func
()
error
}
func
(
m
*
mockPostings
)
Next
()
bool
{
return
m
.
next
()
}
func
(
m
*
mockPostings
)
Seek
(
v
uint
32
)
bool
{
return
m
.
seek
(
v
)
}
func
(
m
*
mockPostings
)
Value
()
uint
32
{
return
m
.
value
()
}
func
(
m
*
mockPostings
)
Seek
(
v
uint
64
)
bool
{
return
m
.
seek
(
v
)
}
func
(
m
*
mockPostings
)
Value
()
uint
64
{
return
m
.
value
()
}
func
(
m
*
mockPostings
)
Err
()
error
{
return
m
.
err
()
}
func
expandPostings
(
p
Postings
)
(
res
[]
uint
32
,
err
error
)
{
func
expandPostings
(
p
Postings
)
(
res
[]
uint
64
,
err
error
)
{
for
p
.
Next
()
{
res
=
append
(
res
,
p
.
At
())
}
...
...
@@ -42,27 +42,27 @@ func expandPostings(p Postings) (res []uint32, err error) {
func
TestIntersect
(
t
*
testing
.
T
)
{
var
cases
=
[]
struct
{
a
,
b
[]
uint
32
res
[]
uint
32
a
,
b
[]
uint
64
res
[]
uint
64
}{
{
a
:
[]
uint
32
{
1
,
2
,
3
,
4
,
5
},
b
:
[]
uint
32
{
6
,
7
,
8
,
9
,
10
},
a
:
[]
uint
64
{
1
,
2
,
3
,
4
,
5
},
b
:
[]
uint
64
{
6
,
7
,
8
,
9
,
10
},
res
:
nil
,
},
{
a
:
[]
uint
32
{
1
,
2
,
3
,
4
,
5
},
b
:
[]
uint
32
{
4
,
5
,
6
,
7
,
8
},
res
:
[]
uint
32
{
4
,
5
},
a
:
[]
uint
64
{
1
,
2
,
3
,
4
,
5
},
b
:
[]
uint
64
{
4
,
5
,
6
,
7
,
8
},
res
:
[]
uint
64
{
4
,
5
},
},
{
a
:
[]
uint
32
{
1
,
2
,
3
,
4
,
9
,
10
},
b
:
[]
uint
32
{
1
,
4
,
5
,
6
,
7
,
8
,
10
,
11
},
res
:
[]
uint
32
{
1
,
4
,
10
},
a
:
[]
uint
64
{
1
,
2
,
3
,
4
,
9
,
10
},
b
:
[]
uint
64
{
1
,
4
,
5
,
6
,
7
,
8
,
10
,
11
},
res
:
[]
uint
64
{
1
,
4
,
10
},
},
{
a
:
[]
uint
32
{
1
},
b
:
[]
uint
32
{
0
,
1
},
res
:
[]
uint
32
{
1
},
a
:
[]
uint
64
{
1
},
b
:
[]
uint
64
{
0
,
1
},
res
:
[]
uint
64
{
1
},
},
}
...
...
@@ -78,29 +78,29 @@ func TestIntersect(t *testing.T) {
func
TestMultiIntersect
(
t
*
testing
.
T
)
{
var
cases
=
[]
struct
{
p
[][]
uint
32
res
[]
uint
32
p
[][]
uint
64
res
[]
uint
64
}{
{
p
:
[][]
uint
32
{
p
:
[][]
uint
64
{
{
1
,
2
,
3
,
4
,
5
,
6
,
1000
,
1001
},
{
2
,
4
,
5
,
6
,
7
,
8
,
999
,
1001
},
{
1
,
2
,
5
,
6
,
7
,
8
,
1001
,
1200
},
},
res
:
[]
uint
32
{
2
,
5
,
6
,
1001
},
res
:
[]
uint
64
{
2
,
5
,
6
,
1001
},
},
// One of the reproduceable cases for:
// https://github.com/prometheus/prometheus/issues/2616
// The initialisation of intersectPostings was moving the iterator forward
// prematurely making us miss some postings.
{
p
:
[][]
uint
32
{
p
:
[][]
uint
64
{
{
1
,
2
},
{
1
,
2
},
{
1
,
2
},
{
2
},
},
res
:
[]
uint
32
{
2
},
res
:
[]
uint
64
{
2
},
},
}
...
...
@@ -118,22 +118,22 @@ func TestMultiIntersect(t *testing.T) {
}
func
BenchmarkIntersect
(
t
*
testing
.
B
)
{
var
a
,
b
,
c
,
d
[]
uint
32
var
a
,
b
,
c
,
d
[]
uint
64
for
i
:=
0
;
i
<
10000000
;
i
+=
2
{
a
=
append
(
a
,
uint
32
(
i
))
a
=
append
(
a
,
uint
64
(
i
))
}
for
i
:=
5000000
;
i
<
5000100
;
i
+=
4
{
b
=
append
(
b
,
uint
32
(
i
))
b
=
append
(
b
,
uint
64
(
i
))
}
for
i
:=
5090000
;
i
<
5090600
;
i
+=
4
{
b
=
append
(
b
,
uint
32
(
i
))
b
=
append
(
b
,
uint
64
(
i
))
}
for
i
:=
4990000
;
i
<
5100000
;
i
++
{
c
=
append
(
c
,
uint
32
(
i
))
c
=
append
(
c
,
uint
64
(
i
))
}
for
i
:=
4000000
;
i
<
6000000
;
i
++
{
d
=
append
(
d
,
uint
32
(
i
))
d
=
append
(
d
,
uint
64
(
i
))
}
i1
:=
newListPostings
(
a
)
...
...
@@ -152,14 +152,14 @@ func BenchmarkIntersect(t *testing.B) {
func
TestMultiMerge
(
t
*
testing
.
T
)
{
var
cases
=
[]
struct
{
a
,
b
,
c
[]
uint
32
res
[]
uint
32
a
,
b
,
c
[]
uint
64
res
[]
uint
64
}{
{
a
:
[]
uint
32
{
1
,
2
,
3
,
4
,
5
,
6
,
1000
,
1001
},
b
:
[]
uint
32
{
2
,
4
,
5
,
6
,
7
,
8
,
999
,
1001
},
c
:
[]
uint
32
{
1
,
2
,
5
,
6
,
7
,
8
,
1001
,
1200
},
res
:
[]
uint
32
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
999
,
1000
,
1001
,
1200
},
a
:
[]
uint
64
{
1
,
2
,
3
,
4
,
5
,
6
,
1000
,
1001
},
b
:
[]
uint
64
{
2
,
4
,
5
,
6
,
7
,
8
,
999
,
1001
},
c
:
[]
uint
64
{
1
,
2
,
5
,
6
,
7
,
8
,
1001
,
1200
},
res
:
[]
uint
64
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
999
,
1000
,
1001
,
1200
},
},
}
...
...
@@ -176,23 +176,23 @@ func TestMultiMerge(t *testing.T) {
func
TestMergedPostings
(
t
*
testing
.
T
)
{
var
cases
=
[]
struct
{
a
,
b
[]
uint
32
res
[]
uint
32
a
,
b
[]
uint
64
res
[]
uint
64
}{
{
a
:
[]
uint
32
{
1
,
2
,
3
,
4
,
5
},
b
:
[]
uint
32
{
6
,
7
,
8
,
9
,
10
},
res
:
[]
uint
32
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
},
a
:
[]
uint
64
{
1
,
2
,
3
,
4
,
5
},
b
:
[]
uint
64
{
6
,
7
,
8
,
9
,
10
},
res
:
[]
uint
64
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
},
},
{
a
:
[]
uint
32
{
1
,
2
,
3
,
4
,
5
},
b
:
[]
uint
32
{
4
,
5
,
6
,
7
,
8
},
res
:
[]
uint
32
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
},
a
:
[]
uint
64
{
1
,
2
,
3
,
4
,
5
},
b
:
[]
uint
64
{
4
,
5
,
6
,
7
,
8
},
res
:
[]
uint
64
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
},
},
{
a
:
[]
uint
32
{
1
,
2
,
3
,
4
,
9
,
10
},
b
:
[]
uint
32
{
1
,
4
,
5
,
6
,
7
,
8
,
10
,
11
},
res
:
[]
uint
32
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
},
a
:
[]
uint
64
{
1
,
2
,
3
,
4
,
9
,
10
},
b
:
[]
uint
64
{
1
,
4
,
5
,
6
,
7
,
8
,
10
,
11
},
res
:
[]
uint
64
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
},
},
}
...
...
@@ -209,43 +209,43 @@ func TestMergedPostings(t *testing.T) {
func
TestMergedPostingsSeek
(
t
*
testing
.
T
)
{
var
cases
=
[]
struct
{
a
,
b
[]
uint
32
a
,
b
[]
uint
64
seek
uint
32
seek
uint
64
success
bool
res
[]
uint
32
res
[]
uint
64
}{
{
a
:
[]
uint
32
{
2
,
3
,
4
,
5
},
b
:
[]
uint
32
{
6
,
7
,
8
,
9
,
10
},
a
:
[]
uint
64
{
2
,
3
,
4
,
5
},
b
:
[]
uint
64
{
6
,
7
,
8
,
9
,
10
},
seek
:
1
,
success
:
true
,
res
:
[]
uint
32
{
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
},
res
:
[]
uint
64
{
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
},
},
{
a
:
[]
uint
32
{
1
,
2
,
3
,
4
,
5
},
b
:
[]
uint
32
{
6
,
7
,
8
,
9
,
10
},
a
:
[]
uint
64
{
1
,
2
,
3
,
4
,
5
},
b
:
[]
uint
64
{
6
,
7
,
8
,
9
,
10
},
seek
:
2
,
success
:
true
,
res
:
[]
uint
32
{
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
},
res
:
[]
uint
64
{
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
},
},
{
a
:
[]
uint
32
{
1
,
2
,
3
,
4
,
5
},
b
:
[]
uint
32
{
4
,
5
,
6
,
7
,
8
},
a
:
[]
uint
64
{
1
,
2
,
3
,
4
,
5
},
b
:
[]
uint
64
{
4
,
5
,
6
,
7
,
8
},
seek
:
9
,
success
:
false
,
res
:
nil
,
},
{
a
:
[]
uint
32
{
1
,
2
,
3
,
4
,
9
,
10
},
b
:
[]
uint
32
{
1
,
4
,
5
,
6
,
7
,
8
,
10
,
11
},
a
:
[]
uint
64
{
1
,
2
,
3
,
4
,
9
,
10
},
b
:
[]
uint
64
{
1
,
4
,
5
,
6
,
7
,
8
,
10
,
11
},
seek
:
10
,
success
:
true
,
res
:
[]
uint
32
{
10
,
11
},
res
:
[]
uint
64
{
10
,
11
},
},
}
...
...
@@ -263,7 +263,7 @@ func TestMergedPostingsSeek(t *testing.T) {
lst
,
err
:=
expandPostings
(
p
)
require
.
NoError
(
t
,
err
)
lst
=
append
([]
uint
32
{
start
},
lst
...
)
lst
=
append
([]
uint
64
{
start
},
lst
...
)
require
.
Equal
(
t
,
c
.
res
,
lst
)
}
}
...
...
@@ -290,7 +290,7 @@ func TestBigEndian(t *testing.T) {
bep
:=
newBigEndianPostings
(
beLst
)
for
i
:=
0
;
i
<
num
;
i
++
{
require
.
True
(
t
,
bep
.
Next
())
require
.
Equal
(
t
,
ls
[
i
]
,
bep
.
At
())
require
.
Equal
(
t
,
uint64
(
ls
[
i
])
,
bep
.
At
())
}
require
.
False
(
t
,
bep
.
Next
())
...
...
@@ -338,8 +338,8 @@ func TestBigEndian(t *testing.T) {
bep
:=
newBigEndianPostings
(
beLst
)
for
_
,
v
:=
range
table
{
require
.
Equal
(
t
,
v
.
found
,
bep
.
Seek
(
v
.
seek
))
require
.
Equal
(
t
,
v
.
val
,
bep
.
At
())
require
.
Equal
(
t
,
v
.
found
,
bep
.
Seek
(
uint64
(
v
.
seek
)
))
require
.
Equal
(
t
,
uint64
(
v
.
val
)
,
bep
.
At
())
require
.
Nil
(
t
,
bep
.
Err
())
}
})
...
...
@@ -348,16 +348,16 @@ func TestBigEndian(t *testing.T) {
func
TestIntersectWithMerge
(
t
*
testing
.
T
)
{
// One of the reproduceable cases for:
// https://github.com/prometheus/prometheus/issues/2616
a
:=
newListPostings
([]
uint
32
{
21
,
22
,
23
,
24
,
25
,
30
})
a
:=
newListPostings
([]
uint
64
{
21
,
22
,
23
,
24
,
25
,
30
})
b
:=
newMergedPostings
(
newListPostings
([]
uint
32
{
10
,
20
,
30
}),
newListPostings
([]
uint
32
{
15
,
26
,
30
}),
newListPostings
([]
uint
64
{
10
,
20
,
30
}),
newListPostings
([]
uint
64
{
15
,
26
,
30
}),
)
p
:=
Intersect
(
a
,
b
)
res
,
err
:=
expandPostings
(
p
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
[]
uint
32
{
30
},
res
)
require
.
Equal
(
t
,
[]
uint
64
{
30
},
res
)
}
querier_test.go
浏览文件 @
1ddedf2b
...
...
@@ -228,7 +228,7 @@ func createIdxChkReaders(tc []struct {
return
labels
.
Compare
(
labels
.
FromMap
(
tc
[
i
]
.
lset
),
labels
.
FromMap
(
tc
[
i
]
.
lset
))
<
0
})
postings
:=
&
memPostings
{
m
:
make
(
map
[
term
][]
uint
32
,
512
)}
postings
:=
&
memPostings
{
m
:
make
(
map
[
term
][]
uint
64
,
512
)}
chkReader
:=
mockChunkReader
(
make
(
map
[
uint64
]
chunks
.
Chunk
))
lblIdx
:=
make
(
map
[
string
]
stringset
)
mi
:=
newMockIndex
()
...
...
@@ -255,11 +255,11 @@ func createIdxChkReaders(tc []struct {
}
ls
:=
labels
.
FromMap
(
s
.
lset
)
mi
.
AddSeries
(
uint
32
(
i
),
ls
,
metas
...
)
mi
.
AddSeries
(
uint
64
(
i
),
ls
,
metas
...
)
postings
.
add
(
uint
32
(
i
),
term
{})
postings
.
add
(
uint
64
(
i
),
term
{})
for
_
,
l
:=
range
ls
{
postings
.
add
(
uint
32
(
i
),
term
{
l
.
Name
,
l
.
Value
})
postings
.
add
(
uint
64
(
i
),
term
{
l
.
Name
,
l
.
Value
})
vs
,
present
:=
lblIdx
[
l
.
Name
]
if
!
present
{
...
...
@@ -555,7 +555,7 @@ func TestBlockQuerierDelete(t *testing.T) {
},
},
tombstones
:
newTombstoneReader
(
map
[
uint
32
]
Intervals
{
map
[
uint
64
]
Intervals
{
1
:
Intervals
{{
1
,
3
}},
2
:
Intervals
{{
1
,
3
},
{
6
,
10
}},
3
:
Intervals
{{
6
,
10
}},
...
...
@@ -663,13 +663,13 @@ func TestBaseChunkSeries(t *testing.T) {
lset
labels
.
Labels
chunks
[]
ChunkMeta
ref
uint
32
ref
uint
64
}
cases
:=
[]
struct
{
series
[]
refdSeries
// Postings should be in the sorted order of the the series
postings
[]
uint
32
postings
[]
uint
64
expIdxs
[]
int
}{
...
...
@@ -703,7 +703,7 @@ func TestBaseChunkSeries(t *testing.T) {
ref
:
108
,
},
},
postings
:
[]
uint
32
{
12
,
10
,
108
},
postings
:
[]
uint
64
{
12
,
10
,
108
},
expIdxs
:
[]
int
{
0
,
1
,
3
},
},
...
...
@@ -722,7 +722,7 @@ func TestBaseChunkSeries(t *testing.T) {
ref
:
1
,
},
},
postings
:
[]
uint
32
{},
postings
:
[]
uint
64
{},
expIdxs
:
[]
int
{},
},
...
...
tombstones.go
浏览文件 @
1ddedf2b
...
...
@@ -33,6 +33,11 @@ const (
tombstoneFormatV1
=
1
)
// TombstoneReader is the iterator over tombstones.
type
TombstoneReader
interface
{
Get
(
ref
uint64
)
Intervals
}
func
writeTombstoneFile
(
dir
string
,
tr
tombstoneReader
)
error
{
path
:=
filepath
.
Join
(
dir
,
tombstoneFilename
)
tmp
:=
path
+
".tmp"
...
...
@@ -59,7 +64,7 @@ func writeTombstoneFile(dir string, tr tombstoneReader) error {
for
k
,
v
:=
range
tr
{
for
_
,
itv
:=
range
v
{
buf
.
reset
()
buf
.
putUvarint
32
(
k
)
buf
.
putUvarint
64
(
k
)
buf
.
putVarint64
(
itv
.
Mint
)
buf
.
putVarint64
(
itv
.
Maxt
)
...
...
@@ -81,15 +86,10 @@ func writeTombstoneFile(dir string, tr tombstoneReader) error {
// Stone holds the information on the posting and time-range
// that is deleted.
type
Stone
struct
{
ref
uint
32
ref
uint
64
intervals
Intervals
}
// TombstoneReader is the iterator over tombstones.
type
TombstoneReader
interface
{
Get
(
ref
uint32
)
Intervals
}
func
readTombstones
(
dir
string
)
(
tombstoneReader
,
error
)
{
b
,
err
:=
ioutil
.
ReadFile
(
filepath
.
Join
(
dir
,
tombstoneFilename
))
if
err
!=
nil
{
...
...
@@ -123,7 +123,7 @@ func readTombstones(dir string) (tombstoneReader, error) {
stonesMap
:=
newEmptyTombstoneReader
()
for
d
.
len
()
>
0
{
k
:=
d
.
uvarint
32
()
k
:=
d
.
uvarint
64
()
mint
:=
d
.
varint64
()
maxt
:=
d
.
varint64
()
if
d
.
err
()
!=
nil
{
...
...
@@ -136,21 +136,21 @@ func readTombstones(dir string) (tombstoneReader, error) {
return
newTombstoneReader
(
stonesMap
),
nil
}
type
tombstoneReader
map
[
uint
32
]
Intervals
type
tombstoneReader
map
[
uint
64
]
Intervals
func
newTombstoneReader
(
ts
map
[
uint
32
]
Intervals
)
tombstoneReader
{
func
newTombstoneReader
(
ts
map
[
uint
64
]
Intervals
)
tombstoneReader
{
return
tombstoneReader
(
ts
)
}
func
newEmptyTombstoneReader
()
tombstoneReader
{
return
tombstoneReader
(
make
(
map
[
uint
32
]
Intervals
))
return
tombstoneReader
(
make
(
map
[
uint
64
]
Intervals
))
}
func
(
t
tombstoneReader
)
Get
(
ref
uint
32
)
Intervals
{
func
(
t
tombstoneReader
)
Get
(
ref
uint
64
)
Intervals
{
return
t
[
ref
]
}
func
(
t
tombstoneReader
)
add
(
ref
uint
32
,
itv
Interval
)
{
func
(
t
tombstoneReader
)
add
(
ref
uint
64
,
itv
Interval
)
{
t
[
ref
]
=
t
[
ref
]
.
add
(
itv
)
}
...
...
tombstones_test.go
浏览文件 @
1ddedf2b
...
...
@@ -27,12 +27,12 @@ func TestWriteAndReadbackTombStones(t *testing.T) {
tmpdir
,
_
:=
ioutil
.
TempDir
(
""
,
"test"
)
defer
os
.
RemoveAll
(
tmpdir
)
ref
:=
uint
32
(
0
)
ref
:=
uint
64
(
0
)
stones
:=
make
(
map
[
uint
32
]
Intervals
)
stones
:=
make
(
map
[
uint
64
]
Intervals
)
// Generate the tombstones.
for
i
:=
0
;
i
<
100
;
i
++
{
ref
+=
uint
32
(
rand
.
Int31n
(
10
))
+
1
ref
+=
uint
64
(
rand
.
Int31n
(
10
))
+
1
numRanges
:=
rand
.
Intn
(
5
)
+
1
dranges
:=
make
(
Intervals
,
0
,
numRanges
)
mint
:=
rand
.
Int63n
(
time
.
Now
()
.
UnixNano
())
...
...
wal.go
浏览文件 @
1ddedf2b
...
...
@@ -238,11 +238,11 @@ WRLoop:
activeSeries
:=
make
([]
RefSeries
,
0
,
len
(
series
))
for
_
,
s
:=
range
series
{
if
!
p
.
Seek
(
uint32
(
s
.
Ref
)
)
{
if
!
p
.
Seek
(
s
.
Ref
)
{
break
WRLoop
}
if
p
.
At
()
==
uint32
(
s
.
Ref
)
{
if
p
.
At
()
==
s
.
Ref
{
activeSeries
=
append
(
activeSeries
,
s
)
}
}
...
...
@@ -596,11 +596,11 @@ func encodeSeries(buf []byte, series []RefSeries) []byte {
buf
=
append
(
buf
,
b
[
:
8
]
...
)
for
_
,
s
:=
range
series
{
n
:=
binary
.
PutVarint
(
b
,
int64
(
s
.
Ref
)
-
int64
(
first
.
Ref
)
)
buf
=
append
(
buf
,
b
[
:
n
]
...
)
binary
.
BigEndian
.
PutUint64
(
b
,
s
.
Ref
)
buf
=
append
(
buf
,
b
[
:
8
]
...
)
lset
:=
s
.
Labels
n
=
binary
.
PutUvarint
(
b
,
uint64
(
len
(
lset
)))
n
:
=
binary
.
PutUvarint
(
b
,
uint64
(
len
(
lset
)))
buf
=
append
(
buf
,
b
[
:
n
]
...
)
for
_
,
l
:=
range
lset
{
...
...
@@ -662,7 +662,7 @@ func (w *SegmentWAL) encodeDeletes(stones []Stone) error {
for
_
,
s
:=
range
stones
{
for
_
,
itv
:=
range
s
.
intervals
{
eb
.
reset
()
eb
.
putUvarint
32
(
s
.
ref
)
eb
.
putUvarint
64
(
s
.
ref
)
eb
.
putVarint64
(
itv
.
Mint
)
eb
.
putVarint64
(
itv
.
Maxt
)
buf
=
append
(
buf
,
eb
.
get
()
...
)
...
...
@@ -913,18 +913,16 @@ func (r *walReader) decodeSeries(flag byte, b []byte) ([]RefSeries, error) {
return
nil
,
errors
.
Wrap
(
errInvalidSize
,
"header length"
)
}
baseRef
:=
binary
.
BigEndian
.
Uint64
(
b
)
b
=
b
[
8
:
]
for
len
(
b
)
>
0
{
var
ser
RefSeries
// TODO: Check again.
dref
,
n
:=
binary
.
Varint
(
b
)
if
n
<
1
{
return
nil
,
errors
.
Wrap
(
errInvalidSize
,
"series ref delta"
)
if
len
(
b
)
<
8
{
return
nil
,
errors
.
Wrap
(
errInvalidSize
,
"series ref"
)
}
b
=
b
[
n
:
]
ser
.
Ref
=
uint64
(
int64
(
baseRef
)
+
dref
)
ser
.
Ref
=
binary
.
BigEndian
.
Uint64
(
b
)
b
=
b
[
8
:
]
l
,
n
:=
binary
.
Uvarint
(
b
)
if
n
<
1
{
...
...
@@ -1002,7 +1000,7 @@ func (r *walReader) decodeDeletes(flag byte, b []byte) ([]Stone, error) {
for
db
.
len
()
>
0
{
var
s
Stone
s
.
ref
=
db
.
uvarint
32
()
s
.
ref
=
db
.
uvarint
64
()
s
.
intervals
=
Intervals
{{
db
.
varint64
(),
db
.
varint64
()}}
if
db
.
err
()
!=
nil
{
return
nil
,
db
.
err
()
...
...
wal_test.go
浏览文件 @
1ddedf2b
...
...
@@ -219,7 +219,7 @@ func TestSegmentWAL_Log_Restore(t *testing.T) {
for
j
:=
0
;
j
<
i
*
20
;
j
++
{
ts
:=
rand
.
Int63
()
stones
=
append
(
stones
,
Stone
{
rand
.
Uint
32
(),
Intervals
{{
ts
,
ts
+
rand
.
Int63n
(
10000
)}}})
stones
=
append
(
stones
,
Stone
{
rand
.
Uint
64
(),
Intervals
{{
ts
,
ts
+
rand
.
Int63n
(
10000
)}}})
}
lbls
:=
series
[
i
:
i
+
stepSize
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录