4 Star 0 Fork 0

wanttobeamaster / elasticell

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
aggregation.go 1.06 KB
一键复制 编辑 原始数据 按行查看 历史
wanttobeamaster 提交于 2021-04-05 17:12 . first
package proxy
import (
"strconv"
"gitee.com/wanttobeamaster/elasticell/pkg/pb/raftcmdpb"
)
var (
cmdSet = []byte("SET")
cmdGet = []byte("GET")
)
type aggregationReq struct {
reply int
parts []*raftcmdpb.Response
mergeFn func([][]byte, ...*raftcmdpb.Response) *raftcmdpb.Response
args [][]byte
}
func newAggregationReq(n int, mergeFn func([][]byte, ...*raftcmdpb.Response) *raftcmdpb.Response, args [][]byte) *aggregationReq {
return &aggregationReq{
reply: n,
parts: make([]*raftcmdpb.Response, n, n),
mergeFn: mergeFn,
args: args,
}
}
func (req *aggregationReq) addPart(index int, rsp *raftcmdpb.Response) bool {
req.parts[index] = rsp
req.reply--
return req.reply == 0
}
func (req *aggregationReq) merge() *raftcmdpb.Response {
return req.mergeFn(req.args, req.parts...)
}
func isAggregationPart(id []byte) bool {
return len(id) > 16
}
func parseAggregationPart(id []byte) ([]byte, int) {
return id[0:16], parseStrInt64(id[16:])
}
func parseStrInt64(data []byte) int {
v, _ := strconv.ParseInt(string(data), 10, 64)
return int(v)
}
Go
1
https://gitee.com/wanttobeamaster/elasticell.git
git@gitee.com:wanttobeamaster/elasticell.git
wanttobeamaster
elasticell
elasticell
8b1bff0b0046

搜索帮助