Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doodoocoder
prometheus
提交
df96d97d
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,发现更多精彩内容 >>
提交
df96d97d
编写于
4月 24, 2017
作者:
F
Fabian Reinartz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move chunk checksum
上级
db4272b8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
33 addition
and
22 deletion
+33
-22
chunks.go
chunks.go
+6
-18
index.go
index.go
+18
-1
index_test.go
index_test.go
+9
-3
未找到文件。
chunks.go
浏览文件 @
df96d97d
...
...
@@ -17,8 +17,6 @@ import (
"bufio"
"encoding/binary"
"fmt"
"hash"
"hash/crc32"
"io"
"os"
...
...
@@ -63,7 +61,6 @@ type chunkWriter struct {
files
[]
*
os
.
File
wbuf
*
bufio
.
Writer
n
int64
crc32
hash
.
Hash
segmentSize
int64
}
...
...
@@ -85,7 +82,6 @@ func newChunkWriter(dir string) (*chunkWriter, error) {
cw
:=
&
chunkWriter
{
dirFile
:
dirFile
,
n
:
0
,
crc32
:
crc32
.
New
(
crc32
.
MakeTable
(
crc32
.
Castagnoli
)),
segmentSize
:
defaultChunkSegmentSize
,
}
return
cw
,
nil
...
...
@@ -165,8 +161,8 @@ func (w *chunkWriter) cut() error {
return
nil
}
func
(
w
*
chunkWriter
)
write
(
wr
io
.
Writer
,
b
[]
byte
)
error
{
n
,
err
:=
w
r
.
Write
(
b
)
func
(
w
*
chunkWriter
)
write
(
b
[]
byte
)
error
{
n
,
err
:=
w
.
wbuf
.
Write
(
b
)
w
.
n
+=
int64
(
n
)
return
err
}
...
...
@@ -187,14 +183,10 @@ func (w *chunkWriter) WriteChunks(chks ...*ChunkMeta) error {
}
}
// Write chunks sequentially and set the reference field in the ChunkMeta.
w
.
crc32
.
Reset
()
wr
:=
io
.
MultiWriter
(
w
.
crc32
,
w
.
wbuf
)
b
:=
make
([]
byte
,
binary
.
MaxVarintLen32
)
n
:=
binary
.
PutUvarint
(
b
,
uint64
(
len
(
chks
)))
if
err
:=
w
.
write
(
wr
,
b
[
:
n
]);
err
!=
nil
{
if
err
:=
w
.
write
(
b
[
:
n
]);
err
!=
nil
{
return
err
}
seq
:=
uint64
(
w
.
seq
())
<<
32
...
...
@@ -204,21 +196,17 @@ func (w *chunkWriter) WriteChunks(chks ...*ChunkMeta) error {
n
=
binary
.
PutUvarint
(
b
,
uint64
(
len
(
chk
.
Chunk
.
Bytes
())))
if
err
:=
w
.
write
(
wr
,
b
[
:
n
]);
err
!=
nil
{
if
err
:=
w
.
write
(
b
[
:
n
]);
err
!=
nil
{
return
err
}
if
err
:=
w
.
write
(
wr
,
[]
byte
{
byte
(
chk
.
Chunk
.
Encoding
())});
err
!=
nil
{
if
err
:=
w
.
write
([]
byte
{
byte
(
chk
.
Chunk
.
Encoding
())});
err
!=
nil
{
return
err
}
if
err
:=
w
.
write
(
wr
,
chk
.
Chunk
.
Bytes
());
err
!=
nil
{
if
err
:=
w
.
write
(
chk
.
Chunk
.
Bytes
());
err
!=
nil
{
return
err
}
chk
.
Chunk
=
nil
}
if
err
:=
w
.
write
(
w
.
wbuf
,
w
.
crc32
.
Sum
(
nil
));
err
!=
nil
{
return
err
}
return
nil
}
...
...
index.go
浏览文件 @
df96d97d
...
...
@@ -228,7 +228,8 @@ func (w *indexWriter) writeSeries() error {
for
_
,
s
:=
range
series
{
// Write label set symbol references.
s
.
offset
=
base
+
uint32
(
len
(
w
.
b
))
start
:=
len
(
w
.
b
)
s
.
offset
=
base
+
uint32
(
start
)
n
:=
binary
.
PutUvarint
(
buf
,
uint64
(
len
(
s
.
labels
)))
w
.
b
=
append
(
w
.
b
,
buf
[
:
n
]
...
)
...
...
@@ -253,6 +254,22 @@ func (w *indexWriter) writeSeries() error {
n
=
binary
.
PutUvarint
(
buf
,
uint64
(
c
.
Ref
))
w
.
b
=
append
(
w
.
b
,
buf
[
:
n
]
...
)
}
// Write checksum over series index entry and all its chunk data.
w
.
crc32
.
Reset
()
w
.
crc32
.
Write
(
w
.
b
[
start
:
])
for
_
,
c
:=
range
s
.
chunks
{
fmt
.
Println
(
c
)
if
_
,
err
:=
w
.
crc32
.
Write
([]
byte
{
byte
(
c
.
Chunk
.
Encoding
())});
err
!=
nil
{
return
err
}
if
_
,
err
:=
w
.
crc32
.
Write
(
c
.
Chunk
.
Bytes
());
err
!=
nil
{
return
err
}
}
w
.
b
=
append
(
w
.
b
,
w
.
crc32
.
Sum
(
nil
)
...
)
}
return
w
.
section
(
len
(
w
.
b
),
flagStd
,
func
(
wr
io
.
Writer
)
error
{
...
...
index_test.go
浏览文件 @
df96d97d
...
...
@@ -22,6 +22,7 @@ import (
"testing"
"github.com/pkg/errors"
"github.com/prometheus/tsdb/chunks"
"github.com/prometheus/tsdb/labels"
"github.com/stretchr/testify/require"
)
...
...
@@ -50,10 +51,14 @@ func (m mockIndex) AddSeries(ref uint32, l labels.Labels, chunks ...*ChunkMeta)
return
errors
.
Errorf
(
"series with reference %d already added"
,
ref
)
}
m
.
series
[
ref
]
=
series
{
l
:
l
,
chunks
:
chunks
,
s
:=
series
{
l
:
l
}
// Actual chunk data is not stored in the index.
for
_
,
c
:=
range
chunks
{
cc
:=
*
c
cc
.
Chunk
=
nil
s
.
chunks
=
append
(
s
.
chunks
,
&
cc
)
}
m
.
series
[
ref
]
=
s
return
nil
}
...
...
@@ -241,6 +246,7 @@ func TestPersistence_index_e2e(t *testing.T) {
MinTime
:
int64
(
j
*
10000
),
MaxTime
:
int64
((
j
+
1
)
*
10000
),
Ref
:
rand
.
Uint64
(),
Chunk
:
chunks
.
NewXORChunk
(),
})
}
input
=
append
(
input
,
&
indexWriterSeries
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录