[
https://issues.apache.org/jira/browse/FLINK-9060?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16412978#comment-16412978
]
ASF GitHub Bot commented on FLINK-9060:
---------------------------------------
Github user sihuazhou commented on the issue:
https://github.com/apache/flink/pull/5751
Hi @kl0u , I have changed the code to meet the comments on JIRA, but
unfortunately, I found some case that could make the situation a bit complex
with that architecture, that is maybe the `State.clear()` is not the last
invocation on the state, for example:
```java
void process() {
/*stuff before state.clear() */
state.clear()
/*stuff after state.clear()*/
Integer value = state.get(); // this should return the default value
of ValueState or null if default value if not setted
state.update(1); // this will re-add the state
}
```
So, if we want to wrapper the state, we need do some works on the almost
state's almost every api, not only the `clear()`, and the `list` that was used
to store the cleared `keys` now has to be changed to `set` (because we need
check whether a `key` has been cleared and also maybe remove it from the
cleared keyset). I think this maybe a bit expensive, now I am a bit like to go
back the simplest way to store the `keys` into a `list`, and loop the list to
perform `process()`, what do you think?
> Deleting state using KeyedStateBackend.getKeys() throws Exception
> -----------------------------------------------------------------
>
> Key: FLINK-9060
> URL: https://issues.apache.org/jira/browse/FLINK-9060
> Project: Flink
> Issue Type: Bug
> Components: State Backends, Checkpointing
> Reporter: Aljoscha Krettek
> Assignee: Sihua Zhou
> Priority: Blocker
> Fix For: 1.5.0
>
>
> Adding this test to {{StateBackendTestBase}} showcases the problem:
> {code}
> @Test
> public void testConcurrentModificationWithGetKeys() throws Exception {
> AbstractKeyedStateBackend<Integer> backend =
> createKeyedBackend(IntSerializer.INSTANCE);
> try {
> ListStateDescriptor<String> listStateDescriptor =
> new ListStateDescriptor<>("foo",
> StringSerializer.INSTANCE);
> backend.setCurrentKey(1);
> backend
> .getPartitionedState(VoidNamespace.INSTANCE,
> VoidNamespaceSerializer.INSTANCE, listStateDescriptor)
> .add("Hello");
> backend.setCurrentKey(2);
> backend
> .getPartitionedState(VoidNamespace.INSTANCE,
> VoidNamespaceSerializer.INSTANCE, listStateDescriptor)
> .add("Ciao");
> Stream<Integer> keys = backend
> .getKeys(listStateDescriptor.getName(),
> VoidNamespace.INSTANCE);
> keys.forEach((key) -> {
> backend.setCurrentKey(key);
> try {
> backend
> .getPartitionedState(
> VoidNamespace.INSTANCE,
>
> VoidNamespaceSerializer.INSTANCE,
> listStateDescriptor)
> .clear();
> } catch (Exception e) {
> e.printStackTrace();
> }
> });
> }
> finally {
> IOUtils.closeQuietly(backend);
> backend.dispose();
> }
> }
> {code}
> This should work because one of the use cases of {{getKeys()}} and
> {{applyToAllKeys()}} is to do stuff for every key, which includes deleting
> them.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)