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

dineshkumar pushed a commit to branch ranger-2.7
in repository https://gitbox.apache.org/repos/asf/ranger.git


The following commit(s) were added to refs/heads/ranger-2.7 by this push:
     new c7e50bcd2 RANGER-5123: Handle Transaction Log Migration for Fresh 
Install
c7e50bcd2 is described below

commit c7e50bcd2ba8c158718534e7075c6b443d9c5be3
Author: Rakesh Gupta <[email protected]>
AuthorDate: Tue Feb 4 11:43:15 2025 +0530

    RANGER-5123: Handle Transaction Log Migration for Fresh Install
    
    Signed-off-by: Dineshkumar Yadav <[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 748632809..286ddd355 100644
--- a/distro/src/main/assembly/admin-web.xml
+++ b/distro/src/main/assembly/admin-web.xml
@@ -591,7 +591,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 bb8ba0b0b..ed6d00826 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
@@ -105,7 +105,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);
         }
@@ -113,6 +115,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;
+        }
+    }
+
     @Override
     public void printStats() {
         stats.logStats();

Reply via email to