Uploaded image for project: 'Kylin'
  1. Kylin
  2. KYLIN-4397

Use newLinkedHashMap in AssignmentUtil.java

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • v3.1.0, v3.0.2
    • Real-time Streaming
    • None

    Description

      The tests in org.apache.kylin.stream.coordinator.assign.DefaultAssignerTest#reBalanceTest can fail and the failure is presented as follow.

      java.lang.AssertionError: expected:<2> but was:<1>

      at org.apache.kylin.stream.coordinator.assign.DefaultAssignerTest.reBalanceTest(DefaultAssignerTest.java:165) when executing assertEquals(2, rsAssignment.size());

       

      The root cause of this failure is when executing Map<Integer, Map<String, List<Partition>>> result = assigner.reBalancePlan(rsList, cubes, existingAssignments); it will iterate over a HashMap. The stack trace is here:

      java.util.HashMap$EntrySet.iterator(HashMap.java:1014)
      org.apache.kylin.stream.coordinator.assign.DefaultAssigner.reBalancePlan(DefaultAssigner.java:93)
      org.apache.kylin.stream.coordinator.assign.DefaultAssignerTest.reBalanceTest(DefaultAssignerTest.java:163)_

      The specification about HashMap says that "this class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time". The documentation is here for your reference: https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.htm[l|https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html]

      The fix is to use LinkedHashMap instead of HashMap when initializing a Map. In this way, the non-deterministic behaviour is eliminated and the test will not suffer from the failure again. The code will be more stable.

       

      Attachments

        Issue Links

          Activity

            People

              cpugputpu cpugputpu
              cpugputpu cpugputpu
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: