You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oozie.apache.org by rk...@apache.org on 2016/06/01 23:48:09 UTC

oozie git commit: OOZIE-2546 Improperly closed resources in OozieDBCLI (pbacsko via rkanter)

Repository: oozie
Updated Branches:
  refs/heads/master 87040a1f1 -> 0c7466788


OOZIE-2546 Improperly closed resources in OozieDBCLI (pbacsko via rkanter)


Project: http://git-wip-us.apache.org/repos/asf/oozie/repo
Commit: http://git-wip-us.apache.org/repos/asf/oozie/commit/0c746678
Tree: http://git-wip-us.apache.org/repos/asf/oozie/tree/0c746678
Diff: http://git-wip-us.apache.org/repos/asf/oozie/diff/0c746678

Branch: refs/heads/master
Commit: 0c74667888d5b963f7d6ee07cb77354fab0aecd1
Parents: 87040a1
Author: Robert Kanter <rk...@cloudera.com>
Authored: Wed Jun 1 16:48:12 2016 -0700
Committer: Robert Kanter <rk...@cloudera.com>
Committed: Wed Jun 1 16:48:12 2016 -0700

----------------------------------------------------------------------
 release-log.txt                                 |  1 +
 .../java/org/apache/oozie/tools/OozieDBCLI.java | 82 +++++++++++---------
 2 files changed, 48 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/oozie/blob/0c746678/release-log.txt
----------------------------------------------------------------------
diff --git a/release-log.txt b/release-log.txt
index e62a6b6..ef211fb 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -1,5 +1,6 @@
 -- Oozie 4.3.0 release (trunk - unreleased)
 
+OOZIE-2546 Improperly closed resources in OozieDBCLI (pbacsko via rkanter)
 OOZIE-2476 When one of the action from fork fails with transient error, WF never joins (puru)
 OOZIE-2475 Oozie does not cleanup action dir of killed actions (satishsaley via rohini)
 OOZIE-2535 User can't disable uber mode (puru)

http://git-wip-us.apache.org/repos/asf/oozie/blob/0c746678/tools/src/main/java/org/apache/oozie/tools/OozieDBCLI.java
----------------------------------------------------------------------
diff --git a/tools/src/main/java/org/apache/oozie/tools/OozieDBCLI.java b/tools/src/main/java/org/apache/oozie/tools/OozieDBCLI.java
index 080fc24..8b3e939 100644
--- a/tools/src/main/java/org/apache/oozie/tools/OozieDBCLI.java
+++ b/tools/src/main/java/org/apache/oozie/tools/OozieDBCLI.java
@@ -568,41 +568,50 @@ public class OozieDBCLI {
 
     private void convertClobToBlobInPostgres(String sqlFile, Connection conn, String startingVersion) throws Exception {
         System.out.println("Converting text columns to bytea for all tables");
-        PrintWriter writer = new PrintWriter(new FileWriter(sqlFile, true));
-        writer.println();
-        Statement statement = conn != null ? conn.createStatement() : null;
-        for (Map.Entry<String, List<String>> tableClobColumnMap : getTableClobColumnMap().entrySet()) {
-            String tableName = tableClobColumnMap.getKey();
-            List<String> columnNames = tableClobColumnMap.getValue();
-            for (String column : columnNames) {
-                if (startingVersion.equals(DB_VERSION_PRE_4_0)
-                        && tableName.equals("COORD_ACTIONS") && column.equals("push_missing_dependencies")) {
-                    // The push_missing_depdencies column was added in DB_VERSION_FOR_4_0 as TEXT and we're going to convert it to
-                    // BYTEA in DB_VERSION_FOR_5_0.  However, if Oozie 5 did the upgrade from DB_VERSION_PRE_4_0 to
-                    // DB_VERSION_FOR_4_0 (and is now doing it for DB_VERSION_FOR_5_0) push_missing_depdencies will already be a
-                    // BYTEA because Oozie 5 created the column instead of Oozie 4; and the update query below will fail.
-                    continue;
-                }
-                String addQuery = getAddColumnQuery(tableName, TEMP_COLUMN_PREFIX + column, "bytea");
-                writer.println(addQuery + ";");
-                String updateQuery = "update " + tableName + " set " + TEMP_COLUMN_PREFIX + column + "=(decode(replace("
-                        + column + ", E'\\\\', E'\\\\\\\\'), 'escape'))";
-                writer.println(updateQuery + ";");
-                String dropQuery = getDropColumnQuery(tableName, column);
-                writer.println(dropQuery + ";");
-                String renameQuery = getRenameColumnQuery(tableName, TEMP_COLUMN_PREFIX + column, column);
-                writer.println(renameQuery + ";");
-                if (statement != null) {
-                    statement.executeUpdate(addQuery);
-                    statement.executeUpdate(updateQuery);
-                    statement.executeUpdate(dropQuery);
-                    statement.executeUpdate(renameQuery);
+        Statement statement = null;
+        PrintWriter writer = null;
+        try {
+            writer = new PrintWriter(new FileWriter(sqlFile, true));
+            writer.println();
+            statement = conn != null ? conn.createStatement() : null;
+
+            for (Map.Entry<String, List<String>> tableClobColumnMap : getTableClobColumnMap().entrySet()) {
+                String tableName = tableClobColumnMap.getKey();
+                List<String> columnNames = tableClobColumnMap.getValue();
+                for (String column : columnNames) {
+                    if (startingVersion.equals(DB_VERSION_PRE_4_0)
+                            && tableName.equals("COORD_ACTIONS") && column.equals("push_missing_dependencies")) {
+                        // The push_missing_depdencies column was added in DB_VERSION_FOR_4_0 as TEXT and we're going to convert it to
+                        // BYTEA in DB_VERSION_FOR_5_0.  However, if Oozie 5 did the upgrade from DB_VERSION_PRE_4_0 to
+                        // DB_VERSION_FOR_4_0 (and is now doing it for DB_VERSION_FOR_5_0) push_missing_depdencies will already be a
+                        // BYTEA because Oozie 5 created the column instead of Oozie 4; and the update query below will fail.
+                        continue;
+                    }
+                    String addQuery = getAddColumnQuery(tableName, TEMP_COLUMN_PREFIX + column, "bytea");
+                    writer.println(addQuery + ";");
+                    String updateQuery = "update " + tableName + " set " + TEMP_COLUMN_PREFIX + column + "=(decode(replace("
+                            + column + ", E'\\\\', E'\\\\\\\\'), 'escape'))";
+                    writer.println(updateQuery + ";");
+                    String dropQuery = getDropColumnQuery(tableName, column);
+                    writer.println(dropQuery + ";");
+                    String renameQuery = getRenameColumnQuery(tableName, TEMP_COLUMN_PREFIX + column, column);
+                    writer.println(renameQuery + ";");
+                    if (statement != null) {
+                        statement.executeUpdate(addQuery);
+                        statement.executeUpdate(updateQuery);
+                        statement.executeUpdate(dropQuery);
+                        statement.executeUpdate(renameQuery);
+                    }
                 }
             }
-        }
-        writer.close();
-        if (statement != null) {
-            statement.close();
+        } finally {
+            if (writer != null) {
+                writer.close();
+            }
+
+            if (statement != null) {
+                statement.close();
+            }
         }
         System.out.println("DONE");
     }
@@ -978,8 +987,9 @@ public class OozieDBCLI {
         writer.close();
         System.out.println("Create OOZIE_SYS table");
         if (run) {
-            Connection conn = createConnection();
+            Connection conn = null;
             try {
+                conn = createConnection();
                 conn.setAutoCommit(true);
                 Statement st = conn.createStatement();
                 st.executeUpdate(CREATE_OOZIE_SYS);
@@ -994,7 +1004,9 @@ public class OozieDBCLI {
                 throw new Exception("Could not create OOZIE_SYS table: " + ex.toString(), ex);
             }
             finally {
-                conn.close();
+                if (conn != null) {
+                    conn.close();
+                }
             }
         }
         System.out.println("DONE");