mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-16 02:58:35 +02:00
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.
32 lines
741 B
Go
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...)
|
|
}
|