-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deliver messages even when events are skipped #1015
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// The MIT License | ||
// | ||
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. | ||
// | ||
// Copyright (c) 2020 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package internal | ||
|
||
import ( | ||
"sort" | ||
|
||
protocolpb "go.temporal.io/api/protocol/v1" | ||
) | ||
|
||
type eventMsgIndex []*protocolpb.Message | ||
|
||
// indexMessagesByEventID creates an index over a set of input messages that allows for | ||
// fast access to messages with an event ID less than or equal to a specific | ||
// upper bound. The order of messages with the same event ID will be preserved. | ||
func indexMessagesByEventID(msgs []*protocolpb.Message) *eventMsgIndex { | ||
// implementor note: the order preservation requirement is why we can't use | ||
// the heap package from the Go SDK here. | ||
|
||
sorted := make(eventMsgIndex, len(msgs)) | ||
copy(sorted, msgs) | ||
sort.SliceStable(sorted, func(i, j int) bool { | ||
return sorted[i].GetEventId() < sorted[j].GetEventId() | ||
}) | ||
return &sorted | ||
} | ||
|
||
// takeLTE removes and returns the messages in this index that have an event ID | ||
// less than or equal to the input argument. | ||
func (emi *eventMsgIndex) takeLTE(eventID int64) []*protocolpb.Message { | ||
indexOfFirstGreater := len(*emi) | ||
for i, msg := range *emi { | ||
if msg.GetEventId() > eventID { | ||
indexOfFirstGreater = i | ||
break | ||
} | ||
} | ||
var out []*protocolpb.Message | ||
out, *emi = (*emi)[0:indexOfFirstGreater], (*emi)[indexOfFirstGreater:] | ||
return out | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// The MIT License | ||
// | ||
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. | ||
// | ||
// Copyright (c) 2020 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package internal | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
protocolpb "go.temporal.io/api/protocol/v1" | ||
) | ||
|
||
func TestEventMessageIndex(t *testing.T) { | ||
newMsg := func(id string, eventID int64) *protocolpb.Message { | ||
return &protocolpb.Message{ | ||
Id: id, | ||
SequencingId: &protocolpb.Message_EventId{EventId: eventID}, | ||
} | ||
} | ||
messages := []*protocolpb.Message{ | ||
newMsg("00", 0), | ||
newMsg("01", 2), | ||
newMsg("02", 2), | ||
newMsg("03", 101), | ||
newMsg("04", 100), | ||
newMsg("05", 50), | ||
newMsg("06", 3), | ||
newMsg("07", 0), | ||
newMsg("08", 100), | ||
} | ||
|
||
emi := indexMessagesByEventID(messages) | ||
|
||
batch := emi.takeLTE(2) | ||
require.Len(t, batch, 4) | ||
for i := 0; i < len(batch)-1; i++ { | ||
if batch[i].GetEventId() == batch[i+1].GetEventId() { | ||
require.Less(t, batch[i].Id, batch[i+1].Id) | ||
} | ||
} | ||
|
||
batch = emi.takeLTE(2) | ||
require.Empty(t, batch) | ||
|
||
batch = emi.takeLTE(3) | ||
require.Len(t, batch, 1) | ||
|
||
batch = emi.takeLTE(100) | ||
require.Len(t, batch, 3) | ||
for i := 0; i < len(batch)-1; i++ { | ||
if batch[i].GetEventId() == batch[i+1].GetEventId() { | ||
require.Less(t, batch[i].Id, batch[i+1].Id) | ||
} | ||
} | ||
|
||
emi = indexMessagesByEventID(messages) | ||
batch = emi.takeLTE(9000) | ||
require.Len(t, batch, len(messages)) | ||
require.Empty(t, emi) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it have value to ask the server to always deliver these in event ID order?
Also, is the number of these so great that you really need to sort because of fear of the cost of
takeLTE
? I think you can just maketakeLTE
iterate over all messages every time and https://github.com/golang/go/wiki/SliceTricks#filter-in-place to keep the ones greater than while extracting the ones less than or equal.So something like this (untested, just typed here in comments):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with doing a little more work in takeLTE. I would expect the number of messages per WFT to be low (which to be fair, also makes sorting cheap) but there may be a substantial number when we rebundle into a bigger WFT for replay. I'd like to preserve the transport's ability to reorder messages until we learn more about what is desirable at that layer.