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

Deleting state using KeyedStateBackend.getKeys() throws Exception

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • None
    • 1.5.0
    • None

    Description

      Adding this test to StateBackendTestBase showcases the problem:

      @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();
      	}
      }
      
      

      This should work because one of the use cases of getKeys() and applyToAllKeys() is to do stuff for every key, which includes deleting them.

      Attachments

        Issue Links

          Activity

            People

              sihuazhou Sihua Zhou
              aljoscha Aljoscha Krettek
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: