umustafi commented on code in PR #3715:
URL: https://github.com/apache/gobblin/pull/3715#discussion_r1266015108


##########
gobblin-runtime/src/main/java/org/apache/gobblin/runtime/api/MysqlMultiActiveLeaseArbiter.java:
##########
@@ -155,19 +163,26 @@ public MysqlMultiActiveLeaseArbiter(Config config) throws 
IOException {
     } catch (SQLException e) {
       throw new IOException("Table creation failure for " + 
leaseArbiterTableName, e);
     }
+    initializeConstantsTable();
+
+    log.info("MysqlMultiActiveLeaseArbiter initialized");
+  }
+
+  // Initialize Constants table if needed and insert row into it if one does 
not exist
+  private void initializeConstantsTable() throws IOException {
     String createConstantsStatement = 
String.format(CREATE_CONSTANTS_TABLE_STATEMENT, this.constantsTableName);
     withPreparedStatement(createConstantsStatement, createStatement -> 
createStatement.executeUpdate(), true);
 
-    int count = withPreparedStatement(String.format(GET_ROW_COUNT_STATEMENT, 
this.constantsTableName), getStatement -> {
+    Optional<Integer> count = 
withPreparedStatement(String.format(GET_ROW_COUNT_STATEMENT, 
this.constantsTableName), getStatement -> {
       ResultSet resultSet = getStatement.executeQuery();
       if (resultSet.next()) {
-        return resultSet.getInt(1);
+        return Optional.of(resultSet.getInt(1));
       }
-      return -1;
+      return Optional.absent();
     }, true);
 
     // Only insert epsilon and linger values from config if this table does 
not contain pre-existing values.
-    if (count == 0) {
+    if (count.isPresent() && count.get() == 0) {

Review Comment:
   Ah good catch, I updated the statement to a simpler one `INSERT ... WHERE 
NOT EXISTS (SELECT 1 FROM table)` to insert if there are no rows in table.



-- 
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]

Reply via email to