Files
seaweedfs/weed/util/slice.go
T
Bruce Zou 554aa13c5b expose whether a volume replica is backed by remote storage
Volume locations returned by lookups do not indicate whether a replica
has been tiered to remote storage. Readers cannot distinguish a local
replica from a remote-backed one, so they may hit a remote-backed
replica first even when a local replica is available.

Add DataInRemote to the lookup location message, populate it from the
master's volume info, and carry it through the wdclient vid map so
clients can prefer local replicas when resolving chunk locations.
2026-09-02 17:51:52 +08:00

32 lines
741 B
Go

package util
// DrainChannel performs a non-blocking drain of a channel after receiving
// the first message. Returns all drained messages including the first one.
// The first message is passed in explicitly (already received by the caller).
func DrainChannel[T any](ch chan T, first T) []T {
result := []T{first}
for {
select {
case v := <-ch:
result = append(result, v)
default:
return result
}
}
}
func ReorderToFront[T comparable](frontMap map[T]bool, inputSlice []T) []T {
var prioritized []T
var remaining []T
for _, item := range inputSlice {
if frontMap[item] {
prioritized = append(prioritized, item)
} else {
remaining = append(remaining, item)
}
}
return append(prioritized, remaining...)
}