Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doodoocoder
prometheus
提交
d3edfb55
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,发现更多精彩内容 >>
提交
d3edfb55
编写于
3月 08, 2017
作者:
F
Fabian Reinartz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Test multiple full write/restore cylcles in WAL
上级
ca1bc920
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
73 addition
and
31 deletion
+73
-31
wal.go
wal.go
+4
-0
wal_test.go
wal_test.go
+69
-31
未找到文件。
wal.go
浏览文件 @
d3edfb55
...
...
@@ -299,6 +299,8 @@ func (w *WAL) entry(et WALEntryType, flag byte, buf []byte) error {
sz
=
int64
(
6
+
4
+
len
(
buf
))
newsz
=
w
.
curN
+
sz
)
// XXX(fabxc): this currently cuts a new file whenever the WAL was newly opened.
// Probably fine in general but may yield a lot of short files in some cases.
if
w
.
cur
==
nil
||
w
.
curN
>
w
.
segmentSize
||
newsz
>
w
.
segmentSize
&&
sz
<=
w
.
segmentSize
{
if
err
:=
w
.
cut
();
err
!=
nil
{
return
err
...
...
@@ -431,6 +433,8 @@ func NewWALReader(rs ...io.ReadCloser) *WALReader {
}
// At returns the last decoded entry of labels or samples.
// The returned slices are only valid until the next call to Next(). Their elements
// have to be copied to preserve them.
func
(
r
*
WALReader
)
At
()
([]
labels
.
Labels
,
[]
refdSample
)
{
return
r
.
labels
,
r
.
samples
}
...
...
wal_test.go
浏览文件 @
d3edfb55
...
...
@@ -8,6 +8,8 @@ import (
"os"
"testing"
"github.com/fabxc/tsdb/labels"
"github.com/coreos/etcd/pkg/fileutil"
"github.com/stretchr/testify/require"
)
...
...
@@ -117,52 +119,88 @@ func TestWAL_cut(t *testing.T) {
// Symmetrical test of reading and writing to the WAL via its main interface.
func
TestWAL_Log_Restore
(
t
*
testing
.
T
)
{
const
(
numMetrics
=
5000
iterations
=
5
stepSize
=
100
)
// Generate testing data. It does not make semantical sense but
// for the purpose of this test.
series
,
err
:=
readPrometheusLabels
(
"testdata/20k.series"
,
10000
)
series
,
err
:=
readPrometheusLabels
(
"testdata/20k.series"
,
numMetrics
)
require
.
NoError
(
t
,
err
)
var
samples
[]
refdSample
for
i
:=
0
;
i
<
200000
;
i
++
{
samples
=
append
(
samples
,
refdSample
{
ref
:
uint64
(
i
%
10000
),
t
:
int64
(
i
*
2
),
v
:
rand
.
Float64
(),
})
}
dir
,
err
:=
ioutil
.
TempDir
(
""
,
"test_wal_log_restore"
)
require
.
NoError
(
t
,
err
)
defer
os
.
RemoveAll
(
dir
)
w
,
err
:=
OpenWAL
(
dir
,
nil
,
0
)
require
.
NoError
(
t
,
err
)
var
(
recordedSeries
[][]
labels
.
Labels
recordedSamples
[][]
refdSample
)
var
totalSamples
int
// Set smaller segment size so we can actually write several files.
w
.
segmentSize
=
300
*
1000
// Open WAL a bunch of times, validate all previous data can be read,
// write more data to it, close it.
for
k
:=
0
;
k
<
numMetrics
;
k
+=
numMetrics
/
iterations
{
w
,
err
:=
OpenWAL
(
dir
,
nil
,
0
)
require
.
NoError
(
t
,
err
)
for
i
:=
0
;
i
<
len
(
series
);
i
+=
100
{
require
.
NoError
(
t
,
w
.
Log
(
series
[
i
:
i
+
100
],
samples
[
i
*
10
:
(
i
+
100
)
*
10
]))
}
// Set smaller segment size so we can actually write several files.
w
.
segmentSize
=
1000
*
1000
r
:=
w
.
Reader
()
var
(
resultSeries
[][]
labels
.
Labels
resultSamples
[][]
refdSample
)
for
r
.
Next
()
{
lsets
,
smpls
:=
r
.
At
()
if
len
(
lsets
)
>
0
{
clsets
:=
make
([]
labels
.
Labels
,
len
(
lsets
))
copy
(
clsets
,
lsets
)
resultSeries
=
append
(
resultSeries
,
clsets
)
}
if
len
(
smpls
)
>
0
{
csmpls
:=
make
([]
refdSample
,
len
(
smpls
))
copy
(
csmpls
,
smpls
)
resultSamples
=
append
(
resultSamples
,
csmpls
)
}
}
require
.
NoError
(
t
,
r
.
Err
())
require
.
NoError
(
t
,
w
.
Close
())
require
.
Equal
(
t
,
recordedSamples
,
resultSamples
)
require
.
Equal
(
t
,
recordedSeries
,
resultSeries
)
w
,
err
=
OpenWAL
(
dir
,
nil
,
0
)
r
:=
w
.
Reader
()
series
:=
series
[
k
:
k
+
(
numMetrics
/
iterations
)]
var
i
,
j
int
// Insert in batches and generate different amounts of samples for each.
for
i
:=
0
;
i
<
len
(
series
);
i
+=
stepSize
{
var
samples
[]
refdSample
for
r
.
Next
()
{
lsets
,
smpls
:=
r
.
At
()
for
j
:=
0
;
j
<
i
*
10
;
j
++
{
samples
=
append
(
samples
,
refdSample
{
ref
:
uint64
(
j
%
10000
),
t
:
int64
(
j
*
2
),
v
:
rand
.
Float64
(),
})
}
if
l
:=
len
(
lsets
);
l
>
0
{
require
.
Equal
(
t
,
series
[
i
:
i
+
l
],
lsets
)
i
+=
l
}
if
l
:=
len
(
smpls
);
l
>
0
{
require
.
Equal
(
t
,
samples
[
j
:
j
+
l
],
smpls
)
j
+=
l
lbls
:=
series
[
i
:
i
+
stepSize
]
require
.
NoError
(
t
,
w
.
Log
(
lbls
,
samples
))
if
len
(
lbls
)
>
0
{
recordedSeries
=
append
(
recordedSeries
,
lbls
)
}
if
len
(
samples
)
>
0
{
recordedSamples
=
append
(
recordedSamples
,
samples
)
totalSamples
+=
len
(
samples
)
}
}
require
.
NoError
(
t
,
w
.
Close
())
}
require
.
NoError
(
t
,
r
.
Err
())
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录