Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-24597

RocksdbStateBackend getKeysAndNamespaces would return duplicate data when using MapState

    XMLWordPrintableJSON

Details

    Description

      For example, in RocksdbStateBackend , if we worked in VoidNamespace , and And use the ValueState like below .

                  // insert record
                  for (int i = 0; i < 3; ++i) {
                      keyedStateBackend.setCurrentKey(i);
                      testValueState.update(String.valueOf(i));
                  }
      

      Then we get all the keysAndNamespace according the method RocksDBKeyedStateBackend#getKeysAndNamespaces().The result of the traversal is
      <1,VoidNamespace>,<2,VoidNamespace>,<3,VoidNamespace> ,which is as expected.

      Thus,if we use MapState , and update the MapState with different user key, the getKeysAndNamespaces would return duplicate data with same keyAndNamespace.

                  // insert record
                  for (int i = 0; i < 3; ++i) {
                      keyedStateBackend.setCurrentKey(i);
                      mapState.put("userKeyA_" + i, "userValue");
                      mapState.put("userKeyB_" + i, "userValue");
                  }
      

      The result of the traversal is
      <1,VoidNamespace>,<1,VoidNamespace>,<2,VoidNamespace>,<2,VoidNamespace>,<3,VoidNamespace>,<3,VoidNamespace>.

      By reading the code, I found that the main reason for this problem is in the implementation of RocksStateKeysAndNamespaceIterator.
      In the hasNext method, when a new keyAndNamespace is created, there is no comparison with the previousKeyAndNamespace. So we can refer to RocksStateKeysIterator to implement the same logic should solve this problem.
       
       

      Attachments

        Issue Links

          Activity

            People

              mayuehappy Yue Ma
              mayuehappy Yue Ma
              Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: