Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit 0403505

Browse files
committed
raft: async-discover
Signed-off-by: Shlomi Noach <[email protected]>
1 parent 08f898f commit 0403505

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

go/http/api.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ func (this *HttpAPI) Instance(params martini.Params, r render.Render, req *http.
208208
// AsyncDiscover issues an asynchronous read on an instance. This is
209209
// useful for bulk loads of a new set of instances and will not block
210210
// if the instance is slow to respond or not reachable.
211+
// It will also not block the raft queue in the event ocmmunication to discover instance hangs.
211212
func (this *HttpAPI) AsyncDiscover(params martini.Params, r render.Render, req *http.Request, user auth.User) {
212213
if !isAuthorizedForAction(req, user) {
213214
Respond(r, &APIResponse{Code: ERROR, Message: "Unauthorized"})
@@ -218,7 +219,12 @@ func (this *HttpAPI) AsyncDiscover(params martini.Params, r render.Render, req *
218219
Respond(r, &APIResponse{Code: ERROR, Message: err.Error()})
219220
return
220221
}
221-
go this.Discover(params, r, req, user)
222+
223+
if orcraft.IsRaftEnabled() {
224+
orcraft.PublishCommand("async-discover", instanceKey)
225+
} else {
226+
go logic.DiscoverInstance(instanceKey)
227+
}
222228

223229
Respond(r, &APIResponse{Code: OK, Message: fmt.Sprintf("Asynchronous discovery initiated for Instance: %+v", instanceKey)})
224230
}

go/logic/command_applier.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
"github.com/openark/orchestrator/go/inst"
2323
"github.com/openark/orchestrator/go/kv"
24-
"github.com/openark/orchestrator/go/raft"
24+
orcraft "github.com/openark/orchestrator/go/raft"
2525

2626
"github.com/openark/golib/log"
2727
)
@@ -45,6 +45,8 @@ func (applier *CommandApplier) ApplyCommand(op string, value []byte) interface{}
4545
return applier.registerNode(value)
4646
case "discover":
4747
return applier.discover(value)
48+
case "async-discover":
49+
return applier.asyncDiscover(value)
4850
case "injected-pseudo-gtid":
4951
return applier.injectedPseudoGTID(value)
5052
case "forget":
@@ -109,6 +111,14 @@ func (applier *CommandApplier) discover(value []byte) interface{} {
109111
return nil
110112
}
111113

114+
// asyncDiscover discover-s in a goroutine so that the discovery cannot block the raft path
115+
// (e.g. a situation where communication with discovered instannce hangs could block the entire
116+
// raft queue; this function is therefore safer)
117+
func (applier *CommandApplier) asyncDiscover(value []byte) interface{} {
118+
go applier.discover(value)
119+
return nil
120+
}
121+
112122
func (applier *CommandApplier) injectedPseudoGTID(value []byte) interface{} {
113123
var clusterName string
114124
if err := json.Unmarshal(value, &clusterName); err != nil {

0 commit comments

Comments
 (0)