Skip to content

Test failure in RankIndexTest::repeatedRankQuery #482

Closed

Description

@alecgrieser

During one pull request build, at least one PR unrelated to rank indexes has encountered an error performing the RankIndexTest::repeatedRankQuery test. Here's the test output:

com.apple.foundationdb.record.provider.foundationdb.RankIndexTest > repeatedRankQuery() FAILED
    org.opentest4j.AssertionFailedError: expected: <[achilles, patroclus, hector, patroclus, hector, hector, achilles, hector, achilles, hector, patroclus]> but was: <[achilles, patroclus, hector, patroclus, hector, hector, achilles, hector, achilles, hector, patroclus, achilles, hector]>
        at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:52)
        at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
        at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:186)
        at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:181)
        at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:486)
        at com.apple.foundationdb.record.provider.foundationdb.RankIndexTest.repeatedRankQuery(RankIndexTest.java:746)

Here are the two lists on their own lines:

[achilles, patroclus, hector, patroclus, hector, hector, achilles, hector, achilles, hector, patroclus]
[achilles, patroclus, hector, patroclus, hector, hector, achilles, hector, achilles, hector, patroclus, achilles, hector]

So it looks like the test is sometimes adding an extra achilles and an extra hector at the end of the query.

One such PR that encountered this error was #160.

Activity

  1. alecgrieser commented on Mar 24, 2019

    @alecgrieser
    CollaboratorAuthor

    I suspect that there's something subtle going on in the RankedSet. This is classified here as a test failing, but it could also be the sign of some subtle race condition rather than a testing failure.

  2. added
    bug
    on Mar 24, 2019
  3. MMcM commented on Mar 25, 2020

    @MMcM
    Collaborator

    Happened again with #870

  4. ScottDugas commented on Apr 20, 2020

    @ScottDugas
    Collaborator

    I managed to reproduce this locally. I then reopened the store after the test failed, and it fails reliably, so it is whatever is in the index.
    For reference the code that inserts these record looks like:

    Code: (for reference)

    rec.setName("patroclus")
            .addScore(-5)
            .addScore(5)
            .addScore(-10)
            .addScore(-11)
            .addScore(-8);
    recordStore.saveRecord(rec.build());
    
    rec.clear();
    rec.setName("achilles")
            .addScore(-14)
            .addScore(5)
            .addScore(9)
            .addScore(-8)
            .addScore(-1)
            .addScore(-16);
    recordStore.saveRecord(rec.build());
    
    rec.clear();
    rec.setName("hector")
            .addScore(-5)
            .addScore(5)
            .addScore(-3)
            .addScore(-2)
            .addScore(0)
            .addScore(10);
    recordStore.saveRecord(rec.build());

    When I open it back up and scan the index/records in different ways I get:
    By Value:

    [score_by_repeated_field:(-16, "achilles"):(),
     score_by_repeated_field:(-14, "achilles"):(),
     score_by_repeated_field:(-11, "patroclus"):(),
     score_by_repeated_field:(-10, "patroclus"):(),
     score_by_repeated_field:(-8, "achilles"):(),
     score_by_repeated_field:(-8, "patroclus"):(),
     score_by_repeated_field:(-5, "hector"):(),
     score_by_repeated_field:(-5, "patroclus"):(),
     score_by_repeated_field:(-3, "hector"):(),
     score_by_repeated_field:(-2, "hector"):(),
     score_by_repeated_field:(-1, "achilles"):(),
     score_by_repeated_field:(0, "hector"):(),
     score_by_repeated_field:(5, "achilles"):(),
     score_by_repeated_field:(5, "hector"):(),
     score_by_repeated_field:(5, "patroclus"):(),
     score_by_repeated_field:(9, "achilles"):(),
     score_by_repeated_field:(10, "hector"):()]
    

    By Rank: (rank value manually added)

    [00: score_by_repeated_field:(-16, "achilles"):(),
     01: score_by_repeated_field:(-14, "achilles"):(),
     02: score_by_repeated_field:(-11, "patroclus"):(),
     03: score_by_repeated_field:(-10, "patroclus"):(),
     
     04: score_by_repeated_field:(-8, "achilles"):(),
     04: score_by_repeated_field:(-8, "patroclus"):(),
     05: score_by_repeated_field:(-5, "hector"):(),
     05: score_by_repeated_field:(-5, "patroclus"):(),
     06: score_by_repeated_field:(-3, "hector"):(),
     07: score_by_repeated_field:(-2, "hector"):(),
     08: score_by_repeated_field:(-1, "achilles"):(),
     09: score_by_repeated_field:(0, "hector"):(),
     10: score_by_repeated_field:(5, "achilles"):(),
     10: score_by_repeated_field:(5, "hector"):(),
     10: score_by_repeated_field:(5, "patroclus"):(),
     
     11: score_by_repeated_field:(9, "achilles"):(),
     12: score_by_repeated_field:(10, "hector"):()]
    

    Records:

    [{name: "achilles"
      score: -14
      score: 5
      score: 9
      score: -8
      score: -1
      score: -16
     },
     {name: "hector"
      score: -5
      score: 5
      score: -3
      score: -2
      score: 0
      score: 10
     },
     {name: "patroclus"
      score: -5
      score: 5
      score: -10
      score: -11
      score: -8}]
    

    Which results in the assertion error:

    expected: <[achilles, patroclus, hector, patroclus, hector, hector, achilles, hector, achilles, hector, patroclus]>
     but was: <[achilles, patroclus, hector, patroclus, hector, hector, achilles, hector, achilles, hector, patroclus, achilles, hector]>
    
  5. ScottDugas commented on Apr 20, 2020

    @ScottDugas
    Collaborator

    I ran the ranked set consistency checker, but I'm not sure how to interpret it, adding it here for others' benefit:

    Consistency{consistent:false,
                level:1,
                prevCount:10,
                count:13,
                structure:'L0: '': 0,
                         '\x13\xef': 1,
                         '\x13\xf1': 1,
                         '\x13\xf4': 1,
                         '\x13\xf5': 1,
                         '\x13\xf7': 1,
                         '\x13\xfa': 1,
                         '\x13\xfc': 1,
                         '\x13\xfd': 1,
                         '\x13\xfe': 1,
                         '\x14': 1,
                         '\x15\x05': 1,
                         '\x15\x09': 1,
                         '\x15\x0a': 1
    L1: '': 10
    L2: '': 13
    L3: '': 13
    L4: '': 13
    L5: '': 10, '}
    
  6. alecgrieser commented on Apr 20, 2020

    @alecgrieser
    CollaboratorAuthor

    That certainly looks bad. Like L1 and L5 disagree with all the intermediate levels

  7. alecgrieser commented on Apr 20, 2020

    @alecgrieser
    CollaboratorAuthor

    Oh, RankIndexMaintainer queues its ranked index updates in parallel, and that operation isn't thread safe (on the same ranked set).

  8. alecgrieser commented on Apr 21, 2020

    @alecgrieser
    CollaboratorAuthor

    Yeah, so it looks like the test failure during the query was caused by a corrupt index, and the index is corrupted because the ranked set is not thread safe. This is only a problem if you have multiple keys being inserted with the same grouping key, so our (somewhat contrived) example of a FanOut index on a field with no grouping keys is sufficient. Hopefully, most real use cases on a FanOut index are doing something like adding a grouping column. However, if they didn't they might need to rebuild their indexes.

  9. added a commit that references this issue on Apr 21, 2020
    1269d61
  10. added a commit that references this issue on Apr 21, 2020
  11. added a commit that references this issue on Apr 22, 2020
  12. added a commit that references this issue on Apr 23, 2020
    95857ae
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions