diff --git a/bolt/bucket.go b/bolt/bucket.go index 64f984a38e..9caacc89a4 100644 --- a/bolt/bucket.go +++ b/bolt/bucket.go @@ -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", diff --git a/inmem/bucket_service.go b/inmem/bucket_service.go index 430003755d..d56a7e1ac2 100644 --- a/inmem/bucket_service.go +++ b/inmem/bucket_service.go @@ -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", diff --git a/kv/bucket.go b/kv/bucket.go index 8e66200833..15ffe40005 100644 --- a/kv/bucket.go +++ b/kv/bucket.go @@ -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", diff --git a/testing/bucket_service.go b/testing/bucket_service.go index cc83358bac..8dcef87388 100644 --- a/testing/bucket_service.go +++ b/testing/bucket_service.go @@ -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 {