You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/09/17 07:42:19 UTC

[GitHub] [flink] dawidwys opened a new pull request #13405: [FLINK-19270] Extract InternalKeyedStateBackend interface

dawidwys opened a new pull request #13405:
URL: https://github.com/apache/flink/pull/13405


   
   ## What is the purpose of the change
   
   This commit extracts a minimal interface from AbstractKeyedStateBackend.
   This interface is returned by StateBackend interface, making it easier
   to implement custom keyed state backend without pulling in all the logic
   of AbstractKeyedStateBackend.
   
   
   ## Verifying this change
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (yes / **no**)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (**yes** / no)
     - The serializers: (yes / **no** / don't know)
     - The runtime per-record code paths (performance sensitive): (yes / **no** / don't know)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn/Mesos, ZooKeeper: (yes / **no** / don't know)
     - The S3 file system connector: (yes / **no** / don't know)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (yes / **no**)
     - If yes, how is the feature documented? (not applicable / docs / **JavaDocs** / not documented)
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13405:
URL: https://github.com/apache/flink/pull/13405#issuecomment-694066808


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6590",
       "triggerID" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "triggerType" : "PUSH"
     }, {
       "hash" : "bea6d1034a41f1c38afdb73d6c0875eba61f924e",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6685",
       "triggerID" : "bea6d1034a41f1c38afdb73d6c0875eba61f924e",
       "triggerType" : "PUSH"
     }, {
       "hash" : "4089ed32d6d11831ef0434356da061868a2bf568",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6692",
       "triggerID" : "4089ed32d6d11831ef0434356da061868a2bf568",
       "triggerType" : "PUSH"
     }, {
       "hash" : "85bf458f7889a735f9abda895cb699862fb66659",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6700",
       "triggerID" : "85bf458f7889a735f9abda895cb699862fb66659",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * bea6d1034a41f1c38afdb73d6c0875eba61f924e Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6685) 
   * 4089ed32d6d11831ef0434356da061868a2bf568 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6692) 
   * 85bf458f7889a735f9abda895cb699862fb66659 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6700) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13405:
URL: https://github.com/apache/flink/pull/13405#issuecomment-694066808


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6590",
       "triggerID" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "triggerType" : "PUSH"
     }, {
       "hash" : "bea6d1034a41f1c38afdb73d6c0875eba61f924e",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6685",
       "triggerID" : "bea6d1034a41f1c38afdb73d6c0875eba61f924e",
       "triggerType" : "PUSH"
     }, {
       "hash" : "4089ed32d6d11831ef0434356da061868a2bf568",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6692",
       "triggerID" : "4089ed32d6d11831ef0434356da061868a2bf568",
       "triggerType" : "PUSH"
     }, {
       "hash" : "85bf458f7889a735f9abda895cb699862fb66659",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "85bf458f7889a735f9abda895cb699862fb66659",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * bea6d1034a41f1c38afdb73d6c0875eba61f924e Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6685) 
   * 4089ed32d6d11831ef0434356da061868a2bf568 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6692) 
   * 85bf458f7889a735f9abda895cb699862fb66659 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] dawidwys commented on a change in pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
dawidwys commented on a change in pull request #13405:
URL: https://github.com/apache/flink/pull/13405#discussion_r492679948



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java
##########
@@ -282,8 +283,8 @@ public void setCurrentKey(Object key) {
 		if (keyedStateBackend != null) {
 			try {
 				// need to work around type restrictions
-				@SuppressWarnings("unchecked,rawtypes")
-				AbstractKeyedStateBackend rawBackend = (AbstractKeyedStateBackend) keyedStateBackend;
+				@SuppressWarnings("rawtypes")
+				CheckpointableKeyedStateBackend rawBackend = keyedStateBackend;
 
 				rawBackend.setCurrentKey(key);

Review comment:
       ![suppress](https://user-images.githubusercontent.com/6242259/93879881-d4b72b00-fcdc-11ea-94c0-2030895acf4c.png)
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13405:
URL: https://github.com/apache/flink/pull/13405#issuecomment-694066808






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] carp84 commented on a change in pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
carp84 commented on a change in pull request #13405:
URL: https://github.com/apache/flink/pull/13405#discussion_r492023475



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java
##########
@@ -217,14 +218,14 @@ void snapshotState(
 	}
 
 	public void notifyCheckpointComplete(long checkpointId) throws Exception {
-		if (keyedStateBackend != null) {
-			keyedStateBackend.notifyCheckpointComplete(checkpointId);
+		if (keyedStateBackend != null && keyedStateBackend instanceof CheckpointListener) {

Review comment:
       ```suggestion
   		if (keyedStateBackend instanceof CheckpointListener) {
   ```
   
   Since the `instanceof` operator always returns `false` for `null`, there is no need to have an additional null check.

##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java
##########
@@ -282,8 +283,8 @@ public void setCurrentKey(Object key) {
 		if (keyedStateBackend != null) {
 			try {
 				// need to work around type restrictions
-				@SuppressWarnings("unchecked,rawtypes")
-				AbstractKeyedStateBackend rawBackend = (AbstractKeyedStateBackend) keyedStateBackend;
+				@SuppressWarnings("rawtypes")
+				CheckpointableKeyedStateBackend rawBackend = keyedStateBackend;
 
 				rawBackend.setCurrentKey(key);

Review comment:
       ```suggestion
   				((CheckpointableKeyedStateBackend) keyedStateBackend).setCurrentKey(key);
   ```
   We could also remove "rawtypes" from the warning suppression of the method.

##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java
##########
@@ -217,14 +218,14 @@ void snapshotState(
 	}
 
 	public void notifyCheckpointComplete(long checkpointId) throws Exception {
-		if (keyedStateBackend != null) {
-			keyedStateBackend.notifyCheckpointComplete(checkpointId);
+		if (keyedStateBackend != null && keyedStateBackend instanceof CheckpointListener) {
+			((CheckpointListener) keyedStateBackend).notifyCheckpointComplete(checkpointId);
 		}
 	}
 
 	public void notifyCheckpointAborted(long checkpointId) throws Exception {
-		if (keyedStateBackend != null) {
-			keyedStateBackend.notifyCheckpointAborted(checkpointId);
+		if (keyedStateBackend != null && keyedStateBackend instanceof CheckpointListener) {

Review comment:
       ```suggestion
   		if (keyedStateBackend instanceof CheckpointListener) {
   ```
   Ditto.

##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/InternalTimeServiceManager.java
##########
@@ -74,19 +74,16 @@
 
 	private final Map<String, InternalTimerServiceImpl<K, ?>> timerServices;
 
-	private final boolean useLegacySynchronousSnapshots;
-
 	InternalTimeServiceManager(
-		KeyGroupRange localKeyGroupRange,
-		KeyContext keyContext,
-		PriorityQueueSetFactory priorityQueueSetFactory,
-		ProcessingTimeService processingTimeService, boolean useLegacySynchronousSnapshots) {

Review comment:
       It seems after the changes made for FLINK-16316 the `useLegacySynchronousSnapshots` field here is never accessed? I'm also +1 for keeping the private field and use it in `snapshotState` to save the cost of `instanceof` when calling `requiresLegacySynchronousTimerSnapshots` for RocksDB backend.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] aljoscha commented on a change in pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
aljoscha commented on a change in pull request #13405:
URL: https://github.com/apache/flink/pull/13405#discussion_r492676606



##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/state/CheckpointableKeyedStateBackend.java
##########
@@ -0,0 +1,42 @@
+/*
+ * 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
+ *
+ *     http://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.state;
+
+import java.io.Closeable;
+
+/**
+ * Interface that combines both, the {@link KeyedStateBackend} interface, which encapsulates methods
+ * responsible for keyed state management and the {@link SnapshotStrategy} which tells the system
+ * how to snapshot the underlying state.
+ *
+ * <p><b>NOTE:</b> Implementations of this class can be notified about a checkpoint result it can additionally implement
+ * the {@link CheckpointListener} interface.
+ *
+ * @param <K> The key by which state is keyed.
+ */

Review comment:
       ```suggestion
    * <p><b>NOTE:</b> State backends that need to be notified of completed checkpoints can additionally implement
    * the {@link CheckpointListener} interface.
    *
    * @param <K> Type of the key by which state is keyed.
    */
   ```
   Formatting is probably not correct after my changes but I think the previous sentence was not grammatically correct.

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/state/CheckpointableKeyedStateBackend.java
##########
@@ -0,0 +1,42 @@
+/*
+ * 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
+ *
+ *     http://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.state;
+
+import java.io.Closeable;
+
+/**
+ * Interface that combines both, the {@link KeyedStateBackend} interface, which encapsulates methods
+ * responsible for keyed state management and the {@link SnapshotStrategy} which tells the system
+ * how to snapshot the underlying state.
+ *
+ * <p><b>NOTE:</b> Implementations of this class can be notified about a checkpoint result it can additionally implement
+ * the {@link CheckpointListener} interface.
+ *
+ * @param <K> The key by which state is keyed.
+ */
+public interface CheckpointableKeyedStateBackend<K> extends
+		KeyedStateBackend<K>,
+		SnapshotStrategy<SnapshotResult<KeyedStateHandle>>,
+		Closeable {
+
+	/**
+	 * Returns the key groups which the state backend is responsible for.

Review comment:
       ```suggestion
   	 * Returns the key groups which this state backend is responsible for.
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] dawidwys commented on a change in pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
dawidwys commented on a change in pull request #13405:
URL: https://github.com/apache/flink/pull/13405#discussion_r491971571



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/InternalTimeServiceManager.java
##########
@@ -74,19 +74,16 @@
 
 	private final Map<String, InternalTimerServiceImpl<K, ?>> timerServices;
 
-	private final boolean useLegacySynchronousSnapshots;
-
 	InternalTimeServiceManager(
-		KeyGroupRange localKeyGroupRange,
-		KeyContext keyContext,
-		PriorityQueueSetFactory priorityQueueSetFactory,
-		ProcessingTimeService processingTimeService, boolean useLegacySynchronousSnapshots) {

Review comment:
       It can. Let me explain it though, why I think it is unnecessary in the ctor. (There is one thing I forgot in the PR, I wanted to make the `snapshotStateForKeyGroup` private. It is used only in the `InternalTimeServiceManager#snapshotState`.)
   
   The flag is used only in the `snapshotStateForKeyGroup` which is used only in the `snapshotState` method. The `snapshotState` method looks like:
   ```
   	public void snapshotState(
   			KeyedStateBackend<?> keyedStateBackend,
   			StateSnapshotContext context,
   			String operatorName) throws Exception {
   		//TODO all of this can be removed once heap-based timers are integrated with RocksDB incremental snapshots
   		if (keyedStateBackend instanceof AbstractKeyedStateBackend &&
   			((AbstractKeyedStateBackend<?>) keyedStateBackend).requiresLegacySynchronousTimerSnapshots()) {
   
               ....
   			snapshotStateForKeyGroup(new DataOutputViewStreamWrapper(out), keyGroupIdx);
               ....
   		}
   	}
   ```
   
   Effectively this flag is checked twice. Once in the preconditions against the value in ctor and the second time in the `snapshotState` method against the value set in the `KeyedStateBackend`. In my opinion the one time in the `snapshotState` is enough.
   
   The only case when the condition in `snapshotStateForKeyGroup` could fail is if we created the `InternalTimeServiceManager` from a different `KeyedStateBackend` than we use for snapshotting. I am quite sure this would let to way more problems than only this precondition failling.
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] dawidwys commented on a change in pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
dawidwys commented on a change in pull request #13405:
URL: https://github.com/apache/flink/pull/13405#discussion_r492649792



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java
##########
@@ -282,8 +283,8 @@ public void setCurrentKey(Object key) {
 		if (keyedStateBackend != null) {
 			try {
 				// need to work around type restrictions
-				@SuppressWarnings("unchecked,rawtypes")
-				AbstractKeyedStateBackend rawBackend = (AbstractKeyedStateBackend) keyedStateBackend;
+				@SuppressWarnings("rawtypes")
+				CheckpointableKeyedStateBackend rawBackend = keyedStateBackend;
 
 				rawBackend.setCurrentKey(key);

Review comment:
       mine, shows it as a warning.
   
   We are using the `CheckpointableKeyedStateBackend` as a raw type, without the key, so there should be a warning.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] dawidwys commented on a change in pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
dawidwys commented on a change in pull request #13405:
URL: https://github.com/apache/flink/pull/13405#discussion_r491971571



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/InternalTimeServiceManager.java
##########
@@ -74,19 +74,16 @@
 
 	private final Map<String, InternalTimerServiceImpl<K, ?>> timerServices;
 
-	private final boolean useLegacySynchronousSnapshots;
-
 	InternalTimeServiceManager(
-		KeyGroupRange localKeyGroupRange,
-		KeyContext keyContext,
-		PriorityQueueSetFactory priorityQueueSetFactory,
-		ProcessingTimeService processingTimeService, boolean useLegacySynchronousSnapshots) {

Review comment:
       It can. Let me explain it though, why I think it is unnecessary in the ctor. (There is one thing I forgot in the PR, I wanted to make the `snapshotStateForKeyGroup` private. It is used only in the `InternalTimeServiceManager#snapshotState`.)
   
   The flag is used only in the `snapshotStateForKeyGroup` which is used only in the `snapshotState` method. The `snapshotState` method looks like:
   ```
   	public void snapshotState(
   			KeyedStateBackend<?> keyedStateBackend,
   			StateSnapshotContext context,
   			String operatorName) throws Exception {
   		//TODO all of this can be removed once heap-based timers are integrated with RocksDB incremental snapshots
   		if (keyedStateBackend instanceof AbstractKeyedStateBackend &&
   			((AbstractKeyedStateBackend<?>) keyedStateBackend).requiresLegacySynchronousTimerSnapshots()) {
   
               ....
   			snapshotStateForKeyGroup(new DataOutputViewStreamWrapper(out), keyGroupIdx);
               ....
   		}
   	}
   ```
   
   Effectively this flag is checked twice. Once in the preconditions against the value in ctor and the second time in the `snapshotState` method against the value set in the `KeyedStateBackend`. In my opinion the one time in the `snapshotState` is enough.
   
   The only case when the condition in `snapshotStateForKeyGroup` could fail is if we created the `InternalTimeServiceManager` from a different `KeyedStateBackend` than we use for snapshotting. I am quite sure this would let to way more problems than only this precondition failling.
   

##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/InternalTimeServiceManager.java
##########
@@ -74,19 +74,16 @@
 
 	private final Map<String, InternalTimerServiceImpl<K, ?>> timerServices;
 
-	private final boolean useLegacySynchronousSnapshots;
-
 	InternalTimeServiceManager(
-		KeyGroupRange localKeyGroupRange,
-		KeyContext keyContext,
-		PriorityQueueSetFactory priorityQueueSetFactory,
-		ProcessingTimeService processingTimeService, boolean useLegacySynchronousSnapshots) {

Review comment:
       It can. Let me explain it though, why I think it is unnecessary in the ctor. (There is one thing I forgot in the PR, I wanted to make the `snapshotStateForKeyGroup` private. It is used only in the `InternalTimeServiceManager#snapshotState`.)
   
   The flag is used only in the `snapshotStateForKeyGroup` which is used only in the `snapshotState` method. The `snapshotState` method looks like:
   ```
   	public void snapshotState(
   			KeyedStateBackend<?> keyedStateBackend,
   			StateSnapshotContext context,
   			String operatorName) throws Exception {
   		//TODO all of this can be removed once heap-based timers are integrated with RocksDB incremental snapshots
   		if (keyedStateBackend instanceof AbstractKeyedStateBackend &&
   			((AbstractKeyedStateBackend<?>) keyedStateBackend).requiresLegacySynchronousTimerSnapshots()) {
   
               ....
   			snapshotStateForKeyGroup(new DataOutputViewStreamWrapper(out), keyGroupIdx);
               ....
   		}
   	}
   ```
   
   Effectively this flag is checked twice. Once in the preconditions against the value passed in the ctor and the second time in the `snapshotState` method against the value set in the passed `KeyedStateBackend`. In my opinion the one time in the `snapshotState` is enough.
   
   The only case when the condition in `snapshotStateForKeyGroup` could fail is if we created the `InternalTimeServiceManager` from a different `KeyedStateBackend` than we use for snapshotting. I am quite sure this would let to way more problems than only this precondition failling.
   

##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/InternalTimeServiceManager.java
##########
@@ -74,19 +74,16 @@
 
 	private final Map<String, InternalTimerServiceImpl<K, ?>> timerServices;
 
-	private final boolean useLegacySynchronousSnapshots;
-
 	InternalTimeServiceManager(
-		KeyGroupRange localKeyGroupRange,
-		KeyContext keyContext,
-		PriorityQueueSetFactory priorityQueueSetFactory,
-		ProcessingTimeService processingTimeService, boolean useLegacySynchronousSnapshots) {

Review comment:
       It can. Let me explain it though, why I think it is unnecessary in the ctor. (There is one thing I forgot in the PR, I wanted to make the `snapshotStateForKeyGroup` private. It is used only in the `InternalTimeServiceManager#snapshotState`.)
   
   The flag is used only in the `snapshotStateForKeyGroup` which is used only in the `snapshotState` method. The `snapshotState` method looks like:
   ```
   	public void snapshotState(
   			KeyedStateBackend<?> keyedStateBackend,
   			StateSnapshotContext context,
   			String operatorName) throws Exception {
   		//TODO all of this can be removed once heap-based timers are integrated with RocksDB incremental snapshots
   		if (keyedStateBackend instanceof AbstractKeyedStateBackend &&
   			((AbstractKeyedStateBackend<?>) keyedStateBackend).requiresLegacySynchronousTimerSnapshots()) {
   
               ....
   			snapshotStateForKeyGroup(new DataOutputViewStreamWrapper(out), keyGroupIdx);
               ....
   		}
   	}
   ```
   
   Effectively this flag is checked twice. Once in the preconditions against the value passed in the ctor and the second time in the `snapshotState` method against the value set in the passed `KeyedStateBackend`. In my opinion the one time in the `snapshotState` is enough.
   
   The only case when the condition in `snapshotStateForKeyGroup` could fail is if we created the `InternalTimeServiceManager` from a different `KeyedStateBackend` than we use for snapshotting. I am quite sure this would lead to way more problems than only this precondition failling.
   

##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java
##########
@@ -282,8 +283,8 @@ public void setCurrentKey(Object key) {
 		if (keyedStateBackend != null) {
 			try {
 				// need to work around type restrictions
-				@SuppressWarnings("unchecked,rawtypes")
-				AbstractKeyedStateBackend rawBackend = (AbstractKeyedStateBackend) keyedStateBackend;
+				@SuppressWarnings("rawtypes")
+				CheckpointableKeyedStateBackend rawBackend = keyedStateBackend;
 
 				rawBackend.setCurrentKey(key);

Review comment:
       In this line, we actually can not remove the "rawtypes" suppression. We can remove it from the method annotation though. I will do that.

##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java
##########
@@ -217,14 +218,14 @@ void snapshotState(
 	}
 
 	public void notifyCheckpointComplete(long checkpointId) throws Exception {
-		if (keyedStateBackend != null) {
-			keyedStateBackend.notifyCheckpointComplete(checkpointId);
+		if (keyedStateBackend != null && keyedStateBackend instanceof CheckpointListener) {

Review comment:
       Makes sense.

##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/InternalTimeServiceManager.java
##########
@@ -74,19 +74,16 @@
 
 	private final Map<String, InternalTimerServiceImpl<K, ?>> timerServices;
 
-	private final boolean useLegacySynchronousSnapshots;
-
 	InternalTimeServiceManager(
-		KeyGroupRange localKeyGroupRange,
-		KeyContext keyContext,
-		PriorityQueueSetFactory priorityQueueSetFactory,
-		ProcessingTimeService processingTimeService, boolean useLegacySynchronousSnapshots) {

Review comment:
       I think I changed it the way you suggested @carp84
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13405:
URL: https://github.com/apache/flink/pull/13405#issuecomment-694066808


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6590",
       "triggerID" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "triggerType" : "PUSH"
     }, {
       "hash" : "bea6d1034a41f1c38afdb73d6c0875eba61f924e",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6685",
       "triggerID" : "bea6d1034a41f1c38afdb73d6c0875eba61f924e",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * bea6d1034a41f1c38afdb73d6c0875eba61f924e Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6685) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13405:
URL: https://github.com/apache/flink/pull/13405#issuecomment-694066808


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6590",
       "triggerID" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 835077d91fd63313743cfff3a30e74fd0b44f9af Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6590) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] dawidwys commented on pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
dawidwys commented on pull request #13405:
URL: https://github.com/apache/flink/pull/13405#issuecomment-696625513


   Could you have another look @carp84 @aljoscha ?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] dawidwys commented on a change in pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
dawidwys commented on a change in pull request #13405:
URL: https://github.com/apache/flink/pull/13405#discussion_r492649792



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java
##########
@@ -282,8 +283,8 @@ public void setCurrentKey(Object key) {
 		if (keyedStateBackend != null) {
 			try {
 				// need to work around type restrictions
-				@SuppressWarnings("unchecked,rawtypes")
-				AbstractKeyedStateBackend rawBackend = (AbstractKeyedStateBackend) keyedStateBackend;
+				@SuppressWarnings("rawtypes")
+				CheckpointableKeyedStateBackend rawBackend = keyedStateBackend;
 
 				rawBackend.setCurrentKey(key);

Review comment:
       mine, shows it as a warning.
   
   We are using the `CheckpointableKeyedStateBackend` as a raw type, without the key, so there should be a warning.
   
   The `keyedStateBackend` is of type `CheckpointableKeyedStateBackend<?>` so we have a signature like: `setCurrentKey(? key)`, which cannot be satisfied. Therefore we need to cast it to a raw type.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] aljoscha commented on a change in pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
aljoscha commented on a change in pull request #13405:
URL: https://github.com/apache/flink/pull/13405#discussion_r491936770



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/InternalTimeServiceManager.java
##########
@@ -74,19 +74,16 @@
 
 	private final Map<String, InternalTimerServiceImpl<K, ?>> timerServices;
 
-	private final boolean useLegacySynchronousSnapshots;
-
 	InternalTimeServiceManager(
-		KeyGroupRange localKeyGroupRange,
-		KeyContext keyContext,
-		PriorityQueueSetFactory priorityQueueSetFactory,
-		ProcessingTimeService processingTimeService, boolean useLegacySynchronousSnapshots) {

Review comment:
       Why is `useLegacySynchronousSnapshots` removed here? Can't `RocksDBKeyedStateBackend.requiresLegacySynchronousTimerSnapshots()` still return true here?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13405:
URL: https://github.com/apache/flink/pull/13405#issuecomment-694066808


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6590",
       "triggerID" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "triggerType" : "PUSH"
     }, {
       "hash" : "bea6d1034a41f1c38afdb73d6c0875eba61f924e",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6685",
       "triggerID" : "bea6d1034a41f1c38afdb73d6c0875eba61f924e",
       "triggerType" : "PUSH"
     }, {
       "hash" : "4089ed32d6d11831ef0434356da061868a2bf568",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6692",
       "triggerID" : "4089ed32d6d11831ef0434356da061868a2bf568",
       "triggerType" : "PUSH"
     }, {
       "hash" : "85bf458f7889a735f9abda895cb699862fb66659",
       "status" : "CANCELED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6700",
       "triggerID" : "85bf458f7889a735f9abda895cb699862fb66659",
       "triggerType" : "PUSH"
     }, {
       "hash" : "ec745aa11eb24be7e2bfc6bb5da93f2e24a1e6cc",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6713",
       "triggerID" : "ec745aa11eb24be7e2bfc6bb5da93f2e24a1e6cc",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 85bf458f7889a735f9abda895cb699862fb66659 Azure: [CANCELED](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6700) 
   * ec745aa11eb24be7e2bfc6bb5da93f2e24a1e6cc Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6713) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot commented on pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
flinkbot commented on pull request #13405:
URL: https://github.com/apache/flink/pull/13405#issuecomment-694050574


   Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
   to review your pull request. We will use this comment to track the progress of the review.
   
   
   ## Automated Checks
   Last check on commit 835077d91fd63313743cfff3a30e74fd0b44f9af (Thu Sep 17 07:43:58 UTC 2020)
   
   **Warnings:**
    * No documentation files were touched! Remember to keep the Flink docs up to date!
   
   
   <sub>Mention the bot in a comment to re-run the automated checks.</sub>
   ## Review Progress
   
   * ❓ 1. The [description] looks good.
   * ❓ 2. There is [consensus] that the contribution should go into to Flink.
   * ❓ 3. Needs [attention] from.
   * ❓ 4. The change fits into the overall [architecture].
   * ❓ 5. Overall code [quality] is good.
   
   Please see the [Pull Request Review Guide](https://flink.apache.org/contributing/reviewing-prs.html) for a full explanation of the review process.<details>
    The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot approve description` to approve one or more aspects (aspects: `description`, `consensus`, `architecture` and `quality`)
    - `@flinkbot approve all` to approve all aspects
    - `@flinkbot approve-until architecture` to approve everything until `architecture`
    - `@flinkbot attention @username1 [@username2 ..]` to require somebody's attention
    - `@flinkbot disapprove architecture` to remove an approval you gave earlier
   </details>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] dawidwys commented on a change in pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
dawidwys commented on a change in pull request #13405:
URL: https://github.com/apache/flink/pull/13405#discussion_r492678054



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java
##########
@@ -282,8 +283,8 @@ public void setCurrentKey(Object key) {
 		if (keyedStateBackend != null) {
 			try {
 				// need to work around type restrictions
-				@SuppressWarnings("unchecked,rawtypes")
-				AbstractKeyedStateBackend rawBackend = (AbstractKeyedStateBackend) keyedStateBackend;
+				@SuppressWarnings("rawtypes")
+				CheckpointableKeyedStateBackend rawBackend = keyedStateBackend;
 
 				rawBackend.setCurrentKey(key);

Review comment:
       The "unchecked" suppressed the cast. The "rawtypes" suppresses the call to `setCurrentKey` on raw type.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] carp84 commented on a change in pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
carp84 commented on a change in pull request #13405:
URL: https://github.com/apache/flink/pull/13405#discussion_r492023475



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java
##########
@@ -217,14 +218,14 @@ void snapshotState(
 	}
 
 	public void notifyCheckpointComplete(long checkpointId) throws Exception {
-		if (keyedStateBackend != null) {
-			keyedStateBackend.notifyCheckpointComplete(checkpointId);
+		if (keyedStateBackend != null && keyedStateBackend instanceof CheckpointListener) {

Review comment:
       ```suggestion
   		if (keyedStateBackend instanceof CheckpointListener) {
   ```
   
   Since the `instanceof` operator always returns `false` for `null`, there is no need to have an additional null check.

##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java
##########
@@ -282,8 +283,8 @@ public void setCurrentKey(Object key) {
 		if (keyedStateBackend != null) {
 			try {
 				// need to work around type restrictions
-				@SuppressWarnings("unchecked,rawtypes")
-				AbstractKeyedStateBackend rawBackend = (AbstractKeyedStateBackend) keyedStateBackend;
+				@SuppressWarnings("rawtypes")
+				CheckpointableKeyedStateBackend rawBackend = keyedStateBackend;
 
 				rawBackend.setCurrentKey(key);

Review comment:
       ```suggestion
   				((CheckpointableKeyedStateBackend) keyedStateBackend).setCurrentKey(key);
   ```
   We could also remove "rawtypes" from the warning suppression of the method.

##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java
##########
@@ -217,14 +218,14 @@ void snapshotState(
 	}
 
 	public void notifyCheckpointComplete(long checkpointId) throws Exception {
-		if (keyedStateBackend != null) {
-			keyedStateBackend.notifyCheckpointComplete(checkpointId);
+		if (keyedStateBackend != null && keyedStateBackend instanceof CheckpointListener) {
+			((CheckpointListener) keyedStateBackend).notifyCheckpointComplete(checkpointId);
 		}
 	}
 
 	public void notifyCheckpointAborted(long checkpointId) throws Exception {
-		if (keyedStateBackend != null) {
-			keyedStateBackend.notifyCheckpointAborted(checkpointId);
+		if (keyedStateBackend != null && keyedStateBackend instanceof CheckpointListener) {

Review comment:
       ```suggestion
   		if (keyedStateBackend instanceof CheckpointListener) {
   ```
   Ditto.

##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/InternalTimeServiceManager.java
##########
@@ -74,19 +74,16 @@
 
 	private final Map<String, InternalTimerServiceImpl<K, ?>> timerServices;
 
-	private final boolean useLegacySynchronousSnapshots;
-
 	InternalTimeServiceManager(
-		KeyGroupRange localKeyGroupRange,
-		KeyContext keyContext,
-		PriorityQueueSetFactory priorityQueueSetFactory,
-		ProcessingTimeService processingTimeService, boolean useLegacySynchronousSnapshots) {

Review comment:
       It seems after the changes made for FLINK-16316 the `useLegacySynchronousSnapshots` field here is never accessed? I'm also +1 for keeping the private field and use it in `snapshotState` to save the cost of `instanceof` when calling `requiresLegacySynchronousTimerSnapshots` for RocksDB backend.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] dawidwys commented on a change in pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
dawidwys commented on a change in pull request #13405:
URL: https://github.com/apache/flink/pull/13405#discussion_r491971571



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/InternalTimeServiceManager.java
##########
@@ -74,19 +74,16 @@
 
 	private final Map<String, InternalTimerServiceImpl<K, ?>> timerServices;
 
-	private final boolean useLegacySynchronousSnapshots;
-
 	InternalTimeServiceManager(
-		KeyGroupRange localKeyGroupRange,
-		KeyContext keyContext,
-		PriorityQueueSetFactory priorityQueueSetFactory,
-		ProcessingTimeService processingTimeService, boolean useLegacySynchronousSnapshots) {

Review comment:
       It can. Let me explain it though, why I think it is unnecessary in the ctor. (There is one thing I forgot in the PR, I wanted to make the `snapshotStateForKeyGroup` private. It is used only in the `InternalTimeServiceManager#snapshotState`.)
   
   The flag is used only in the `snapshotStateForKeyGroup` which is used only in the `snapshotState` method. The `snapshotState` method looks like:
   ```
   	public void snapshotState(
   			KeyedStateBackend<?> keyedStateBackend,
   			StateSnapshotContext context,
   			String operatorName) throws Exception {
   		//TODO all of this can be removed once heap-based timers are integrated with RocksDB incremental snapshots
   		if (keyedStateBackend instanceof AbstractKeyedStateBackend &&
   			((AbstractKeyedStateBackend<?>) keyedStateBackend).requiresLegacySynchronousTimerSnapshots()) {
   
               ....
   			snapshotStateForKeyGroup(new DataOutputViewStreamWrapper(out), keyGroupIdx);
               ....
   		}
   	}
   ```
   
   Effectively this flag is checked twice. Once in the preconditions against the value passed in the ctor and the second time in the `snapshotState` method against the value set in the passed `KeyedStateBackend`. In my opinion the one time in the `snapshotState` is enough.
   
   The only case when the condition in `snapshotStateForKeyGroup` could fail is if we created the `InternalTimeServiceManager` from a different `KeyedStateBackend` than we use for snapshotting. I am quite sure this would lead to way more problems than only this precondition failling.
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] carp84 commented on a change in pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
carp84 commented on a change in pull request #13405:
URL: https://github.com/apache/flink/pull/13405#discussion_r492677227



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java
##########
@@ -282,8 +283,8 @@ public void setCurrentKey(Object key) {
 		if (keyedStateBackend != null) {
 			try {
 				// need to work around type restrictions
-				@SuppressWarnings("unchecked,rawtypes")
-				AbstractKeyedStateBackend rawBackend = (AbstractKeyedStateBackend) keyedStateBackend;
+				@SuppressWarnings("rawtypes")
+				CheckpointableKeyedStateBackend rawBackend = keyedStateBackend;
 
 				rawBackend.setCurrentKey(key);

Review comment:
       True, but that's why we need to suppress the "unchecked" warning, rather than "rawtypes"? (In my local env it will also show the warning if I remove the "unchecked" suppression from the method signature)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] dawidwys closed pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
dawidwys closed pull request #13405:
URL: https://github.com/apache/flink/pull/13405


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] dawidwys closed pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
dawidwys closed pull request #13405:
URL: https://github.com/apache/flink/pull/13405


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] dawidwys commented on a change in pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
dawidwys commented on a change in pull request #13405:
URL: https://github.com/apache/flink/pull/13405#discussion_r492155621



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java
##########
@@ -217,14 +218,14 @@ void snapshotState(
 	}
 
 	public void notifyCheckpointComplete(long checkpointId) throws Exception {
-		if (keyedStateBackend != null) {
-			keyedStateBackend.notifyCheckpointComplete(checkpointId);
+		if (keyedStateBackend != null && keyedStateBackend instanceof CheckpointListener) {

Review comment:
       Makes sense.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13405:
URL: https://github.com/apache/flink/pull/13405#issuecomment-694066808


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6590",
       "triggerID" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "triggerType" : "PUSH"
     }, {
       "hash" : "bea6d1034a41f1c38afdb73d6c0875eba61f924e",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6685",
       "triggerID" : "bea6d1034a41f1c38afdb73d6c0875eba61f924e",
       "triggerType" : "PUSH"
     }, {
       "hash" : "4089ed32d6d11831ef0434356da061868a2bf568",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6692",
       "triggerID" : "4089ed32d6d11831ef0434356da061868a2bf568",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * bea6d1034a41f1c38afdb73d6c0875eba61f924e Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6685) 
   * 4089ed32d6d11831ef0434356da061868a2bf568 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6692) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] dawidwys commented on a change in pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
dawidwys commented on a change in pull request #13405:
URL: https://github.com/apache/flink/pull/13405#discussion_r492649792



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java
##########
@@ -282,8 +283,8 @@ public void setCurrentKey(Object key) {
 		if (keyedStateBackend != null) {
 			try {
 				// need to work around type restrictions
-				@SuppressWarnings("unchecked,rawtypes")
-				AbstractKeyedStateBackend rawBackend = (AbstractKeyedStateBackend) keyedStateBackend;
+				@SuppressWarnings("rawtypes")
+				CheckpointableKeyedStateBackend rawBackend = keyedStateBackend;
 
 				rawBackend.setCurrentKey(key);

Review comment:
       mine, shows it as a warning.
   
   We are using the `CheckpointableKeyedStateBackend` as a raw type, without the key, so there should be a warning.

##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java
##########
@@ -282,8 +283,8 @@ public void setCurrentKey(Object key) {
 		if (keyedStateBackend != null) {
 			try {
 				// need to work around type restrictions
-				@SuppressWarnings("unchecked,rawtypes")
-				AbstractKeyedStateBackend rawBackend = (AbstractKeyedStateBackend) keyedStateBackend;
+				@SuppressWarnings("rawtypes")
+				CheckpointableKeyedStateBackend rawBackend = keyedStateBackend;
 
 				rawBackend.setCurrentKey(key);

Review comment:
       mine, shows it as a warning.
   
   We are using the `CheckpointableKeyedStateBackend` as a raw type, without the key, so there should be a warning.
   
   The `keyedStateBackend` is of type `CheckpointableKeyedStateBackend<?>` so we have a signature like: `setCurrentKey(? key)`, which cannot be satisfied. Therefore we need to cast it to a raw type.

##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java
##########
@@ -282,8 +283,8 @@ public void setCurrentKey(Object key) {
 		if (keyedStateBackend != null) {
 			try {
 				// need to work around type restrictions
-				@SuppressWarnings("unchecked,rawtypes")
-				AbstractKeyedStateBackend rawBackend = (AbstractKeyedStateBackend) keyedStateBackend;
+				@SuppressWarnings("rawtypes")
+				CheckpointableKeyedStateBackend rawBackend = keyedStateBackend;
 
 				rawBackend.setCurrentKey(key);

Review comment:
       The "unchecked" suppressed the cast. The "rawtypes" suppresses the call to `setCurrentKey` on raw type.

##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java
##########
@@ -282,8 +283,8 @@ public void setCurrentKey(Object key) {
 		if (keyedStateBackend != null) {
 			try {
 				// need to work around type restrictions
-				@SuppressWarnings("unchecked,rawtypes")
-				AbstractKeyedStateBackend rawBackend = (AbstractKeyedStateBackend) keyedStateBackend;
+				@SuppressWarnings("rawtypes")
+				CheckpointableKeyedStateBackend rawBackend = keyedStateBackend;
 
 				rawBackend.setCurrentKey(key);

Review comment:
       ![suppress](https://user-images.githubusercontent.com/6242259/93879881-d4b72b00-fcdc-11ea-94c0-2030895acf4c.png)
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13405:
URL: https://github.com/apache/flink/pull/13405#issuecomment-694066808


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6590",
       "triggerID" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "triggerType" : "PUSH"
     }, {
       "hash" : "bea6d1034a41f1c38afdb73d6c0875eba61f924e",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6685",
       "triggerID" : "bea6d1034a41f1c38afdb73d6c0875eba61f924e",
       "triggerType" : "PUSH"
     }, {
       "hash" : "4089ed32d6d11831ef0434356da061868a2bf568",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "4089ed32d6d11831ef0434356da061868a2bf568",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * bea6d1034a41f1c38afdb73d6c0875eba61f924e Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6685) 
   * 4089ed32d6d11831ef0434356da061868a2bf568 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot commented on pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
flinkbot commented on pull request #13405:
URL: https://github.com/apache/flink/pull/13405#issuecomment-694066808


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 835077d91fd63313743cfff3a30e74fd0b44f9af UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13405:
URL: https://github.com/apache/flink/pull/13405#issuecomment-694066808


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6590",
       "triggerID" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "triggerType" : "PUSH"
     }, {
       "hash" : "bea6d1034a41f1c38afdb73d6c0875eba61f924e",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "bea6d1034a41f1c38afdb73d6c0875eba61f924e",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 835077d91fd63313743cfff3a30e74fd0b44f9af Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6590) 
   * bea6d1034a41f1c38afdb73d6c0875eba61f924e UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13405:
URL: https://github.com/apache/flink/pull/13405#issuecomment-694066808


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6590",
       "triggerID" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "triggerType" : "PUSH"
     }, {
       "hash" : "bea6d1034a41f1c38afdb73d6c0875eba61f924e",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6685",
       "triggerID" : "bea6d1034a41f1c38afdb73d6c0875eba61f924e",
       "triggerType" : "PUSH"
     }, {
       "hash" : "4089ed32d6d11831ef0434356da061868a2bf568",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6692",
       "triggerID" : "4089ed32d6d11831ef0434356da061868a2bf568",
       "triggerType" : "PUSH"
     }, {
       "hash" : "85bf458f7889a735f9abda895cb699862fb66659",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6700",
       "triggerID" : "85bf458f7889a735f9abda895cb699862fb66659",
       "triggerType" : "PUSH"
     }, {
       "hash" : "ec745aa11eb24be7e2bfc6bb5da93f2e24a1e6cc",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6713",
       "triggerID" : "ec745aa11eb24be7e2bfc6bb5da93f2e24a1e6cc",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * ec745aa11eb24be7e2bfc6bb5da93f2e24a1e6cc Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6713) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13405:
URL: https://github.com/apache/flink/pull/13405#issuecomment-694050574


   Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
   to review your pull request. We will use this comment to track the progress of the review.
   
   
   ## Automated Checks
   Last check on commit ec745aa11eb24be7e2bfc6bb5da93f2e24a1e6cc (Fri Feb 19 07:22:52 UTC 2021)
   
   **Warnings:**
    * No documentation files were touched! Remember to keep the Flink docs up to date!
   
   
   <sub>Mention the bot in a comment to re-run the automated checks.</sub>
   ## Review Progress
   
   * ❓ 1. The [description] looks good.
   * ❓ 2. There is [consensus] that the contribution should go into to Flink.
   * ❓ 3. Needs [attention] from.
   * ❓ 4. The change fits into the overall [architecture].
   * ❓ 5. Overall code [quality] is good.
   
   Please see the [Pull Request Review Guide](https://flink.apache.org/contributing/reviewing-prs.html) for a full explanation of the review process.<details>
    The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot approve description` to approve one or more aspects (aspects: `description`, `consensus`, `architecture` and `quality`)
    - `@flinkbot approve all` to approve all aspects
    - `@flinkbot approve-until architecture` to approve everything until `architecture`
    - `@flinkbot attention @username1 [@username2 ..]` to require somebody's attention
    - `@flinkbot disapprove architecture` to remove an approval you gave earlier
   </details>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] carp84 commented on a change in pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
carp84 commented on a change in pull request #13405:
URL: https://github.com/apache/flink/pull/13405#discussion_r492641148



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java
##########
@@ -282,8 +283,8 @@ public void setCurrentKey(Object key) {
 		if (keyedStateBackend != null) {
 			try {
 				// need to work around type restrictions
-				@SuppressWarnings("unchecked,rawtypes")
-				AbstractKeyedStateBackend rawBackend = (AbstractKeyedStateBackend) keyedStateBackend;
+				@SuppressWarnings("rawtypes")
+				CheckpointableKeyedStateBackend rawBackend = keyedStateBackend;
 
 				rawBackend.setCurrentKey(key);

Review comment:
       The suggested change looks ok in my local IntelliJ, could you double check? Thanks. :-)

##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java
##########
@@ -282,8 +283,8 @@ public void setCurrentKey(Object key) {
 		if (keyedStateBackend != null) {
 			try {
 				// need to work around type restrictions
-				@SuppressWarnings("unchecked,rawtypes")
-				AbstractKeyedStateBackend rawBackend = (AbstractKeyedStateBackend) keyedStateBackend;
+				@SuppressWarnings("rawtypes")
+				CheckpointableKeyedStateBackend rawBackend = keyedStateBackend;
 
 				rawBackend.setCurrentKey(key);

Review comment:
       True, but that's why we need to suppress the "unchecked" warning, rather than "rawtypes"? (In my local env it will also show the warning if I remove the "unchecked" suppression from the method signature)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] aljoscha commented on a change in pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
aljoscha commented on a change in pull request #13405:
URL: https://github.com/apache/flink/pull/13405#discussion_r491936770



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/InternalTimeServiceManager.java
##########
@@ -74,19 +74,16 @@
 
 	private final Map<String, InternalTimerServiceImpl<K, ?>> timerServices;
 
-	private final boolean useLegacySynchronousSnapshots;
-
 	InternalTimeServiceManager(
-		KeyGroupRange localKeyGroupRange,
-		KeyContext keyContext,
-		PriorityQueueSetFactory priorityQueueSetFactory,
-		ProcessingTimeService processingTimeService, boolean useLegacySynchronousSnapshots) {

Review comment:
       Why is `useLegacySynchronousSnapshots` removed here? Can't `RocksDBKeyedStateBackend.requiresLegacySynchronousTimerSnapshots()` still return true here?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] dawidwys commented on a change in pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
dawidwys commented on a change in pull request #13405:
URL: https://github.com/apache/flink/pull/13405#discussion_r491971571



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/InternalTimeServiceManager.java
##########
@@ -74,19 +74,16 @@
 
 	private final Map<String, InternalTimerServiceImpl<K, ?>> timerServices;
 
-	private final boolean useLegacySynchronousSnapshots;
-
 	InternalTimeServiceManager(
-		KeyGroupRange localKeyGroupRange,
-		KeyContext keyContext,
-		PriorityQueueSetFactory priorityQueueSetFactory,
-		ProcessingTimeService processingTimeService, boolean useLegacySynchronousSnapshots) {

Review comment:
       It can. Let me explain it though, why I think it is unnecessary in the ctor. (There is one thing I forgot in the PR, I wanted to make the `snapshotStateForKeyGroup` private. It is used only in the `InternalTimeServiceManager#snapshotState`.)
   
   The flag is used only in the `snapshotStateForKeyGroup` which is used only in the `snapshotState` method. The `snapshotState` method looks like:
   ```
   	public void snapshotState(
   			KeyedStateBackend<?> keyedStateBackend,
   			StateSnapshotContext context,
   			String operatorName) throws Exception {
   		//TODO all of this can be removed once heap-based timers are integrated with RocksDB incremental snapshots
   		if (keyedStateBackend instanceof AbstractKeyedStateBackend &&
   			((AbstractKeyedStateBackend<?>) keyedStateBackend).requiresLegacySynchronousTimerSnapshots()) {
   
               ....
   			snapshotStateForKeyGroup(new DataOutputViewStreamWrapper(out), keyGroupIdx);
               ....
   		}
   	}
   ```
   
   Effectively this flag is checked twice. Once in the preconditions against the value passed in the ctor and the second time in the `snapshotState` method against the value set in the passed `KeyedStateBackend`. In my opinion the one time in the `snapshotState` is enough.
   
   The only case when the condition in `snapshotStateForKeyGroup` could fail is if we created the `InternalTimeServiceManager` from a different `KeyedStateBackend` than we use for snapshotting. I am quite sure this would let to way more problems than only this precondition failling.
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13405:
URL: https://github.com/apache/flink/pull/13405#issuecomment-694066808


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6590",
       "triggerID" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 835077d91fd63313743cfff3a30e74fd0b44f9af Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6590) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] dawidwys commented on pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
dawidwys commented on pull request #13405:
URL: https://github.com/apache/flink/pull/13405#issuecomment-696625513


   Could you have another look @carp84 @aljoscha ?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] carp84 commented on a change in pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
carp84 commented on a change in pull request #13405:
URL: https://github.com/apache/flink/pull/13405#discussion_r492641148



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java
##########
@@ -282,8 +283,8 @@ public void setCurrentKey(Object key) {
 		if (keyedStateBackend != null) {
 			try {
 				// need to work around type restrictions
-				@SuppressWarnings("unchecked,rawtypes")
-				AbstractKeyedStateBackend rawBackend = (AbstractKeyedStateBackend) keyedStateBackend;
+				@SuppressWarnings("rawtypes")
+				CheckpointableKeyedStateBackend rawBackend = keyedStateBackend;
 
 				rawBackend.setCurrentKey(key);

Review comment:
       The suggested change looks ok in my local IntelliJ, could you double check? Thanks. :-)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] dawidwys commented on a change in pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
dawidwys commented on a change in pull request #13405:
URL: https://github.com/apache/flink/pull/13405#discussion_r492157663



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/InternalTimeServiceManager.java
##########
@@ -74,19 +74,16 @@
 
 	private final Map<String, InternalTimerServiceImpl<K, ?>> timerServices;
 
-	private final boolean useLegacySynchronousSnapshots;
-
 	InternalTimeServiceManager(
-		KeyGroupRange localKeyGroupRange,
-		KeyContext keyContext,
-		PriorityQueueSetFactory priorityQueueSetFactory,
-		ProcessingTimeService processingTimeService, boolean useLegacySynchronousSnapshots) {

Review comment:
       I think I changed it the way you suggested @carp84
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13405:
URL: https://github.com/apache/flink/pull/13405#issuecomment-694066808


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6590",
       "triggerID" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "triggerType" : "PUSH"
     }, {
       "hash" : "bea6d1034a41f1c38afdb73d6c0875eba61f924e",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6685",
       "triggerID" : "bea6d1034a41f1c38afdb73d6c0875eba61f924e",
       "triggerType" : "PUSH"
     }, {
       "hash" : "4089ed32d6d11831ef0434356da061868a2bf568",
       "status" : "CANCELED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6692",
       "triggerID" : "4089ed32d6d11831ef0434356da061868a2bf568",
       "triggerType" : "PUSH"
     }, {
       "hash" : "85bf458f7889a735f9abda895cb699862fb66659",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6700",
       "triggerID" : "85bf458f7889a735f9abda895cb699862fb66659",
       "triggerType" : "PUSH"
     }, {
       "hash" : "ec745aa11eb24be7e2bfc6bb5da93f2e24a1e6cc",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "ec745aa11eb24be7e2bfc6bb5da93f2e24a1e6cc",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 4089ed32d6d11831ef0434356da061868a2bf568 Azure: [CANCELED](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6692) 
   * 85bf458f7889a735f9abda895cb699862fb66659 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6700) 
   * ec745aa11eb24be7e2bfc6bb5da93f2e24a1e6cc UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] aljoscha commented on a change in pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
aljoscha commented on a change in pull request #13405:
URL: https://github.com/apache/flink/pull/13405#discussion_r492676606



##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/state/CheckpointableKeyedStateBackend.java
##########
@@ -0,0 +1,42 @@
+/*
+ * 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
+ *
+ *     http://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.state;
+
+import java.io.Closeable;
+
+/**
+ * Interface that combines both, the {@link KeyedStateBackend} interface, which encapsulates methods
+ * responsible for keyed state management and the {@link SnapshotStrategy} which tells the system
+ * how to snapshot the underlying state.
+ *
+ * <p><b>NOTE:</b> Implementations of this class can be notified about a checkpoint result it can additionally implement
+ * the {@link CheckpointListener} interface.
+ *
+ * @param <K> The key by which state is keyed.
+ */

Review comment:
       ```suggestion
    * <p><b>NOTE:</b> State backends that need to be notified of completed checkpoints can additionally implement
    * the {@link CheckpointListener} interface.
    *
    * @param <K> Type of the key by which state is keyed.
    */
   ```
   Formatting is probably not correct after my changes but I think the previous sentence was not grammatically correct.

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/state/CheckpointableKeyedStateBackend.java
##########
@@ -0,0 +1,42 @@
+/*
+ * 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
+ *
+ *     http://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.state;
+
+import java.io.Closeable;
+
+/**
+ * Interface that combines both, the {@link KeyedStateBackend} interface, which encapsulates methods
+ * responsible for keyed state management and the {@link SnapshotStrategy} which tells the system
+ * how to snapshot the underlying state.
+ *
+ * <p><b>NOTE:</b> Implementations of this class can be notified about a checkpoint result it can additionally implement
+ * the {@link CheckpointListener} interface.
+ *
+ * @param <K> The key by which state is keyed.
+ */
+public interface CheckpointableKeyedStateBackend<K> extends
+		KeyedStateBackend<K>,
+		SnapshotStrategy<SnapshotResult<KeyedStateHandle>>,
+		Closeable {
+
+	/**
+	 * Returns the key groups which the state backend is responsible for.

Review comment:
       ```suggestion
   	 * Returns the key groups which this state backend is responsible for.
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13405:
URL: https://github.com/apache/flink/pull/13405#issuecomment-694066808


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6590",
       "triggerID" : "835077d91fd63313743cfff3a30e74fd0b44f9af",
       "triggerType" : "PUSH"
     }, {
       "hash" : "bea6d1034a41f1c38afdb73d6c0875eba61f924e",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6685",
       "triggerID" : "bea6d1034a41f1c38afdb73d6c0875eba61f924e",
       "triggerType" : "PUSH"
     }, {
       "hash" : "4089ed32d6d11831ef0434356da061868a2bf568",
       "status" : "CANCELED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6692",
       "triggerID" : "4089ed32d6d11831ef0434356da061868a2bf568",
       "triggerType" : "PUSH"
     }, {
       "hash" : "85bf458f7889a735f9abda895cb699862fb66659",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6700",
       "triggerID" : "85bf458f7889a735f9abda895cb699862fb66659",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 4089ed32d6d11831ef0434356da061868a2bf568 Azure: [CANCELED](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6692) 
   * 85bf458f7889a735f9abda895cb699862fb66659 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6700) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] dawidwys commented on a change in pull request #13405: [FLINK-19270] Extract an inteface from AbstractKeyedStateBackend

Posted by GitBox <gi...@apache.org>.
dawidwys commented on a change in pull request #13405:
URL: https://github.com/apache/flink/pull/13405#discussion_r492155536



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java
##########
@@ -282,8 +283,8 @@ public void setCurrentKey(Object key) {
 		if (keyedStateBackend != null) {
 			try {
 				// need to work around type restrictions
-				@SuppressWarnings("unchecked,rawtypes")
-				AbstractKeyedStateBackend rawBackend = (AbstractKeyedStateBackend) keyedStateBackend;
+				@SuppressWarnings("rawtypes")
+				CheckpointableKeyedStateBackend rawBackend = keyedStateBackend;
 
 				rawBackend.setCurrentKey(key);

Review comment:
       In this line, we actually can not remove the "rawtypes" suppression. We can remove it from the method annotation though. I will do that.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org