Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doodoocoder
prometheus
提交
cdfb604d
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,发现更多精彩内容 >>
提交
cdfb604d
编写于
4月 28, 2017
作者:
F
Fabian Reinartz
提交者:
GitHub
4月 28, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #64 from prometheus/dbref
Fix and test ref handling in DB appender
上级
5b3cb11f
54a7b98c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
33 addition
and
2 deletion
+33
-2
db.go
db.go
+2
-2
db_test.go
db_test.go
+31
-0
未找到文件。
db.go
浏览文件 @
cdfb604d
...
@@ -521,7 +521,7 @@ func (a *dbAppender) Add(lset labels.Labels, t int64, v float64) (uint64, error)
...
@@ -521,7 +521,7 @@ func (a *dbAppender) Add(lset labels.Labels, t int64, v float64) (uint64, error)
}
}
a
.
samples
++
a
.
samples
++
// Store last byte of sequence number in 3rd byte of reference.
// Store last byte of sequence number in 3rd byte of reference.
return
ref
|
(
uint64
(
h
.
meta
.
Sequence
^
0xff
)
<<
40
),
nil
return
ref
|
(
uint64
(
h
.
meta
.
Sequence
&
0xff
)
<<
40
),
nil
}
}
func
(
a
*
dbAppender
)
AddFast
(
ref
uint64
,
t
int64
,
v
float64
)
error
{
func
(
a
*
dbAppender
)
AddFast
(
ref
uint64
,
t
int64
,
v
float64
)
error
{
...
@@ -534,7 +534,7 @@ func (a *dbAppender) AddFast(ref uint64, t int64, v float64) error {
...
@@ -534,7 +534,7 @@ func (a *dbAppender) AddFast(ref uint64, t int64, v float64) error {
return
err
return
err
}
}
// If the last byte of the sequence does not add up, the reference is not valid.
// If the last byte of the sequence does not add up, the reference is not valid.
if
uint64
(
h
.
meta
.
Sequence
^
0xff
)
!=
gen
{
if
uint64
(
h
.
meta
.
Sequence
&
0xff
)
!=
gen
{
return
ErrNotFound
return
ErrNotFound
}
}
if
err
:=
h
.
app
.
AddFast
(
ref
,
t
,
v
);
err
!=
nil
{
if
err
:=
h
.
app
.
AddFast
(
ref
,
t
,
v
);
err
!=
nil
{
...
...
db_test.go
浏览文件 @
cdfb604d
...
@@ -98,3 +98,34 @@ func TestDataNotAvailableAfterRollback(t *testing.T) {
...
@@ -98,3 +98,34 @@ func TestDataNotAvailableAfterRollback(t *testing.T) {
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
seriesSet
,
map
[
string
][]
sample
{})
require
.
Equal
(
t
,
seriesSet
,
map
[
string
][]
sample
{})
}
}
func
TestDBAppenderAddRef
(
t
*
testing
.
T
)
{
tmpdir
,
_
:=
ioutil
.
TempDir
(
""
,
"test"
)
defer
os
.
RemoveAll
(
tmpdir
)
db
,
err
:=
Open
(
tmpdir
,
nil
,
nil
,
nil
)
require
.
NoError
(
t
,
err
)
defer
db
.
Close
()
app
:=
db
.
Appender
()
defer
app
.
Rollback
()
ref
,
err
:=
app
.
Add
(
labels
.
FromStrings
(
"a"
,
"b"
),
0
,
0
)
require
.
NoError
(
t
,
err
)
// Head sequence number should be in 3rd MSB and be greater than 0.
gen
:=
(
ref
<<
16
)
>>
56
require
.
True
(
t
,
gen
>
1
)
// Reference must be valid to add another sample.
err
=
app
.
AddFast
(
ref
,
1
,
1
)
require
.
NoError
(
t
,
err
)
// AddFast for the same timestamp must fail if the generation in the reference
// doesn't add up.
refBad
:=
ref
|
((
gen
+
1
)
<<
4
)
err
=
app
.
AddFast
(
refBad
,
1
,
1
)
require
.
Error
(
t
,
err
)
require
.
Equal
(
t
,
2
,
app
.
(
*
dbAppender
)
.
samples
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录