Skip to content

Commit

Permalink
rpc: rename ping interceptors for clarity
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
tbg committed Oct 14, 2020
1 parent 3cde9d5 commit 40cdd5a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
20 changes: 10 additions & 10 deletions pkg/rpc/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,15 @@ type ContextOptions struct {
Clock *hlc.Clock
Stopper *stop.Stopper
Settings *cluster.Settings
// OnHandlePing is called when handling a PingRequest, after
// OnIncomingPing is called when handling a PingRequest, after
// preliminary checks but before recording clock offset information.
//
// It can inject an error.
OnHandlePing func(*PingRequest) error
// OnSendPing intercepts outgoing PingRequests. It may inject an
OnIncomingPing func(*PingRequest) error
// OnOutgoingPing intercepts outgoing PingRequests. It may inject an
// error.
OnSendPing func(*PingRequest) error
Knobs ContextTestingKnobs
OnOutgoingPing func(*PingRequest) error
Knobs ContextTestingKnobs
}

func (c ContextOptions) validate() error {
Expand All @@ -406,9 +406,9 @@ func (c ContextOptions) validate() error {
return errors.New("Settings must be set")
}

// NB: OnSendPing and OnHandlePing default to noops.
// NB: OnOutgoingPing and OnIncomingPing default to noops.
// This is used both for testing and the cli.
_, _ = c.OnSendPing, c.OnHandlePing
_, _ = c.OnOutgoingPing, c.OnIncomingPing

return nil
}
Expand Down Expand Up @@ -1138,7 +1138,7 @@ func (ctx *Context) runHeartbeat(
// Permanent errors return an error from this method, which means that
// the connection will be removed. Errors are presumed transient by
// default, but some - like ClusterID or version mismatches, as well as
// PermissionDenied errors injected by OnSendPing, are considered permanent.
// PermissionDenied errors injected by OnOutgoingPing, are considered permanent.
returnErr := false
for {
select {
Expand All @@ -1163,7 +1163,7 @@ func (ctx *Context) runHeartbeat(
}

interceptor := func(*PingRequest) error { return nil }
if fn := ctx.OnSendPing; fn != nil {
if fn := ctx.OnOutgoingPing; fn != nil {
interceptor = fn
}

Expand Down Expand Up @@ -1274,7 +1274,7 @@ func (ctx *Context) NewHeartbeatService() *HeartbeatService {
clusterID: &ctx.ClusterID,
nodeID: &ctx.NodeID,
settings: ctx.Settings,
onHandlePing: ctx.OnHandlePing,
onHandlePing: ctx.OnIncomingPing,
testingAllowNamedRPCToAnonymousServer: ctx.TestingAllowNamedRPCToAnonymousServer,
}
}
6 changes: 3 additions & 3 deletions pkg/rpc/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func TestHeartbeatCB(t *testing.T) {
})
}

// TestPingInterceptors checks that OnSendPing and OnHandlePing can inject errors.
// TestPingInterceptors checks that OnOutgoingPing and OnIncomingPing can inject errors.
func TestPingInterceptors(t *testing.T) {
defer leaktest.AfterTest(t)()
ctx := context.Background()
Expand All @@ -181,13 +181,13 @@ func TestPingInterceptors(t *testing.T) {
Clock: hlc.NewClock(hlc.UnixNano, 500*time.Millisecond),
Stopper: stop.NewStopper(),
Settings: cluster.MakeTestingClusterSettings(),
OnSendPing: func(req *PingRequest) error {
OnOutgoingPing: func(req *PingRequest) error {
if req.TargetNodeID == blockedTargetNodeID {
return errBoomSend
}
return nil
},
OnHandlePing: func(req *PingRequest) error {
OnIncomingPing: func(req *PingRequest) error {
if req.OriginNodeID == blockedOriginNodeID {
return errBoomRecv
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/rpc/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type HeartbeatService struct {
clusterName string
disableClusterNameVerification bool

onHandlePing func(*PingRequest) error // see ContextOptions.OnHandlePing
onHandlePing func(*PingRequest) error // see ContextOptions.OnIncomingPing

// TestingAllowNamedRPCToAnonymousServer, when defined (in tests),
// disables errors in case a heartbeat requests a specific node ID but
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ func NewServer(cfg Config, stopper *stop.Stopper) (*Server, error) {
Clock: clock,
Stopper: stopper,
Settings: cfg.Settings,
OnSendPing: func(req *rpc.PingRequest) error {
OnOutgoingPing: func(req *rpc.PingRequest) error {
return checkPingFor(ctx, req.TargetNodeID)
},
OnHandlePing: func(req *rpc.PingRequest) error {
OnIncomingPing: func(req *rpc.PingRequest) error {
return checkPingFor(ctx, req.OriginNodeID)
}}
if knobs := cfg.TestingKnobs.Server; knobs != nil {
Expand Down

0 comments on commit 40cdd5a

Please sign in to comment.