Skip to content

Commit

Permalink
keymanager: Wait for keymanager to become ready
Browse files Browse the repository at this point in the history
  • Loading branch information
matevz committed Jun 1, 2020
1 parent c82553b commit 7396a7d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
11 changes: 11 additions & 0 deletions .changelog/2130.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
client protocol: Add IsReady() and WaitReady() RPC methods

Beside `IsSynced()` and `WaitSynced()` which are triggered when a node is
registered, new `IsReady()` and `WaitReady()` methods have been added to
client protocol. These are triggered when all node workers have been
initialized (including the runtimes) and the hosted processes are ready to
process requests. Some oasis-test-runner scenarios have been updated
accordingly.

In addition new `oasis-node debug control wait-ready`
command was added which blocks the client until the node is ready.
36 changes: 13 additions & 23 deletions go/worker/keymanager/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,29 +184,20 @@ func (w *Worker) callLocal(ctx context.Context, data []byte) ([]byte, error) {
}

func (w *Worker) updateStatus(status *api.Status, startedEvent *host.StartedEvent) error {
var initOk bool
defer func() {
if !initOk {
// TODO: once #2130 is done and keymanager reports as Ready only
// after initialization succeeds, change this to always pre-register
// on the initial updateStatus call (and not only after the first
// initialization fails as it is done currently).
// This is likely a new key manager that needs to replicate.
// Send a node registration anyway, so that other nodes know
// to update their access control.
w.roleProvider.SetAvailable(func(n *node.Node) error {
rt := n.AddOrUpdateRuntime(w.runtime.ID())
rt.Version = startedEvent.Version
rt.ExtraInfo = nil
rt.Capabilities.TEE = startedEvent.CapabilityTEE
return nil
})

// If initialization failed setup a retry ticker.
if w.initTicker == nil {
w.initTicker = backoff.NewTicker(backoff.NewExponentialBackOff())
w.initTickerCh = w.initTicker.C
}
<-w.Initialized()
w.roleProvider.SetAvailable(func(n *node.Node) error {
rt := n.AddOrUpdateRuntime(w.runtime.ID())
rt.Version = startedEvent.Version
rt.ExtraInfo = nil
rt.Capabilities.TEE = startedEvent.CapabilityTEE
return nil
})

// If initialization failed setup a retry ticker.
if w.initTicker == nil {
w.initTicker = backoff.NewTicker(backoff.NewExponentialBackOff())
w.initTickerCh = w.initTicker.C
}
}()

Expand Down Expand Up @@ -307,7 +298,6 @@ func (w *Worker) updateStatus(status *api.Status, startedEvent *host.StartedEven
}

// Register as we are now ready to handle requests.
initOk = true
w.roleProvider.SetAvailable(func(n *node.Node) error {
rt := n.AddOrUpdateRuntime(w.runtime.ID())
rt.Version = startedEvent.Version
Expand Down

0 comments on commit 7396a7d

Please sign in to comment.