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

    https://github.com/apache/flink/pull/5645#discussion_r172911926
  
    --- Diff: 
flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/typeutils/AvroSerializer.java
 ---
    @@ -163,8 +224,19 @@ public T copy(T from, T reuse) {
     
        @Override
        public void copy(DataInputView source, DataOutputView target) throws 
IOException {
    -           T value = deserialize(source);
    -           serialize(value, target);
    +           if (CONCURRENT_ACCESS_CHECK) {
    +                   enterExclusiveThread();
    +           }
    +
    +           try {
    +                   T value = deserialize(source);
    --- End diff --
    
    An alternative would be to do the following, but I would honestly not do 
that. This is a heuristic anyways (otherwise we would need to use CAS on the 
`currentThread` field).
    
    ```java
    private void enterExclusiveThread() {
        Thread previous = currentThread;
        Thread thisThread = Thread.currentThread();
        if (previous == null) {
                reEntranceDepth = 1;
                currentThread = thisThread;
        }
        else if (previous == thisThread) {
                reEntranceDepth++;
        }
        else {
                throw new IllegalStateException(
                                "Concurrent access to KryoSerializer. Thread 1: 
" + thisThread.getName() +
                                                " , Thread 2: " + 
previous.getName());
        }
    }
    
    private void exitExclusiveThread() {
        if (--reEntranceDepth == 0) {
                currentThread = null;
        }
    }
    ```


---

Reply via email to