Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

Workaround WAVE-446 #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Workaround WAVE-446 #24

wants to merge 2 commits into from

Conversation

pablojan
Copy link
Contributor

@pablojan pablojan commented May 1, 2017

Workaround for critical bug in client/server protocol implementation
See https://issues.apache.org/jira/browse/WAVE-446

Copy link
Contributor

@vega113 vega113 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the commit fixes WAVE-443 but the pull request is for WAVE-446.
Great job on figuring the root cause of this issue! It would be really great to add a unit test that reproduces the issue.

List<TransformedWaveletDelta> singleDeltaList = new ArrayList<TransformedWaveletDelta>(1);
singleDeltaList.add(delta);
sendUpdate(waveletName, singleDeltaList, null);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the bracket could use formatting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, thanks, always struggling with formatters :(

//
// Workaround for WAVE-446 ([email protected])
//
for (TransformedWaveletDelta delta: filteredDeltas) {
Copy link
Contributor

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?

Copy link
Contributor Author

@pablojan pablojan May 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that is neater

// Workaround for WAVE-446 ([email protected])
//
for (TransformedWaveletDelta delta: filteredDeltas) {
List<TransformedWaveletDelta> singleDeltaList = new ArrayList<TransformedWaveletDelta>(1);
Copy link
Contributor

@vega113 vega113 May 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use SingletonList instead?
In fact, it looks like it is enough to partition the filteredDeltas into sublists with contiguous deltas and send only those sublists separately.
We can split with something like this (didn't test this yet):

  @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;
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@vjrj
Copy link
Member

vjrj commented May 3, 2017

Thanks indeed Pablo for taking care of this important bug.

@wisebaldone
Copy link
Contributor

is this approved?

@vega113
Copy link
Contributor

vega113 commented Jul 3, 2017

I didn't test the last commit but it LGTM

vjrj added a commit to comunes/kune that referenced this pull request Aug 26, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants