fix(go.sum): update ResolveSpec dependency to v1.0.87
CI / build-and-test (push) Failing after 1s
Release / release (push) Failing after 19m26s

This commit is contained in:
Hein
2026-06-23 13:17:16 +02:00
parent 0227912325
commit 1adf50e3db
2436 changed files with 1078758 additions and 114 deletions
File diff suppressed because it is too large Load Diff
+144
View File
@@ -0,0 +1,144 @@
package routing
import (
"fmt"
"strings"
)
type RequestPolicy uint8
const (
ReqDefault RequestPolicy = iota
ReqAllNodes
ReqAllShards
ReqMultiShard
ReqSpecial
)
const (
ReadOnlyCMD string = "readonly"
)
func (p RequestPolicy) String() string {
switch p {
case ReqDefault:
return "default"
case ReqAllNodes:
return "all_nodes"
case ReqAllShards:
return "all_shards"
case ReqMultiShard:
return "multi_shard"
case ReqSpecial:
return "special"
default:
return fmt.Sprintf("unknown_request_policy(%d)", p)
}
}
func ParseRequestPolicy(raw string) (RequestPolicy, error) {
switch strings.ToLower(raw) {
case "", "default", "none":
return ReqDefault, nil
case "all_nodes":
return ReqAllNodes, nil
case "all_shards":
return ReqAllShards, nil
case "multi_shard":
return ReqMultiShard, nil
case "special":
return ReqSpecial, nil
default:
return ReqDefault, fmt.Errorf("routing: unknown request_policy %q", raw)
}
}
type ResponsePolicy uint8
const (
RespDefaultKeyless ResponsePolicy = iota
RespDefaultHashSlot
RespAllSucceeded
RespOneSucceeded
RespAggSum
RespAggMin
RespAggMax
RespAggLogicalAnd
RespAggLogicalOr
RespSpecial
)
func (p ResponsePolicy) String() string {
switch p {
case RespDefaultKeyless:
return "default(keyless)"
case RespDefaultHashSlot:
return "default(hashslot)"
case RespAllSucceeded:
return "all_succeeded"
case RespOneSucceeded:
return "one_succeeded"
case RespAggSum:
return "agg_sum"
case RespAggMin:
return "agg_min"
case RespAggMax:
return "agg_max"
case RespAggLogicalAnd:
return "agg_logical_and"
case RespAggLogicalOr:
return "agg_logical_or"
case RespSpecial:
return "special"
default:
return "all_succeeded"
}
}
func ParseResponsePolicy(raw string) (ResponsePolicy, error) {
switch strings.ToLower(raw) {
case "default(keyless)":
return RespDefaultKeyless, nil
case "default(hashslot)":
return RespDefaultHashSlot, nil
case "all_succeeded":
return RespAllSucceeded, nil
case "one_succeeded":
return RespOneSucceeded, nil
case "agg_sum":
return RespAggSum, nil
case "agg_min":
return RespAggMin, nil
case "agg_max":
return RespAggMax, nil
case "agg_logical_and":
return RespAggLogicalAnd, nil
case "agg_logical_or":
return RespAggLogicalOr, nil
case "special":
return RespSpecial, nil
default:
return RespDefaultKeyless, fmt.Errorf("routing: unknown response_policy %q", raw)
}
}
type CommandPolicy struct {
Request RequestPolicy
Response ResponsePolicy
// Tips that are not request_policy or response_policy
// e.g nondeterministic_output, nondeterministic_output_order.
Tips map[string]string
}
func (p *CommandPolicy) CanBeUsedInPipeline() bool {
return p.Request != ReqAllNodes && p.Request != ReqAllShards && p.Request != ReqMultiShard
}
func (p *CommandPolicy) IsReadOnly() bool {
_, readOnly := p.Tips[ReadOnlyCMD]
return readOnly
}
+57
View File
@@ -0,0 +1,57 @@
package routing
import (
"math/rand"
"sync/atomic"
)
// ShardPicker chooses “one arbitrary shard” when the request_policy is
// ReqDefault and the command has no keys.
type ShardPicker interface {
Next(total int) int // returns an index in [0,total)
}
// StaticShardPicker always returns the same shard index.
type StaticShardPicker struct {
index int
}
func NewStaticShardPicker(index int) *StaticShardPicker {
return &StaticShardPicker{index: index}
}
func (p *StaticShardPicker) Next(total int) int {
if total == 0 || p.index >= total {
return 0
}
return p.index
}
/*───────────────────────────────
Round-robin (default)
────────────────────────────────*/
type RoundRobinPicker struct {
cnt atomic.Uint32
}
func (p *RoundRobinPicker) Next(total int) int {
if total == 0 {
return 0
}
i := p.cnt.Add(1)
return int(i-1) % total
}
/*───────────────────────────────
Random
────────────────────────────────*/
type RandomPicker struct{}
func (RandomPicker) Next(total int) int {
if total == 0 {
return 0
}
return rand.Intn(total)
}