Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
f28ff0db
Unverified
Commit
f28ff0db
authored
Feb 16, 2021
by
acud
Committed by
GitHub
Feb 16, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tags: delete persisted tag (#1255)
parent
60facaea
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
3 deletions
+33
-3
tags.go
pkg/tags/tags.go
+15
-3
tags_test.go
pkg/tags/tags_test.go
+18
-0
No files found.
pkg/tags/tags.go
View file @
f28ff0db
...
...
@@ -35,7 +35,8 @@ import (
)
const
(
maxPage
=
1000
// hard limit of page size
maxPage
=
1000
// hard limit of page size
tagKeyPrefix
=
"tags_"
)
var
(
...
...
@@ -125,6 +126,13 @@ func (ts *Tags) Range(fn func(k, v interface{}) bool) {
func
(
ts
*
Tags
)
Delete
(
k
interface
{})
{
ts
.
tags
.
Delete
(
k
)
// k is a uint32, try to create the tag key and remove
// from statestore
if
uid
,
ok
:=
k
.
(
uint32
);
ok
&&
uid
!=
0
{
key
:=
tagKey
(
uid
)
_
=
ts
.
stateStore
.
Delete
(
key
)
}
}
func
(
ts
*
Tags
)
MarshalJSON
()
(
out
[]
byte
,
err
error
)
{
...
...
@@ -192,7 +200,7 @@ func (ts *Tags) ListAll(ctx context.Context, offset, limit int) (t []*Tag, err e
}
// and then from statestore
err
=
ts
.
stateStore
.
Iterate
(
"tags_"
,
func
(
key
,
value
[]
byte
)
(
stop
bool
,
err
error
)
{
err
=
ts
.
stateStore
.
Iterate
(
tagKeyPrefix
,
func
(
key
,
value
[]
byte
)
(
stop
bool
,
err
error
)
{
if
offset
>
0
{
offset
--
return
false
,
nil
...
...
@@ -239,7 +247,7 @@ func decodeTagValueFromStore(value []byte) (*Tag, error) {
// getTagFromStore get a given tag from the state store.
func
(
ts
*
Tags
)
getTagFromStore
(
uid
uint32
)
(
*
Tag
,
error
)
{
key
:=
"tags_"
+
strconv
.
Itoa
(
int
(
uid
)
)
key
:=
tagKey
(
uid
)
var
data
[]
byte
err
:=
ts
.
stateStore
.
Get
(
key
,
&
data
)
if
err
!=
nil
{
...
...
@@ -266,3 +274,7 @@ func (ts *Tags) Close() (err error) {
}
return
nil
}
func
tagKey
(
uid
uint32
)
string
{
return
tagKeyPrefix
+
strconv
.
Itoa
(
int
(
uid
))
}
pkg/tags/tags_test.go
View file @
f28ff0db
...
...
@@ -18,6 +18,7 @@ package tags
import
(
"context"
"errors"
"io/ioutil"
"sort"
"testing"
...
...
@@ -210,4 +211,21 @@ func TestPersistence(t *testing.T) {
if
ta
.
Synced
!=
rcvd2
.
Synced
{
t
.
Fatalf
(
"invalid synced: expected %d got %d"
,
ta
.
Synced
,
rcvd2
.
Synced
)
}
// regression test case: make sure that a persisted tag
// is flushed from statestore on Delete
ts
.
Delete
(
ta
.
Uid
)
// simulate node closing down and booting up
err
=
ts
.
Close
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
ts
=
NewTags
(
mockStatestore
,
logger
)
// get the tag after the node boot up
_
,
err
=
ts
.
Get
(
ta
.
Uid
)
if
!
errors
.
Is
(
err
,
ErrNotFound
)
{
t
.
Fatal
(
err
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment