Github user aljoscha commented on a diff in the pull request:

    https://github.com/apache/flink/pull/5230#discussion_r166337384
  
    --- Diff: 
flink-runtime/src/main/java/org/apache/flink/runtime/state/KeyedStateBackend.java
 ---
    @@ -38,6 +38,37 @@
         */
        void setCurrentKey(K newKey);
     
    +   /**
    +    * Returns a safe version of the current key (see {@link 
#setCurrentKey(Object)}).
    +    *
    +    * <p>"Safe" means that the user can interact with it without 
jeopardizing correctness.
    +    * This implies that:
    +    * <ol>
    +    *     <li>for the {@code MemoryStateBackend} and the {@code 
FsStateBackend} we
    +    *     return a <b>copy</b> of the actual key, while
    +    *     <li>for the {@code RocksDBStateBackend} we return the key 
itself, as returned
    +    *     by the backend.
    +    * </ol>
    +    *
    +    * <p>The copy is created using the {@link TypeSerializer#copy(Object) 
copy()} method
    +    * of the key {@link TypeSerializer}. Consequently, the correctness of 
the method assumes
    +    * a correct {@code copy()} method.
    +    *
    +    */
    +   K getCurrentKeySafe();
    --- End diff --
    
    I think we don't need this since the methods on broadcast state also don't 
make sure that returned values are safe, i.e. if a user modifies the value they 
break things. In the other parts we document in the Javadoc that users 
shouldn't modify the value, I think we can go down the same route here, which 
makes iteration over all keys cheaper.


---

Reply via email to