Return NumVersions in quorum when available (#19766)

Similar to https://github.com/minio/minio/pull/17925
This commit is contained in:
Krishnan Parthasarathi
2024-05-17 13:57:37 -07:00
committed by GitHub
parent fc4561c64c
commit 1228d6bf1a
3 changed files with 73 additions and 22 deletions

View File

@@ -26,6 +26,20 @@ import (
"github.com/minio/pkg/v2/sync/errgroup"
)
// counterMap type adds GetValueWithQuorum method to a map[T]int used to count occurrences of values of type T.
type counterMap[T comparable] map[T]int
// GetValueWithQuorum returns the first key which occurs >= quorum number of times.
func (c counterMap[T]) GetValueWithQuorum(quorum int) (T, bool) {
var zero T
for x, count := range c {
if count >= quorum {
return x, true
}
}
return zero, false
}
// figure out the most commonVersions across disk that satisfies
// the 'writeQuorum' this function returns "" if quorum cannot
// be achieved and disks have too many inconsistent versions.