forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-8802] [QS] Fix concurrent access to non-duplicated serializers.
This closes apache#5691.
- Loading branch information
Showing
44 changed files
with
1,074 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
flink-runtime/src/main/java/org/apache/flink/runtime/query/KvStateEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.runtime.query; | ||
|
||
import org.apache.flink.annotation.Internal; | ||
import org.apache.flink.annotation.VisibleForTesting; | ||
import org.apache.flink.runtime.state.internal.InternalKvState; | ||
import org.apache.flink.util.Preconditions; | ||
|
||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
/** | ||
* An entry holding the {@link InternalKvState} along with its {@link KvStateInfo}. | ||
* | ||
* @param <K> The type of key the state is associated to | ||
* @param <N> The type of the namespace the state is associated to | ||
* @param <V> The type of values kept internally in state | ||
*/ | ||
@Internal | ||
public class KvStateEntry<K, N, V> { | ||
|
||
private final InternalKvState<K, N, V> state; | ||
private final KvStateInfo<K, N, V> stateInfo; | ||
|
||
private final boolean areSerializersStateless; | ||
|
||
private final ConcurrentMap<Thread, KvStateInfo<K, N, V>> serializerCache; | ||
|
||
public KvStateEntry(final InternalKvState<K, N, V> state) { | ||
this.state = Preconditions.checkNotNull(state); | ||
this.stateInfo = new KvStateInfo<>( | ||
state.getKeySerializer(), | ||
state.getNamespaceSerializer(), | ||
state.getValueSerializer() | ||
); | ||
this.serializerCache = new ConcurrentHashMap<>(); | ||
this.areSerializersStateless = stateInfo.duplicate() == stateInfo; | ||
} | ||
|
||
public InternalKvState<K, N, V> getState() { | ||
return state; | ||
} | ||
|
||
public KvStateInfo<K, N, V> getInfoForCurrentThread() { | ||
return areSerializersStateless | ||
? stateInfo | ||
: serializerCache.computeIfAbsent(Thread.currentThread(), t -> stateInfo.duplicate()); | ||
} | ||
|
||
public void clear() { | ||
serializerCache.clear(); | ||
} | ||
|
||
@VisibleForTesting | ||
public int getCacheSize() { | ||
return serializerCache.size(); | ||
} | ||
} |
Oops, something went wrong.