-
Notifications
You must be signed in to change notification settings - Fork 98
Workaround WAVE-446 #24
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
import org.waveprotocol.wave.model.version.HashedVersion; | ||
import org.waveprotocol.wave.util.logging.Log; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
|
@@ -154,7 +155,15 @@ public synchronized void submitResponse(WaveletName waveletName, HashedVersion v | |
// Forward any queued deltas. | ||
List<TransformedWaveletDelta> filteredDeltas = filterOwnDeltas(state.heldBackDeltas, state); | ||
if (!filteredDeltas.isEmpty()) { | ||
sendUpdate(waveletName, filteredDeltas, null); | ||
// | ||
// Workaround for WAVE-446 ([email protected]) | ||
// | ||
for (TransformedWaveletDelta delta: filteredDeltas) { | ||
List<TransformedWaveletDelta> singleDeltaList = new ArrayList<TransformedWaveletDelta>(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use SingletonList instead? @VisibleForTesting
List<List<TransformedWaveletDelta>> splitToContiguousParts(List<TransformedWaveletDelta>
filteredDeltas) {
Stack<TransformedWaveletDelta> stack = new Stack<>();
Pair<List<List<TransformedWaveletDelta>>, Stack<TransformedWaveletDelta>> identity =
Pair.of(Lists.newArrayList(), stack);
Pair<List<List<TransformedWaveletDelta>>, Stack<TransformedWaveletDelta>> result =
filteredDeltas.stream().reduce(identity, (u, t) -> {
Stack<TransformedWaveletDelta> stackBuffer = u.getSecond();
if (stackBuffer.isEmpty() ||
stackBuffer.peek().getResultingVersion().getVersion() + 1 == t.getResultingVersion().getVersion()) {
stackBuffer.push(t);
} else {
Collections.reverse(stackBuffer);
u.getFirst().add(Lists.newArrayList(stackBuffer));
stackBuffer.clear();
stackBuffer.push(t);
}
return u;
}, (a, b) -> b);
List<List<TransformedWaveletDelta>> out = result.getFirst();
Stack<TransformedWaveletDelta> stackBuffer = result.getSecond();
Collections.reverse(stackBuffer);
out.add(Lists.newArrayList(stackBuffer));
return out;
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you are right, pack and send contiguous deltas works. I wonder whether to add that split function is worthwhile as mere workaround because first, as far as I see in the logs during debug, it is not very common to send more than 2 or 3 deltas at once. Secondly, I think the actual issue is in the client side (or protocol's message): since each received delta message doesn't have both start and end version, the deserialize method can't infer the right ones if they are not contiguous. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess let's just implement a naive splitter that packs every delta into a separate list. I think the better solution would be to take the client-server implementation from the wiab pro. They totally rewrote and improved it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I'm wrong but this sounds to me a common "perfect is the enemy of good" situation. What about if we merge this PR, while we think/work in your proposal of using the wiab pro code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, that's what I intended to say, probably I wasn't clear. |
||
singleDeltaList.add(delta); | ||
sendUpdate(waveletName, singleDeltaList, null); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like the bracket could use formatting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, thanks, always struggling with formatters :( |
||
|
||
} | ||
state.heldBackDeltas.clear(); | ||
} | ||
|
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.
Can we extract the code into a separate method with a descriptive name instead of putting a comment in the code?
Uh oh!
There was an error while loading. Please reload this page.
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.
Sure, that is neater