wanglijie95 commented on a change in pull request #11499:
URL: https://github.com/apache/flink/pull/11499#discussion_r415331203



##########
File path: 
flink-connectors/flink-jdbc/src/main/java/org/apache/flink/api/java/io/jdbc/JDBCLookupFunction.java
##########
@@ -139,6 +139,14 @@ public void eval(Object... keys) {
 
                for (int retry = 1; retry <= maxRetryTimes; retry++) {
                        try {
+                               try {

Review comment:
       Check whether connection is valid on each writes is expensive. How about 
catching the "statement closed" exception (mentioned in FLINK-16681) and 
solving it by creating a new connection.

##########
File path: 
flink-connectors/flink-jdbc/src/main/java/org/apache/flink/api/java/io/jdbc/JDBCOutputFormat.java
##########
@@ -50,6 +50,8 @@
        final JdbcInsertOptions insertOptions;
        private final JdbcExecutionOptions batchOptions;
 
+       private static final int connectionCheckTimeout = 60;

Review comment:
       I think the variable name should be  `CONNECTION_CHECK_TIMEOUT`, because 
it's static final variable. 

##########
File path: 
flink-connectors/flink-jdbc/src/main/java/org/apache/flink/api/java/io/jdbc/JDBCOutputFormat.java
##########
@@ -87,8 +89,12 @@ public void open(int taskNumber, int numTasks) throws 
IOException {
        }
 
        @Override
-       public void writeRecord(Row row) {
+       public void writeRecord(Row row) throws IOException{
                try {
+                       if (!connection.isValid(connectionCheckTimeout)) {
+                               LOG.error("JDBC connection is closed,start to 
open a new connection");
+                               establishConnectionAndPreparedStatement();

Review comment:
       Maybe you should close the connection and statement fisrt, and then 
reestablish.

##########
File path: 
flink-connectors/flink-jdbc/src/main/java/org/apache/flink/api/java/io/jdbc/JDBCLookupFunction.java
##########
@@ -139,6 +139,14 @@ public void eval(Object... keys) {
 
                for (int retry = 1; retry <= maxRetryTimes; retry++) {
                        try {
+                               try {
+                                       if 
(!dbConn.isValid(connectionCheckTimeout)) {
+                                               
establishConnectionAndPreparedStatement();

Review comment:
       Maybe you should close the connection and statement fisrt, and then 
reestablish.




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to