Skip to content

Commit

Permalink
handle intent none in fdv2 protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
cwaldren-ld committed Dec 5, 2024
1 parent cd461e5 commit ff694fc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions internal/datasourcev2/polling_http_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ func (r *pollingRequester) Request() (*fdv2proto.ChangeSet, error) {
if err != nil {
return nil, err
}
if serverIntent.Payload.Code == fdv2proto.IntentNone {
return changeSet.NoChanges(), nil
}
if err := changeSet.Start(serverIntent); err != nil {
return nil, err
}
Expand Down
14 changes: 12 additions & 2 deletions internal/datasourcev2/streaming_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ func (sp *StreamProcessor) consumeStream(stream *es.Stream, closeWhenReady chan<
break
}

// IntentNone is a special case where we won't receive a payload-transferred event, so we will need
// to instead immediately notify the client that we are initialized.
if serverIntent.Payload.Code == fdv2proto.IntentNone {
sp.setInitializedAndNotifyClient(true, closeWhenReady)
break
}

if err := changeSetBuilder.Start(serverIntent); err != nil {
gotMalformedEvent(event, err)
break
Expand Down Expand Up @@ -268,13 +275,16 @@ func (sp *StreamProcessor) consumeStream(stream *es.Stream, closeWhenReady chan<
switch code {
case fdv2proto.IntentTransferFull:
sp.dataDestination.SetBasis(changeSet.Changes(), changeSet.Selector(), true)
sp.setInitializedAndNotifyClient(true, closeWhenReady)
case fdv2proto.IntentTransferChanges:
sp.dataDestination.ApplyDelta(changeSet.Changes(), changeSet.Selector(), true)
case fdv2proto.IntentNone:
// No changes, our existing data is up-to-date for the moment.
/* We don't expect to receive this, but it could be possible. In that case, it should be
equivalent to transferring no changes - a no-op.
*/
}

sp.setInitializedAndNotifyClient(true, closeWhenReady)

default:
sp.loggers.Infof("Unexpected event found in stream: %s", event.Event())
}
Expand Down

0 comments on commit ff694fc

Please sign in to comment.