fix(kv): fix bucket update issue

pull/12456/head
Kelvin Wang 2019-03-08 11:30:55 -05:00
parent 81e15b7141
commit fb6e3b3a5f
4 changed files with 44 additions and 8 deletions

View File

@ -6,8 +6,7 @@ import (
"fmt"
"time"
"github.com/coreos/bbolt"
bolt "github.com/coreos/bbolt"
platform "github.com/influxdata/influxdb"
platformcontext "github.com/influxdata/influxdb/context"
"github.com/influxdata/influxdb/kit/tracing"
@ -557,8 +556,8 @@ func (c *Client) updateBucket(ctx context.Context, tx *bolt.Tx, id platform.ID,
}
if upd.Name != nil {
_, err := c.findBucketByName(ctx, tx, b.OrganizationID, *upd.Name)
if err == nil {
b0, err := c.findBucketByName(ctx, tx, b.OrganizationID, *upd.Name)
if err == nil && b0.ID != id {
return nil, &platform.Error{
Code: platform.EConflict,
Msg: "bucket name is not unique",

View File

@ -294,10 +294,10 @@ func (s *Service) UpdateBucket(ctx context.Context, id platform.ID, upd platform
b.RetentionPeriod = *upd.RetentionPeriod
}
_, err = s.FindBucket(ctx, platform.BucketFilter{
b0, err := s.FindBucket(ctx, platform.BucketFilter{
Name: upd.Name,
})
if err == nil {
if err == nil && b0.ID != id {
return nil, &platform.Error{
Code: platform.EConflict,
Msg: "bucket name is not unique",

View File

@ -622,8 +622,8 @@ func (s *Service) updateBucket(ctx context.Context, tx Tx, id influxdb.ID, upd i
}
if upd.Name != nil {
_, err := s.findBucketByName(ctx, tx, b.OrganizationID, *upd.Name)
if err == nil {
b0, err := s.findBucketByName(ctx, tx, b.OrganizationID, *upd.Name)
if err == nil && b0.ID != id {
return nil, &influxdb.Error{
Code: influxdb.EConflict,
Msg: "bucket name is not unique",

View File

@ -1239,6 +1239,43 @@ func UpdateBucket(
},
},
},
{
name: "update retention and same name",
fields: BucketFields{
Organizations: []*platform.Organization{
{
Name: "theorg",
ID: MustIDBase16(orgOneID),
},
},
Buckets: []*platform.Bucket{
{
ID: MustIDBase16(bucketOneID),
OrganizationID: MustIDBase16(orgOneID),
Name: "bucket1",
},
{
ID: MustIDBase16(bucketTwoID),
OrganizationID: MustIDBase16(orgOneID),
Name: "bucket2",
},
},
},
args: args{
id: MustIDBase16(bucketTwoID),
retention: 101,
name: "bucket2",
},
wants: wants{
bucket: &platform.Bucket{
ID: MustIDBase16(bucketTwoID),
OrganizationID: MustIDBase16(orgOneID),
Organization: "theorg",
Name: "bucket2",
RetentionPeriod: 101 * time.Minute,
},
},
},
}
for _, tt := range tests {