Uploaded image for project: 'Apache IoTDB'
  1. Apache IoTDB
  2. IOTDB-1572

Should not change object's state in toString()

    XMLWordPrintableJSON

Details

    Description

      I meet a strange problem.
      When I debug memtable flushing, I do as follows:
      1. insert into root.a.c(time,s1) values (207,2)
      2. insert into root.a.c(time,s1) values (203,2)
      According to the code logic, after the second insertion complete, the "sorted" in TVList should be false.
      But, every time when I look into the value of "sorted" in TVList from memChunk, where the debug breakpoint in, it's always true!
      I am sure there is no flush or query be triggered between the insertion and breakpoint.
      After several hours' efforts, I found the cause:
      1. When debuging, IDEA will invoke Object's toString() method by default.
      2. This kind of invoke cannot be suspended by breakpoint
      3. In WritableMemChunk's toString() method, getSortedTVListForQuery() has been invoked, which will trigger a sorting in TVList, has been invoked. And after sorting, "sorted" will be set to true...

      Certainly, it's not a bug and can be bypassed by disable IDEA's auto invoking.
      In my opinion, it's better not to change object's state in toString method, after all, toString is a representation of object's current state, it should be a method sth like read-only.

      At last, WritableMemChunk's toString() method only want to print the min and max point, which can be found with a simple traversal.

       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              xinzhongtianxia xinzhongtianxia
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: