xintongsong commented on code in PR #388: URL: https://github.com/apache/flink-agents/pull/388#discussion_r2639484705
########## runtime/src/main/java/org/apache/flink/agents/runtime/operator/StateUtils.java: ########## @@ -0,0 +1,73 @@ +/* + * 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.agents.runtime.operator; + +import org.apache.flink.api.common.state.ListState; +import org.apache.flink.api.common.state.ListStateDescriptor; +import org.apache.flink.runtime.state.StateInitializationContext; +import org.apache.flink.shaded.guava31.com.google.common.collect.Lists; +import org.apache.flink.util.Preconditions; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +/** Utility class for sink state manipulation. Copy from Apache Paimon. */ Review Comment: In our case, this is not related to sink. ########## runtime/src/main/java/org/apache/flink/agents/runtime/operator/ActionExecutionOperator.java: ########## @@ -635,6 +644,18 @@ public void initializeState(StateInitializationContext context) throws Exception } actionStateStore.rebuildState(markers); } + + if (jobIdentifier == null) { + String initialJobIdentifier = + agentPlan + .getConfig() + .getStr( + JOB_IDENTIFIER.getKey(), + getRuntimeContext().getJobInfo().getJobId().toString()); + jobIdentifier = + StateUtils.getSingleValueFromState( + context, "identifier_state", String.class, initialJobIdentifier); Review Comment: We should respect the configured value, and only read from state when it's not configured. ########## runtime/src/main/java/org/apache/flink/agents/runtime/operator/StateUtils.java: ########## @@ -0,0 +1,73 @@ +/* + * 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.agents.runtime.operator; + +import org.apache.flink.api.common.state.ListState; +import org.apache.flink.api.common.state.ListStateDescriptor; +import org.apache.flink.runtime.state.StateInitializationContext; +import org.apache.flink.shaded.guava31.com.google.common.collect.Lists; +import org.apache.flink.util.Preconditions; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +/** Utility class for sink state manipulation. Copy from Apache Paimon. */ +public class StateUtils { + + public static @Nullable <T> T getSingleValueFromState( + StateInitializationContext context, + String stateName, + Class<T> valueClass, + T defaultValue) + throws Exception { + ListState<T> state = + context.getOperatorStateStore() + .getUnionListState(new ListStateDescriptor<>(stateName, valueClass)); + + List<T> values = new ArrayList<>(); + state.get().forEach(values::add); Review Comment: Why would there be multiple values? -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
