This is an automated email from the ASF dual-hosted git repository.

madhan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ranger.git


The following commit(s) were added to refs/heads/master by this push:
     new a1dbe9822 RANGER-5123: handle transaction log migration failure in 
fresh install
a1dbe9822 is described below

commit a1dbe9822a3980586e2e861cdc4655d5cb5545ad
Author: Rakesh Gupta <[email protected]>
AuthorDate: Tue Feb 4 12:09:42 2025 +0530

    RANGER-5123: handle transaction log migration failure in fresh install
    
    Signed-off-by: Madhan Neethiraj <[email protected]>
---
 distro/src/main/assembly/admin-web.xml                     |  3 ++-
 .../scripts/ranger-admin-transaction-log-migrate.sh        |  0
 .../apache/ranger/patch/cliutil/TrxLogV2MigrationUtil.java | 14 +++++++++++++-
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/distro/src/main/assembly/admin-web.xml 
b/distro/src/main/assembly/admin-web.xml
index 54fba59ba..e01362ef5 100644
--- a/distro/src/main/assembly/admin-web.xml
+++ b/distro/src/main/assembly/admin-web.xml
@@ -590,7 +590,8 @@
         <include>changepasswordutil.py</include>
         <include>changeusernameutil.py</include>
         <include>rolebasedusersearchutil.py</include>
-       <include>updateUserAndGroupNamesInJson.py</include>
+        <include>updateUserAndGroupNamesInJson.py</include>
+        <include>ranger-admin-transaction-log-migrate.sh</include>
       </includes>
       <fileMode>544</fileMode>
     </fileSet>
diff --git a/embeddedwebserver/scripts/ranger-admin-transaction-log-migrate.sh 
b/security-admin/scripts/ranger-admin-transaction-log-migrate.sh
similarity index 100%
rename from embeddedwebserver/scripts/ranger-admin-transaction-log-migrate.sh
rename to security-admin/scripts/ranger-admin-transaction-log-migrate.sh
diff --git 
a/security-admin/src/main/java/org/apache/ranger/patch/cliutil/TrxLogV2MigrationUtil.java
 
b/security-admin/src/main/java/org/apache/ranger/patch/cliutil/TrxLogV2MigrationUtil.java
index be582199a..79f7b6d50 100644
--- 
a/security-admin/src/main/java/org/apache/ranger/patch/cliutil/TrxLogV2MigrationUtil.java
+++ 
b/security-admin/src/main/java/org/apache/ranger/patch/cliutil/TrxLogV2MigrationUtil.java
@@ -107,7 +107,9 @@ public void execLoad() {
         logger.info("==> TrxLogV2MigrationUtil.execLoad()");
 
         try {
-            migrateTrxLogs();
+            if (isXTrxLogTableExists()) {
+                migrateTrxLogs();
+            }
         } catch (Exception e) {
             logger.error("Error while migrating trx logs from v1 to v2", e);
         }
@@ -115,6 +117,16 @@ public void execLoad() {
         logger.info("<== TrxLogV2MigrationUtil.execLoad(): migration 
completed. Transaction counts(total: {}, migrated: {}, already-migrated: {}, 
failed: {})", stats.totalCount, stats.migratedCount, 
stats.alreadyMigratedCount, stats.failedCount);
     }
 
+    private boolean isXTrxLogTableExists() {
+        try {
+            // This query checks whether the 'x_trx_log' table exists without 
retrieving any actual data.
+            return !daoMgr.getEntityManager().createNativeQuery("select 
count(*) from x_trx_log where 1=2").getResultList().isEmpty();
+        } catch (Exception e) {
+            logger.warn("Table 'x_trx_log' does not exist. Skipping 
migration.");
+            return false;
+        }
+    }
+
     private void migrateTrxLogs() throws Exception {
         logger.info("==> TrxLogV2MigrationUtil.migrateTrxLogs()");
 

Reply via email to