forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-12963] [state-processor] Introduce OperatorStateSpec wrapper c…
…lass This class is a simple container class to represent an operator state that is either still defined by a BootstrapTransformation, i.e. new state that has not been written out yet, or an existing OperatorState. Introducing this class improves readability of the code, instead of using Eithers and Tuples that would not have clear semantics for the user.
- Loading branch information
Showing
4 changed files
with
156 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...g-api/src/main/java/org/apache/flink/state/api/runtime/BootstrapTransformationWithID.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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.state.api.runtime; | ||
|
||
import org.apache.flink.annotation.Internal; | ||
import org.apache.flink.runtime.jobgraph.OperatorID; | ||
import org.apache.flink.state.api.BootstrapTransformation; | ||
import org.apache.flink.util.Preconditions; | ||
|
||
/** | ||
* A simple container class that represents a newly bootstrapped operator state within savepoints. | ||
* It wraps the target {@link OperatorID} for the bootstrapped operator, as well as the {@link BootstrapTransformation} | ||
* that defines how the state is bootstrapped. | ||
*/ | ||
@Internal | ||
public class BootstrapTransformationWithID<T> { | ||
|
||
private final OperatorID operatorID; | ||
private final BootstrapTransformation<T> bootstrapTransformation; | ||
|
||
public BootstrapTransformationWithID(OperatorID operatorID, BootstrapTransformation<T> bootstrapTransformation) { | ||
this.operatorID = Preconditions.checkNotNull(operatorID); | ||
this.bootstrapTransformation = Preconditions.checkNotNull(bootstrapTransformation); | ||
} | ||
|
||
public OperatorID getOperatorID() { | ||
return operatorID; | ||
} | ||
|
||
public BootstrapTransformation<T> getBootstrapTransformation() { | ||
return bootstrapTransformation; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...sing-api/src/main/java/org/apache/flink/state/api/runtime/metadata/OperatorStateSpec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* 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.state.api.runtime.metadata; | ||
|
||
import org.apache.flink.annotation.Internal; | ||
import org.apache.flink.runtime.checkpoint.OperatorState; | ||
import org.apache.flink.runtime.jobgraph.OperatorID; | ||
import org.apache.flink.state.api.runtime.BootstrapTransformationWithID; | ||
import org.apache.flink.util.Preconditions; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* This class specifies an operator state maintained by {@link SavepointMetadata}. | ||
* An operator state is either represented as an existing {@link OperatorState}, or a | ||
* {@link org.apache.flink.state.api.BootstrapTransformation} that will be used to create it. | ||
*/ | ||
@Internal | ||
class OperatorStateSpec { | ||
|
||
private final OperatorID id; | ||
|
||
@Nullable | ||
private final OperatorState existingState; | ||
|
||
@Nullable | ||
private final BootstrapTransformationWithID<?> newOperatorStateTransformation; | ||
|
||
static OperatorStateSpec existing(OperatorState existingState) { | ||
return new OperatorStateSpec(Preconditions.checkNotNull(existingState)); | ||
} | ||
|
||
static OperatorStateSpec newWithTransformation(BootstrapTransformationWithID<?> transformation) { | ||
return new OperatorStateSpec(Preconditions.checkNotNull(transformation)); | ||
} | ||
|
||
private OperatorStateSpec(OperatorState existingState) { | ||
this.id = existingState.getOperatorID(); | ||
this.existingState = existingState; | ||
this.newOperatorStateTransformation = null; | ||
} | ||
|
||
private OperatorStateSpec(BootstrapTransformationWithID<?> transformation) { | ||
this.id = transformation.getOperatorID(); | ||
this.newOperatorStateTransformation = transformation; | ||
this.existingState = null; | ||
} | ||
|
||
boolean isExistingState() { | ||
return existingState != null; | ||
} | ||
|
||
boolean isNewStateTransformation() { | ||
return !isExistingState(); | ||
} | ||
|
||
OperatorState asExistingState() { | ||
Preconditions.checkState(isExistingState(), "OperatorState %s is not an existing state.", id); | ||
return existingState; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
<T> BootstrapTransformationWithID<T> asNewStateTransformation() { | ||
Preconditions.checkState(isNewStateTransformation(), "OperatorState %s is not a new state defined with BootstrapTransformation", id); | ||
return (BootstrapTransformationWithID<T>) newOperatorStateTransformation; | ||
} | ||
} |