Github user rmetzger commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1305#discussion_r45544375
  
    --- Diff: 
flink-contrib/flink-streaming-contrib/src/main/java/org/apache/flink/contrib/streaming/state/DbStateHandle.java
 ---
    @@ -0,0 +1,88 @@
    +/*
    + * 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.contrib.streaming.state;
    +
    +import static org.apache.flink.contrib.streaming.state.SQLRetrier.retry;
    +
    +import java.io.IOException;
    +import java.io.Serializable;
    +import java.util.concurrent.Callable;
    +
    +import org.apache.flink.runtime.state.StateHandle;
    +import org.apache.flink.util.InstantiationUtil;
    +import org.eclipse.jetty.util.log.Log;
    +
    +/**
    + * State handle implementation for storing checkpoints as byte arrays in
    + * databases using the {@link MySqlAdapter} defined in the {@link 
DbBackendConfig}.
    + * 
    + */
    +public class DbStateHandle<S> implements Serializable, StateHandle<S> {
    +
    +   private static final long serialVersionUID = 1L;
    +
    +   private final String jobId;
    +   private final DbBackendConfig dbConfig;
    +
    +   private final long checkpointId;
    +   private final long checkpointTs;
    +
    +   private final long handleId;
    +
    +   public DbStateHandle(String jobId, long checkpointId, long 
checkpointTs, long handleId, DbBackendConfig dbConfig) {
    +           this.checkpointId = checkpointId;
    +           this.handleId = handleId;
    +           this.jobId = jobId;
    +           this.dbConfig = dbConfig;
    +           this.checkpointTs = checkpointTs;
    +   }
    +
    +   protected byte[] getBytes() throws IOException {
    +           return retry(new Callable<byte[]>() {
    +                   public byte[] call() throws Exception {
    +                           try (ShardedConnection con = 
dbConfig.createShardedConnection()) {
    +                                   return 
dbConfig.getDbAdapter().getCheckpoint(jobId, con.getFirst(), checkpointId, 
checkpointTs, handleId);
    +                           }
    +                   }
    +           }, dbConfig.getMaxNumberOfSqlRetries(), 
dbConfig.getSleepBetweenSqlRetries());
    +   }
    +
    +   @Override
    +   public void discardState() {
    +           try {
    +                   retry(new Callable<Boolean>() {
    +                           public Boolean call() throws Exception {
    +                                   try (ShardedConnection con = 
dbConfig.createShardedConnection()) {
    +                                           
dbConfig.getDbAdapter().deleteCheckpoint(jobId, con.getFirst(), checkpointId, 
checkpointTs, handleId);
    +                                   }
    +                                   return true;
    +                           }
    +                   }, dbConfig.getMaxNumberOfSqlRetries(), 
dbConfig.getSleepBetweenSqlRetries());
    +           } catch (IOException e) {
    +                   // We don't want to fail the job here, but log the 
error.
    +                   if (Log.isDebugEnabled()) {
    --- End diff --
    
    We could add a checkstyle rule for that, but I would like to solve the 
problem in a different way: I recently opened a JIRA for checking whether a 
Flink module is only using dependencies it has explicitly declared (forbidding 
to rely on transitive dependencies). WIth that check, we would also identify 
cases like this one.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to