Skip to content

Commit

Permalink
kv: adjust comments of BatchRequest.hasFlag and hasFlagForAll
Browse files Browse the repository at this point in the history
Adjust the comments of `BatchRequest.hasFlag` and `hasFlagForAll` to
clarify that `hasFlag` has the *any* semantics and `hasFlagForAll` has
the *all* semantics. (I think the latter is probably true, but currently
`hasFlagForAll` is only called in a single place with a single flag.)

Epic: None
Release note: None
  • Loading branch information
michae2 committed Oct 23, 2024
1 parent b7d9b82 commit b8bc94c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions pkg/kv/kvpb/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,25 +405,25 @@ func (ba *BatchRequest) IsCompleteTransaction() bool {
panic(fmt.Sprintf("unreachable. Batch requests: %s", TruncatedRequestsString(ba.Requests, 1024)))
}

// hasFlag returns true iff one of the requests within the batch contains the
// specified flag.
func (ba *BatchRequest) hasFlag(flag flag) bool {
// hasFlag returns true iff at least one of the requests within the batch
// contains at least one of the specified flags.
func (ba *BatchRequest) hasFlag(flags flag) bool {
for _, union := range ba.Requests {
if (union.GetInner().flags() & flag) != 0 {
if (union.GetInner().flags() & flags) != 0 {
return true
}
}
return false
}

// hasFlagForAll returns true iff all of the requests within the batch contains
// the specified flag.
func (ba *BatchRequest) hasFlagForAll(flag flag) bool {
// hasFlagForAll returns true iff all of the requests within the batch contain
// all of the specified flags.
func (ba *BatchRequest) hasFlagForAll(flags flag) bool {
if len(ba.Requests) == 0 {
return false
}
for _, union := range ba.Requests {
if (union.GetInner().flags() & flag) == 0 {
if (union.GetInner().flags() & flags) != flags {
return false
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kv/kvserver/asim/tests/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func (o OutputFlags) set(f OutputFlags) OutputFlags {
return o | f
}

// Has returns true if this flag has the given f OutputFlags on.
// Has returns true if this flag has all of the given f OutputFlags on.
func (o OutputFlags) Has(f OutputFlags) bool {
return o&f != 0
return o&f == f
}

type testResult struct {
Expand Down

0 comments on commit b8bc94c

Please sign in to comment.