Skip to content

Commit

Permalink
Fix the bug that property merge new tags failed (apache#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanahmily authored Oct 31, 2023
1 parent 0b55f26 commit facef3d
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Release Notes.
- Support etcd client authentication.
- Implement Local file system.

### Bugs

- Fix the bug that property merge new tags failed.

## 0.5.0

### Features
Expand Down
12 changes: 8 additions & 4 deletions banyand/metadata/schema/property.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,20 @@ func (e *etcdSchemaRegistry) mergeProperty(ctx context.Context, key string, prop
return false, 0, 0, err
}
merge := func(existed *propertyv1.Property) (*propertyv1.Property, error) {
tags := make([]*modelv1.Tag, len(property.Tags))
copy(tags, property.Tags)
tags := make([]*modelv1.Tag, 0)
for i := 0; i < int(tagsNum); i++ {
t := tags[0]
tags = tags[1:]
t := property.Tags[i]
tagExisted := false
for _, et := range existed.Tags {
if et.Key == t.Key {
et.Value = t.Value
tagExisted = true
break
}
}
if !tagExisted {
tags = append(tags, t)
}
}
existed.Tags = append(existed.Tags, tags...)
existed.LeaseId = leaseID
Expand Down
2 changes: 1 addition & 1 deletion pkg/node/maglev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

const (
dataNodeTemplate = "data-node-%d"
targetEpsilon = 0.03
targetEpsilon = 0.1
)

func TestMaglevSelector(t *testing.T) {
Expand Down
69 changes: 69 additions & 0 deletions test/integration/standalone/other/property_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,75 @@ var _ = Describe("Property application", func() {
{Key: "t2", Value: &modelv1.TagValue{Value: &modelv1.TagValue_Str{Str: &modelv1.Str{Value: "v22"}}}},
}))
})
It("applies properties with new tags", func() {
md := &propertyv1.Metadata{
Container: &commonv1.Metadata{
Name: "p",
Group: "g",
},
Id: "1",
}
resp, err := client.Apply(context.Background(), &propertyv1.ApplyRequest{Property: &propertyv1.Property{
Metadata: md,
Tags: []*modelv1.Tag{
{Key: "t1", Value: &modelv1.TagValue{Value: &modelv1.TagValue_Str{Str: &modelv1.Str{Value: "v1"}}}},
},
}})
Expect(err).NotTo(HaveOccurred())
Expect(resp.Created).To(BeTrue())
Expect(resp.TagsNum).To(Equal(uint32(1)))
resp, err = client.Apply(context.Background(), &propertyv1.ApplyRequest{Property: &propertyv1.Property{
Metadata: md,
Tags: []*modelv1.Tag{
{Key: "t1", Value: &modelv1.TagValue{Value: &modelv1.TagValue_Str{Str: &modelv1.Str{Value: "v2"}}}},
{Key: "t2", Value: &modelv1.TagValue{Value: &modelv1.TagValue_Str{Str: &modelv1.Str{Value: "v22"}}}},
},
}})
Expect(err).NotTo(HaveOccurred())
Expect(resp.Created).To(BeFalse())
Expect(resp.TagsNum).To(Equal(uint32(2)))
got, err := client.Get(context.Background(), &propertyv1.GetRequest{Metadata: md})
Expect(err).NotTo(HaveOccurred())
Expect(got.Property.Tags).To(Equal([]*modelv1.Tag{
{Key: "t1", Value: &modelv1.TagValue{Value: &modelv1.TagValue_Str{Str: &modelv1.Str{Value: "v2"}}}},
{Key: "t2", Value: &modelv1.TagValue{Value: &modelv1.TagValue_Str{Str: &modelv1.Str{Value: "v22"}}}},
}))
})
It("applies null tag", func() {
md := &propertyv1.Metadata{
Container: &commonv1.Metadata{
Name: "p",
Group: "g",
},
Id: "1",
}
resp, err := client.Apply(context.Background(), &propertyv1.ApplyRequest{Property: &propertyv1.Property{
Metadata: md,
Tags: []*modelv1.Tag{
{Key: "t1", Value: &modelv1.TagValue{Value: &modelv1.TagValue_Str{Str: &modelv1.Str{Value: "v1"}}}},
{Key: "t2", Value: &modelv1.TagValue{Value: &modelv1.TagValue_Null{}}},
},
}})
Expect(err).NotTo(HaveOccurred())
Expect(resp.Created).To(BeTrue())
Expect(resp.TagsNum).To(Equal(uint32(2)))
resp, err = client.Apply(context.Background(), &propertyv1.ApplyRequest{Property: &propertyv1.Property{
Metadata: md,
Tags: []*modelv1.Tag{
{Key: "t1", Value: &modelv1.TagValue{Value: &modelv1.TagValue_Str{Str: &modelv1.Str{Value: "v2"}}}},
{Key: "t2", Value: &modelv1.TagValue{Value: &modelv1.TagValue_Str{Str: &modelv1.Str{Value: "v22"}}}},
},
}})
Expect(err).NotTo(HaveOccurred())
Expect(resp.Created).To(BeFalse())
Expect(resp.TagsNum).To(Equal(uint32(2)))
got, err := client.Get(context.Background(), &propertyv1.GetRequest{Metadata: md})
Expect(err).NotTo(HaveOccurred())
Expect(got.Property.Tags).To(Equal([]*modelv1.Tag{
{Key: "t1", Value: &modelv1.TagValue{Value: &modelv1.TagValue_Str{Str: &modelv1.Str{Value: "v2"}}}},
{Key: "t2", Value: &modelv1.TagValue{Value: &modelv1.TagValue_Str{Str: &modelv1.Str{Value: "v22"}}}},
}))
})
It("applies a property with TTL", func() {
md := &propertyv1.Metadata{
Container: &commonv1.Metadata{
Expand Down

0 comments on commit facef3d

Please sign in to comment.