[ 
https://issues.apache.org/jira/browse/GOBBLIN-1851?focusedWorklogId=871407&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-871407
 ]

ASF GitHub Bot logged work on GOBBLIN-1851:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 17/Jul/23 23:46
            Start Date: 17/Jul/23 23:46
    Worklog Time Spent: 10m 
      Work Description: 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.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 871407)
    Time Spent: 20m  (was: 10m)

> Unit Testing of Multi-active Algorithm
> --------------------------------------
>
>                 Key: GOBBLIN-1851
>                 URL: https://issues.apache.org/jira/browse/GOBBLIN-1851
>             Project: Apache Gobblin
>          Issue Type: Bug
>          Components: gobblin-service
>            Reporter: Urmi Mustafi
>            Assignee: Abhishek Tiwari
>            Priority: Major
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> Tests all cases of trying to acquire a lease for a flow action event with one 
> participant involved and makes corresponding fixes in the 
> `MultiActiveLeaseArbiter`. 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to