// FindBucket returns the first bucket that matches filter.
545624
func (s *BucketService) FindBucket(ctx context.Context, filter platform.BucketFilter) (*platform.Bucket, error) {
	bs, n, err := s.FindBuckets(ctx, filter)
	if err != nil {
		return nil, err
	}

	if n == 0 {
		return nil, &platform.Error{
			Code: platform.ENotFound,
			Op:   s.OpPrefix + platform.OpFindBucket,
			Msg:  "bucket not found",
			Err:  ErrNotFound,
		}
	}

	return bs[0], nil
}
388805
func (s *PutBucketWebsiteInput) SetBucket(v string) *PutBucketWebsiteInput {
	s.Bucket = &v
	return s
}
1219130
func (a *CompositeAggregationTermsValuesSource) MissingBucket(missingBucket bool) *CompositeAggregationTermsValuesSource {
	a.missingBucket = &missingBucket
	return a
}
500426
func (s *GetBucketAccelerateConfigurationInput) SetBucket(v string) *GetBucketAccelerateConfigurationInput {
	s.Bucket = &v
	return s
}
342816
func (ht *HashTable) nextBucket(bucket int) int {
	if bucket >= ht.numBuckets {
		return 0
	}
	bucketAddr := bucket * ht.BucketSize
	nextUint, err := binary.Varint(ht.Buf[bucketAddr : bucketAddr+10])
	next := int(nextUint)
	if next == 0 {
		return 0
	} else if err < 0 || next <= bucket || next >= ht.numBuckets || next < ht.InitialBuckets {
		tdlog.CritNoRepeat("Bad hash table - repair ASAP %s", ht.Path)
		return 0
	} else {
		return next
	}
}
138934
func (builder *FetchCounterCommandBuilder) WithBucket(bucket string) *FetchCounterCommandBuilder {
	builder.protobuf.Bucket = []byte(bucket)
	return builder
}
522267
func (s *Service) FindBucket(ctx context.Context, filter platform.BucketFilter) (*platform.Bucket, error) {
	op := OpPrefix + platform.OpFindBucket
	var err error
	var b *platform.Bucket

	if filter.ID == nil && filter.Name == nil && filter.OrganizationID == nil {
		return nil, &platform.Error{
			Code: platform.EInvalid,
			Op:   op,
			Msg:  "no filter parameters provided",
		}
	}

	// filter by bucket id
	if filter.ID != nil {
		b, err = s.FindBucketByID(ctx, *filter.ID)
		if err != nil {
			return nil, &platform.Error{
				Op:  op,
				Err: err,
			}
		}
		return b, nil
	}

	bs, n, err := s.FindBuckets(ctx, filter)
	if err != nil {
		return nil, err
	}

	if n < 1 && filter.Name != nil {
		return nil, &platform.Error{
			Code: platform.ENotFound,
			Op:   op,
			Msg:  fmt.Sprintf("bucket %q not found", *filter.Name),
		}
	} else if n < 1 {
		return nil, &platform.Error{
			Code: platform.ENotFound,
			Op:   op,
			Msg:  "bucket not found",
		}
	}

	return bs[0], nil
}
5335
func (s *Service) FindBucketByName(ctx context.Context, orgID influxdb.ID, n string) (*influxdb.Bucket, error) {
	span, ctx := tracing.StartSpanFromContext(ctx)
	defer span.Finish()

	var b *influxdb.Bucket
	var err error

	err = s.kv.View(ctx, func(tx Tx) error {
		bkt, pe := s.findBucketByName(ctx, tx, orgID, n)
		if pe != nil {
			err = pe
			return err
		}
		b = bkt
		return nil
	})

	return b, err
}
980553
func (s *PutBucketReplicationInput) SetBucket(v string) *PutBucketReplicationInput {
	s.Bucket = &v
	return s
}
1369794
func (c *Client) GetBucket(bucket string) (*RpbGetBucketResp, error) {
	return c.getBucket(nil, bucket)
}
348132
func (s *PutBucketAnalyticsConfigurationInput) SetBucket(v string) *PutBucketAnalyticsConfigurationInput {
	s.Bucket = &v
	return s
}
760069
func (s *PutBucketLifecycleConfigurationInput) SetBucket(v string) *PutBucketLifecycleConfigurationInput {
	s.Bucket = &v
	return s
}
1112279
func (s *BucketService) FindBucketByID(ctx context.Context, id influxdb.ID) (*influxdb.Bucket, error) {
	span, ctx := tracing.StartSpanFromContext(ctx)
	defer span.Finish()

	b, err := s.s.FindBucketByID(ctx, id)
	if err != nil {
		return nil, err
	}

	if err := authorizeReadBucket(ctx, b.OrgID, id); err != nil {
		return nil, err
	}

	return b, nil
}
609392
func readBucket(f *os.File) (map[string]bucketItem, error) {
	// If the file is empty, return an empty bucket.
	ok, err := isEmpty(f)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	if ok {
		return map[string]bucketItem{}, nil
	}

	// The file is not empty, read it into a map.
	var items map[string]bucketItem
	bytes, err := ioutil.ReadAll(f)
	if err != nil {
		return nil, trace.ConvertSystemError(err)
	}
	err = utils.FastUnmarshal(bytes, &items)
	if err != nil {
		return nil, trace.Wrap(err)
	}

	return items, nil
}
225140
func (builder *FetchValueCommandBuilder) WithBucket(bucket string) *FetchValueCommandBuilder {
	builder.protobuf.Bucket = []byte(bucket)
	return builder
}
604939
func (s *PutBucketNotificationConfigurationInput) SetBucket(v string) *PutBucketNotificationConfigurationInput {
	s.Bucket = &v
	return s
}
486135
func (c *Client) FindBucketByID(ctx context.Context, id platform.ID) (*platform.Bucket, error) {
	var b *platform.Bucket
	var err error

	err = c.db.View(func(tx *bolt.Tx) error {
		bkt, pe := c.findBucketByID(ctx, tx, id)
		if pe != nil {
			pe.Op = getOp(platform.OpFindBucketByID)
			err = pe
			return err
		}
		b = bkt
		return nil
	})

	if err != nil {
		return nil, err
	}

	return b, nil
}