Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #728 from mpuncel/mpuncel/wait-for-exists-watch-po…
Browse files Browse the repository at this point in the history
…d-status

Mpuncel/wait for exists watch pod status
  • Loading branch information
mpuncel committed Jan 19, 2017
2 parents 783f36a + a763b04 commit 38c9708
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 37 deletions.
13 changes: 10 additions & 3 deletions pkg/grpc/podstore/podstore.go
Expand Up @@ -92,6 +92,16 @@ func (s store) WatchPodStatus(req *podstore_protos.WatchPodStatusRequest, stream
go func() {
for {
status, queryMeta, err := s.podStatusStore.WaitForStatus(podUniqueKey, waitIndex)

if queryMeta != nil {
waitIndex = queryMeta.LastIndex
}

if statusstore.IsNoStatus(err) && req.WaitForExists {
// the client wants 404 to be ignored, start
// the watch again with our new index
continue
}
select {
case podStatusResultCh <- podStatusResult{
status: status,
Expand All @@ -102,9 +112,6 @@ func (s store) WatchPodStatus(req *podstore_protos.WatchPodStatusRequest, stream
return
}

if queryMeta != nil {
waitIndex = queryMeta.LastIndex
}
case <-innerQuit:
// Client canceled
return
Expand Down
4 changes: 1 addition & 3 deletions pkg/grpc/podstore/podstore_test.go
Expand Up @@ -111,9 +111,7 @@ func TestWatchPodStatus(t *testing.T) {
req := &podstore_protos.WatchPodStatusRequest{
StatusNamespace: consul.PreparerPodStatusNamespace.String(),
PodUniqueKey: podUniqueKey.String(),
// Set it 1 above last index so we wait for the key to exist. (The test status
// store starts at 1234 for some reason)
WaitIndex: 1235,
WaitForExists: true,
}

watchErrCh := make(chan error)
Expand Down
64 changes: 33 additions & 31 deletions pkg/grpc/podstore/protos/podstore.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/grpc/podstore/protos/podstore.proto
Expand Up @@ -23,6 +23,7 @@ message WatchPodStatusRequest {
string pod_unique_key = 1;
uint64 wait_index = 2; // the WaitIndex to pass to watch requests
string status_namespace = 3;
bool wait_for_exists = 4; // If set, the server will wait for a not-existing key to exist (rather than return a Not Found error)
}

message PodStatusResponse {
Expand Down

0 comments on commit 38c9708

Please sign in to comment.