Skip to content

Commit

Permalink
support both serializable and linearizable read checker
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Jun 7, 2024
1 parent ae504f9 commit f434941
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ func diagnosisCommandFunc(_ *cobra.Command, _ []string) {
plugins := []intf.Plugin{
membership.NewPlugin(globalCfg),
epstatus.NewPlugin(globalCfg),
read.NewPlugin(globalCfg),
read.NewPlugin(globalCfg, false),
read.NewPlugin(globalCfg, true),
metrics.NewPlugin(globalCfg),
}

Expand Down
21 changes: 18 additions & 3 deletions plugins/read/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

type readChecker struct {
common.Checker
linearizable bool
}

type readResponse struct {
Expand All @@ -27,19 +28,27 @@ type checkResult struct {
ReadResponses []readResponse `json:"readResponses,omitempty"`
}

func NewPlugin(gcfg agent.GlobalConfig) intf.Plugin {
func NewPlugin(gcfg agent.GlobalConfig, linearizable bool) intf.Plugin {
return &readChecker{
Checker: common.Checker{
GlobalConfig: gcfg,
Name: "readChecker",
Name: generateName(linearizable),
},
linearizable: linearizable,
}
}

func (ck *readChecker) Name() string {
return ck.Checker.Name
}

func generateName(linearizable bool) string {
if linearizable {
return "linearizableReadChecker"
}
return "serializableReadChecker"
}

func (ck *readChecker) Diagnose() (result any) {
var (
eps []string
Expand Down Expand Up @@ -74,7 +83,13 @@ func (ck *readChecker) Diagnose() (result any) {
chkResult.ReadResponses[i].Endpoint = ep

startTs := time.Now()
if _, err := agent.Read(ck.GlobalConfig, []string{ep}, "health", clientv3.WithSerializable()); err != nil && err != rpctypes.ErrPermissionDenied {
var err error
if ck.linearizable {
_, err = agent.Read(ck.GlobalConfig, []string{ep}, "health")
} else {
_, err = agent.Read(ck.GlobalConfig, []string{ep}, "health", clientv3.WithSerializable())
}
if err != nil && err != rpctypes.ErrPermissionDenied {
chkResult.ReadResponses[i].Error = err.Error()
shouldRetry = true
}
Expand Down

0 comments on commit f434941

Please sign in to comment.