You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by "difin (via GitHub)" <gi...@apache.org> on 2026/02/03 18:33:10 UTC

[PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

difin opened a new pull request, #6292:
URL: https://github.com/apache/hive/pull/6292

   …ncurrent write operations.
   
   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://cwiki.apache.org/confluence/display/Hive/HowToContribute
     2. Ensure that you have created an issue on the Hive project JIRA: https://issues.apache.org/jira/projects/HIVE/summary
     3. Ensure you have added or run the appropriate tests for your PR: 
     4. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP]HIVE-XXXXX:  Your PR title ...'.
     5. Be sure to keep the PR description updated to reflect all changes.
     6. Please write your PR title to summarize what this PR proposes.
     7. If possible, provide a concise example to reproduce the issue for a faster review.
   
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description, screenshot and/or a reproducable example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Hive versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   -->
   


-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "difin (via GitHub)" <gi...@apache.org>.
difin commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2764519610


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergOutputCommitter.java:
##########
@@ -612,9 +612,10 @@ private void commit(SnapshotUpdate<?> update) {
    */
   private void commitCompaction(Table table, Long snapshotId, long startTime, FilesForCommit results,
       String partitionPath, long fileSizeThreshold) {
-    List<DataFile> existingDataFiles = IcebergCompactionUtil.getDataFiles(table, partitionPath, fileSizeThreshold);
+    List<DataFile> existingDataFiles =
+        IcebergCompactionUtil.getDataFiles(table, snapshotId, partitionPath, fileSizeThreshold);
     List<DeleteFile> existingDeleteFiles = fileSizeThreshold == -1 ?
-        IcebergCompactionUtil.getDeleteFiles(table, partitionPath) : Collections.emptyList();
+        IcebergCompactionUtil.getDeleteFiles(table, snapshotId, partitionPath) : Collections.emptyList();

Review Comment:
   Working on it.



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "difin (via GitHub)" <gi...@apache.org>.
difin commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2764519610


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergOutputCommitter.java:
##########
@@ -612,9 +612,10 @@ private void commit(SnapshotUpdate<?> update) {
    */
   private void commitCompaction(Table table, Long snapshotId, long startTime, FilesForCommit results,
       String partitionPath, long fileSizeThreshold) {
-    List<DataFile> existingDataFiles = IcebergCompactionUtil.getDataFiles(table, partitionPath, fileSizeThreshold);
+    List<DataFile> existingDataFiles =
+        IcebergCompactionUtil.getDataFiles(table, snapshotId, partitionPath, fileSizeThreshold);
     List<DeleteFile> existingDeleteFiles = fileSizeThreshold == -1 ?
-        IcebergCompactionUtil.getDeleteFiles(table, partitionPath) : Collections.emptyList();
+        IcebergCompactionUtil.getDeleteFiles(table, snapshotId, partitionPath) : Collections.emptyList();

Review Comment:
   Done



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2781493032


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/compaction/IcebergTableOptimizer.java:
##########
@@ -212,6 +202,77 @@ private List<Partition> findModifiedPartitions(org.apache.hadoop.hive.ql.metadat
     }
   }
 
+  /**
+   * Checks if there are any modified partitions (with added or deleted files) between a given past
+   * snapshot ID and the table's current (latest) snapshot. This method short-circuits as soon as
+   * it finds any modified partition, making it more efficient than findModifiedPartitions when
+   * only checking for existence.
+   * @param icebergTable The Iceberg table to inspect.
+   * @param pastSnapshotTimeMil The timestamp in milliseconds of the snapshot to check from (exclusive).
+   * @param latestSpecOnly when True, checks partitions with the current spec only;
+   *                       False - older specs only;
+   *                       Null - any spec
+   * @return true if at least one modified partition exists, false otherwise.
+   */
+  private boolean hasModifiedPartitions(org.apache.iceberg.Table icebergTable, Long pastSnapshotTimeMil,
+                                        Boolean latestSpecOnly) {
+    List<Snapshot> relevantSnapshots = getRelevantSnapshots(icebergTable, pastSnapshotTimeMil).toList();
+    if (relevantSnapshots.isEmpty()) {
+      return false;
+    }
+
+    try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
+      // Submit a task for each snapshot and collect the Futures
+      List<Future<Set<String>>> futures = createPartitionNameFutures(
+          executor, icebergTable, relevantSnapshots, latestSpecOnly);
+
+      // Check results as they complete and short-circuit on first non-empty result
+      for (Future<Set<String>> future : futures) {

Review Comment:
   that's not good, blocks in submission order



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6292:
URL: https://github.com/apache/hive/pull/6292#issuecomment-3877139495

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6292) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [2 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6292&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6292&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6292&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6292&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6292&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6292)
   
   


-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "difin (via GitHub)" <gi...@apache.org>.
difin merged PR #6292:
URL: https://github.com/apache/hive/pull/6292


-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2784759057


##########
iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestConflictingDataFiles.java:
##########
@@ -309,4 +310,60 @@ public void testConcurrentInsertAndOverwrite() throws Exception {
     HiveIcebergTestUtils.validateData(expected,
         HiveIcebergTestUtils.valueForRow(schema, objects), 0);
   }
+
+  @Test
+  public void testConcurrentInsertAndCompaction() throws Exception {
+    Assume.assumeTrue(formatVersion >= 2);
+
+    Schema schema = new Schema(
+        required(1, "i", Types.IntegerType.get()),
+        required(2, "p", Types.IntegerType.get())
+    );
+
+    // create and insert an initial batch of records
+    testTables.createTable(shell, "ice_t", schema, PartitionSpec.unpartitioned(), fileFormat, null,
+        formatVersion, Map.of("compactor.threshold.target.size", "1500"), STORAGE_HANDLER_STUB);
+
+    shell.executeStatement("INSERT INTO ice_t values (1, 1), (2, 2), (3, 3)");
+    shell.executeStatement("INSERT INTO ice_t values (10, 10), (20, 20), (30, 30), (40, 40)");
+
+    String[] sql = new String[] {
+        "INSERT INTO ice_t SELECT i*100, p*100 FROM ice_t",
+        "ALTER TABLE ice_t compact 'MAJOR' and wait"

Review Comment:
   please check above, maybe we need to execute IOW with compaction session attributes.
   or fix the synchronization



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2760692171


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergOutputCommitter.java:
##########
@@ -612,9 +612,10 @@ private void commit(SnapshotUpdate<?> update) {
    */
   private void commitCompaction(Table table, Long snapshotId, long startTime, FilesForCommit results,
       String partitionPath, long fileSizeThreshold) {
-    List<DataFile> existingDataFiles = IcebergCompactionUtil.getDataFiles(table, partitionPath, fileSizeThreshold);
+    List<DataFile> existingDataFiles =
+        IcebergCompactionUtil.getDataFiles(table, snapshotId, partitionPath, fileSizeThreshold);
     List<DeleteFile> existingDeleteFiles = fileSizeThreshold == -1 ?
-        IcebergCompactionUtil.getDeleteFiles(table, partitionPath) : Collections.emptyList();
+        IcebergCompactionUtil.getDeleteFiles(table, snapshotId, partitionPath) : Collections.emptyList();

Review Comment:
   please add test. 
   as an example you could use `TestConflictingDataFiles#testConflictingUpdateAndDelete`



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2781968459


##########
iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/test/utils/HiveIcebergStorageHandlerTestUtils.java:
##########
@@ -110,11 +112,35 @@ public static TestHiveShell shell(Map<String, String> configs) {
     shell.setHiveConfValue("hive.notification.event.poll.interval", "-1");
     shell.setHiveConfValue("hive.tez.exec.print.summary", "true");
     shell.setHiveConfValue("tez.counters.max", "1024");
+
+    // Settings for Hive Iceberg Compaction
+    shell.setHiveConfValue(HiveConf.ConfVars.HIVE_LOCK_MANAGER.varname,
+        "org.apache.hadoop.hive.ql.lockmgr.DbLockManager");
+    shell.setHiveConfValue(HiveConf.ConfVars.HIVE_COMPACTOR_WORKER_THREADS.varname, "2");
+    shell.setHiveConfValue(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY.varname, "true");
+    shell.setHiveConfValue(HiveConf.ConfVars.DYNAMIC_PARTITIONING_MODE.varname, "nonstrict");
+    shell.setHiveConfValue(HiveConf.ConfVars.COMPACTOR_CRUD_QUERY_BASED.varname,
+        "true");
+    shell.setHiveConfValue(MetastoreConf.ConfVars.COMPACTOR_WORKER_THREADS.getVarname(), "2");
+    shell.setHiveConfValue(MetastoreConf.ConfVars.HIVE_TXN_MANAGER.getVarname(),
+        "org.apache.hadoop.hive.ql.lockmgr.DbTxnManager");
+    shell.setHiveConfValue(MetastoreConf.ConfVars.COMPACTOR_INITIATOR_ON.getVarname(), "false");
+    shell.setHiveConfValue(MetastoreConf.ConfVars.COMPACTOR_CLEANER_ON.getVarname(), "false");
+
+    // Set jar directory and user install directory for Tez execution (required for compaction)
+    String defaultTempDir = System.getProperty("java.io.tmpdir");
+    shell.setHiveConfValue(HiveConf.ConfVars.HIVE_JAR_DIRECTORY.varname, defaultTempDir);
+    shell.setHiveConfValue(HiveConf.ConfVars.HIVE_USER_INSTALL_DIR.varname, defaultTempDir);
+
     configs.forEach((k, v) -> shell.setHiveConfValue(k, v));
     // We would like to make sure that ORC reading overrides this config, so reading Iceberg tables could work in
     // systems (like Hive 3.2 and higher) where this value is set to true explicitly.
     shell.setHiveConfValue(OrcConf.FORCE_POSITIONAL_EVOLUTION.getHiveConfName(), "true");
     shell.start();
+
+    shell.setHiveSessionValue(HiveConf.ConfVars.METASTORE_CONNECT_URL_KEY.varname,

Review Comment:
   that is weird that we need to pass METASTORE_CONNECT_URL_KEY to a shell



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "difin (via GitHub)" <gi...@apache.org>.
difin commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2784229232


##########
iceberg/iceberg-catalog/src/test/java/org/apache/iceberg/hive/TestHiveMetastore.java:
##########
@@ -195,6 +195,24 @@ public HiveConf hiveConf() {
     return hiveConf;
   }
 
+  /**
+   * Gets the actual connection URL used by the metastore handler.
+   * This is needed because hiveConf() returns the original conf passed to start(),
+   * which may not have the connection URL that was set in the handler's serverConf.
+   */
+  public String getConnectionURL() {

Review Comment:
   > why not move to initConf
   > 
   > ```
   > MetastoreConf.setVar(conf, MetastoreConf.ConfVars.CONNECT_URL_KEY,
   >         "jdbc:derby:" + DERBY_PATH + ";create=true");
   > ```
   
   It doesn't work - when compaction command is analyzed it connects to the default derby in-memory db.
   It only works when this is added in `HiveIcebergStorageHandlerWithEngineBase#executeConcurrently`
   
   ```
               shell.setHiveSessionValue(HiveConf.ConfVars.METASTORE_CONNECT_URL_KEY.varname,
                 shell.metastore().getConnectionURL());
   ```



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6292:
URL: https://github.com/apache/hive/pull/6292#issuecomment-3863324345

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6292) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [4 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6292&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6292&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6292&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6292&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6292&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6292)
   
   


-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "difin (via GitHub)" <gi...@apache.org>.
difin commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2783096874


##########
iceberg/iceberg-catalog/src/test/java/org/apache/iceberg/hive/TestHiveMetastore.java:
##########
@@ -195,6 +195,24 @@ public HiveConf hiveConf() {
     return hiveConf;
   }
 
+  /**
+   * Gets the actual connection URL used by the metastore handler.
+   * This is needed because hiveConf() returns the original conf passed to start(),
+   * which may not have the connection URL that was set in the handler's serverConf.
+   */
+  public String getConnectionURL() {

Review Comment:
   No, `MetaStoreInit.getConnectionURL(Configuration conf)` returns default db url - Derby in-memory:
   `jdbc:derby:memory:/Users/dfingerman/workspace/hive-upstream-difin/iceberg/iceberg-handler/target/tmp/junit_metastore_db;create=true`
   
   ```
     static String getConnectionURL(Configuration conf) {
       return MetastoreConf.getVar(conf, ConfVars.CONNECT_URL_KEY, "");
     }
   ```
   
   Current method returns the correct db url: 
   `shell.metastore().getConnectionURL()`: `jdbc:derby:/var/folders/ks/4pwh80t957gc8q2z7jdblpw80000gq/T/hive3437069780704791128/metastore_db;create=true`



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "difin (via GitHub)" <gi...@apache.org>.
difin commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2784234504


##########
iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/test/utils/HiveIcebergStorageHandlerTestUtils.java:
##########
@@ -110,11 +112,35 @@ public static TestHiveShell shell(Map<String, String> configs) {
     shell.setHiveConfValue("hive.notification.event.poll.interval", "-1");
     shell.setHiveConfValue("hive.tez.exec.print.summary", "true");
     shell.setHiveConfValue("tez.counters.max", "1024");
+
+    // Settings for Hive Iceberg Compaction
+    shell.setHiveConfValue(HiveConf.ConfVars.HIVE_LOCK_MANAGER.varname,
+        "org.apache.hadoop.hive.ql.lockmgr.DbLockManager");
+    shell.setHiveConfValue(HiveConf.ConfVars.HIVE_COMPACTOR_WORKER_THREADS.varname, "2");
+    shell.setHiveConfValue(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY.varname, "true");
+    shell.setHiveConfValue(HiveConf.ConfVars.DYNAMIC_PARTITIONING_MODE.varname, "nonstrict");
+    shell.setHiveConfValue(HiveConf.ConfVars.COMPACTOR_CRUD_QUERY_BASED.varname,
+        "true");
+    shell.setHiveConfValue(MetastoreConf.ConfVars.COMPACTOR_WORKER_THREADS.getVarname(), "2");
+    shell.setHiveConfValue(MetastoreConf.ConfVars.HIVE_TXN_MANAGER.getVarname(),
+        "org.apache.hadoop.hive.ql.lockmgr.DbTxnManager");
+    shell.setHiveConfValue(MetastoreConf.ConfVars.COMPACTOR_INITIATOR_ON.getVarname(), "false");
+    shell.setHiveConfValue(MetastoreConf.ConfVars.COMPACTOR_CLEANER_ON.getVarname(), "false");
+
+    // Set jar directory and user install directory for Tez execution (required for compaction)
+    String defaultTempDir = System.getProperty("java.io.tmpdir");
+    shell.setHiveConfValue(HiveConf.ConfVars.HIVE_JAR_DIRECTORY.varname, defaultTempDir);
+    shell.setHiveConfValue(HiveConf.ConfVars.HIVE_USER_INSTALL_DIR.varname, defaultTempDir);
+
     configs.forEach((k, v) -> shell.setHiveConfValue(k, v));
     // We would like to make sure that ORC reading overrides this config, so reading Iceberg tables could work in
     // systems (like Hive 3.2 and higher) where this value is set to true explicitly.
     shell.setHiveConfValue(OrcConf.FORCE_POSITIONAL_EVOLUTION.getHiveConfName(), "true");
     shell.start();
+
+    shell.setHiveSessionValue(HiveConf.ConfVars.METASTORE_CONNECT_URL_KEY.varname,

Review Comment:
   removed, works without it.



##########
iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandlerWithEngineBase.java:
##########
@@ -327,6 +329,15 @@ protected void executeConcurrently(
             HiveConf.setVar(shell.getHiveConf(), HiveConf.ConfVars.HIVE_QUERY_REEXECUTION_STRATEGIES,
                 retryStrategies);
 
+            HMSHandlerContext.clear();

Review Comment:
   removed



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2781376327


##########
iceberg/iceberg-catalog/src/test/java/org/apache/iceberg/hive/TestHiveMetastore.java:
##########
@@ -195,6 +195,24 @@ public HiveConf hiveConf() {
     return hiveConf;
   }
 
+  /**
+   * Gets the actual connection URL used by the metastore handler.
+   * This is needed because hiveConf() returns the original conf passed to start(),
+   * which may not have the connection URL that was set in the handler's serverConf.
+   */
+  public String getConnectionURL() {

Review Comment:
   is this the code used to set the DB url? 
   ````
     private static void setupMetastoreDB(String dbURL) throws Exception {
       HiveConf conf = new HiveConf();
       MetastoreConf.setVar(conf, MetastoreConf.ConfVars.CONNECT_URL_KEY,
           "jdbc:derby:" + DERBY_PATH + ";create=true");
       TestTxnDbUtil.prepDb(conf);
     }
   ````
   why we use baseHandler.getConf()?



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "difin (via GitHub)" <gi...@apache.org>.
difin commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2783096874


##########
iceberg/iceberg-catalog/src/test/java/org/apache/iceberg/hive/TestHiveMetastore.java:
##########
@@ -195,6 +195,24 @@ public HiveConf hiveConf() {
     return hiveConf;
   }
 
+  /**
+   * Gets the actual connection URL used by the metastore handler.
+   * This is needed because hiveConf() returns the original conf passed to start(),
+   * which may not have the connection URL that was set in the handler's serverConf.
+   */
+  public String getConnectionURL() {

Review Comment:
   No, `MetaStoreInit.getConnectionURL(Configuration conf)` returns default db url - Derby in-memory:
   
   `jdbc:derby:memory:/Users/dfingerman/workspace/hive-upstream-difin/iceberg/iceberg-handler/target/tmp/junit_metastore_db;create=true`
   
   ```
     static String getConnectionURL(Configuration conf) {
       return MetastoreConf.getVar(conf, ConfVars.CONNECT_URL_KEY, "");
     }
   ```
   
   Current method returns the correct file-based derby db url: 
   `shell.metastore().getConnectionURL()`: 
   
   `jdbc:derby:/var/folders/ks/4pwh80t957gc8q2z7jdblpw80000gq/T/hive3437069780704791128/metastore_db;create=true`
   
   This is what took me 1-2 days to find why compaction command wasn't able to resolve correct database during compaction command analysis.



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2760692171


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergOutputCommitter.java:
##########
@@ -612,9 +612,10 @@ private void commit(SnapshotUpdate<?> update) {
    */
   private void commitCompaction(Table table, Long snapshotId, long startTime, FilesForCommit results,
       String partitionPath, long fileSizeThreshold) {
-    List<DataFile> existingDataFiles = IcebergCompactionUtil.getDataFiles(table, partitionPath, fileSizeThreshold);
+    List<DataFile> existingDataFiles =
+        IcebergCompactionUtil.getDataFiles(table, snapshotId, partitionPath, fileSizeThreshold);
     List<DeleteFile> existingDeleteFiles = fileSizeThreshold == -1 ?
-        IcebergCompactionUtil.getDeleteFiles(table, partitionPath) : Collections.emptyList();
+        IcebergCompactionUtil.getDeleteFiles(table, snapshotId, partitionPath) : Collections.emptyList();

Review Comment:
   please add test. see as an example TestConflictingDataFiles#testConflictingUpdateAndDelete



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "difin (via GitHub)" <gi...@apache.org>.
difin commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2783096874


##########
iceberg/iceberg-catalog/src/test/java/org/apache/iceberg/hive/TestHiveMetastore.java:
##########
@@ -195,6 +195,24 @@ public HiveConf hiveConf() {
     return hiveConf;
   }
 
+  /**
+   * Gets the actual connection URL used by the metastore handler.
+   * This is needed because hiveConf() returns the original conf passed to start(),
+   * which may not have the connection URL that was set in the handler's serverConf.
+   */
+  public String getConnectionURL() {

Review Comment:
   > could we reuse MetaStoreInit.getConnectionURL(Configuration conf)
   
   No, `MetaStoreInit.getConnectionURL(Configuration conf)` returns default db url - Derby in-memory:
   
   `jdbc:derby:memory:/Users/dfingerman/workspace/hive-upstream-difin/iceberg/iceberg-handler/target/tmp/junit_metastore_db;create=true`
   
   ```
     static String getConnectionURL(Configuration conf) {
       return MetastoreConf.getVar(conf, ConfVars.CONNECT_URL_KEY, "");
     }
   ```
   
   Current method returns the correct file-based derby db url: 
   `shell.metastore().getConnectionURL()`: 
   
   `jdbc:derby:/var/folders/ks/4pwh80t957gc8q2z7jdblpw80000gq/T/hive3437069780704791128/metastore_db;create=true`
   
   This is what took me 1-2 days to find why compaction command wasn't able to resolve correct database during compaction command analysis.



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2760699005


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/compaction/IcebergCompactionUtil.java:
##########
@@ -88,10 +89,10 @@ public static List<DataFile> getDataFiles(Table table, String partitionPath, lon
    * @param table the iceberg table
    * @param partitionPath partition path
    */
-  public static List<DeleteFile> getDeleteFiles(Table table, String partitionPath) {
+  public static List<DeleteFile> getDeleteFiles(Table table, Long snapshotId, String partitionPath) {
     Table deletesTable =
         MetadataTableUtils.createMetadataTableInstance(table, MetadataTableType.POSITION_DELETES);
-    CloseableIterable<ScanTask> deletesScanTasks = deletesTable.newBatchScan().planFiles();
+    CloseableIterable<ScanTask> deletesScanTasks = deletesTable.newBatchScan().useSnapshot(snapshotId).planFiles();

Review Comment:
   why do you use here newBatchScan() and in getDataFiles newScan()? should we use BatchScan in both places?



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2781974184


##########
iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandlerWithEngineBase.java:
##########
@@ -327,6 +329,15 @@ protected void executeConcurrently(
             HiveConf.setVar(shell.getHiveConf(), HiveConf.ConfVars.HIVE_QUERY_REEXECUTION_STRATEGIES,
                 retryStrategies);
 
+            HMSHandlerContext.clear();

Review Comment:
   why should we do it here?



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2784759057


##########
iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestConflictingDataFiles.java:
##########
@@ -309,4 +310,60 @@ public void testConcurrentInsertAndOverwrite() throws Exception {
     HiveIcebergTestUtils.validateData(expected,
         HiveIcebergTestUtils.valueForRow(schema, objects), 0);
   }
+
+  @Test
+  public void testConcurrentInsertAndCompaction() throws Exception {
+    Assume.assumeTrue(formatVersion >= 2);
+
+    Schema schema = new Schema(
+        required(1, "i", Types.IntegerType.get()),
+        required(2, "p", Types.IntegerType.get())
+    );
+
+    // create and insert an initial batch of records
+    testTables.createTable(shell, "ice_t", schema, PartitionSpec.unpartitioned(), fileFormat, null,
+        formatVersion, Map.of("compactor.threshold.target.size", "1500"), STORAGE_HANDLER_STUB);
+
+    shell.executeStatement("INSERT INTO ice_t values (1, 1), (2, 2), (3, 3)");
+    shell.executeStatement("INSERT INTO ice_t values (10, 10), (20, 20), (30, 30), (40, 40)");
+
+    String[] sql = new String[] {
+        "INSERT INTO ice_t SELECT i*100, p*100 FROM ice_t",
+        "ALTER TABLE ice_t compact 'MAJOR' and wait"

Review Comment:
   please check above, maybe we need to execute IOW with compaction session attributes



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2786672965


##########
iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/test/utils/HiveIcebergStorageHandlerTestUtils.java:
##########
@@ -110,11 +112,35 @@ public static TestHiveShell shell(Map<String, String> configs) {
     shell.setHiveConfValue("hive.notification.event.poll.interval", "-1");
     shell.setHiveConfValue("hive.tez.exec.print.summary", "true");
     shell.setHiveConfValue("tez.counters.max", "1024");
+
+    // Settings for Hive Iceberg Compaction
+    shell.setHiveConfValue(HiveConf.ConfVars.HIVE_LOCK_MANAGER.varname,

Review Comment:
   that is not good actually, DbLockManager should be the default. Isn't ACID default upstream?



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "difin (via GitHub)" <gi...@apache.org>.
difin commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2764518910


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/compaction/IcebergCompactionUtil.java:
##########
@@ -88,10 +89,10 @@ public static List<DataFile> getDataFiles(Table table, String partitionPath, lon
    * @param table the iceberg table
    * @param partitionPath partition path
    */
-  public static List<DeleteFile> getDeleteFiles(Table table, String partitionPath) {
+  public static List<DeleteFile> getDeleteFiles(Table table, Long snapshotId, String partitionPath) {
     Table deletesTable =
         MetadataTableUtils.createMetadataTableInstance(table, MetadataTableType.POSITION_DELETES);
-    CloseableIterable<ScanTask> deletesScanTasks = deletesTable.newBatchScan().planFiles();
+    CloseableIterable<ScanTask> deletesScanTasks = deletesTable.newBatchScan().useSnapshot(snapshotId).planFiles();

Review Comment:
   It was in the existing code, changed to `newScan()`.



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "difin (via GitHub)" <gi...@apache.org>.
difin commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2764518910


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/compaction/IcebergCompactionUtil.java:
##########
@@ -88,10 +89,10 @@ public static List<DataFile> getDataFiles(Table table, String partitionPath, lon
    * @param table the iceberg table
    * @param partitionPath partition path
    */
-  public static List<DeleteFile> getDeleteFiles(Table table, String partitionPath) {
+  public static List<DeleteFile> getDeleteFiles(Table table, Long snapshotId, String partitionPath) {
     Table deletesTable =
         MetadataTableUtils.createMetadataTableInstance(table, MetadataTableType.POSITION_DELETES);
-    CloseableIterable<ScanTask> deletesScanTasks = deletesTable.newBatchScan().planFiles();
+    CloseableIterable<ScanTask> deletesScanTasks = deletesTable.newBatchScan().useSnapshot(snapshotId).planFiles();

Review Comment:
   It was in the existing code, changed to `newScan()`.
   Changed to use `BatchScan` in both places.



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "difin (via GitHub)" <gi...@apache.org>.
difin commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2783096874


##########
iceberg/iceberg-catalog/src/test/java/org/apache/iceberg/hive/TestHiveMetastore.java:
##########
@@ -195,6 +195,24 @@ public HiveConf hiveConf() {
     return hiveConf;
   }
 
+  /**
+   * Gets the actual connection URL used by the metastore handler.
+   * This is needed because hiveConf() returns the original conf passed to start(),
+   * which may not have the connection URL that was set in the handler's serverConf.
+   */
+  public String getConnectionURL() {

Review Comment:
   No, `MetaStoreInit.getConnectionURL(Configuration conf)` returns default db url - Derby in-memory:
   
   `jdbc:derby:memory:/Users/dfingerman/workspace/hive-upstream-difin/iceberg/iceberg-handler/target/tmp/junit_metastore_db;create=true`
   
   ```
     static String getConnectionURL(Configuration conf) {
       return MetastoreConf.getVar(conf, ConfVars.CONNECT_URL_KEY, "");
     }
   ```
   
   Current method returns the correct file-based derby db url: 
   `shell.metastore().getConnectionURL()`: 
   
   `jdbc:derby:/var/folders/ks/4pwh80t957gc8q2z7jdblpw80000gq/T/hive3437069780704791128/metastore_db;create=true`



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2784746364


##########
iceberg/iceberg-catalog/src/test/java/org/apache/iceberg/hive/TestHiveMetastore.java:
##########
@@ -195,6 +195,24 @@ public HiveConf hiveConf() {
     return hiveConf;
   }
 
+  /**
+   * Gets the actual connection URL used by the metastore handler.
+   * This is needed because hiveConf() returns the original conf passed to start(),
+   * which may not have the connection URL that was set in the handler's serverConf.
+   */
+  public String getConnectionURL() {

Review Comment:
   ok, but what about metastore().getConnectionURL() do we always go with fallback? can we set CONNECT_URL_KEY in init and then return in getConnectionURL()?



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2781962627


##########
iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/test/utils/HiveIcebergStorageHandlerTestUtils.java:
##########
@@ -110,11 +112,35 @@ public static TestHiveShell shell(Map<String, String> configs) {
     shell.setHiveConfValue("hive.notification.event.poll.interval", "-1");
     shell.setHiveConfValue("hive.tez.exec.print.summary", "true");
     shell.setHiveConfValue("tez.counters.max", "1024");
+
+    // Settings for Hive Iceberg Compaction
+    shell.setHiveConfValue(HiveConf.ConfVars.HIVE_LOCK_MANAGER.varname,

Review Comment:
   do not set configs that are already defaults



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "difin (via GitHub)" <gi...@apache.org>.
difin commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2784229232


##########
iceberg/iceberg-catalog/src/test/java/org/apache/iceberg/hive/TestHiveMetastore.java:
##########
@@ -195,6 +195,24 @@ public HiveConf hiveConf() {
     return hiveConf;
   }
 
+  /**
+   * Gets the actual connection URL used by the metastore handler.
+   * This is needed because hiveConf() returns the original conf passed to start(),
+   * which may not have the connection URL that was set in the handler's serverConf.
+   */
+  public String getConnectionURL() {

Review Comment:
   > why not move to initConf
   > 
   > ```
   > MetastoreConf.setVar(conf, MetastoreConf.ConfVars.CONNECT_URL_KEY,
   >         "jdbc:derby:" + DERBY_PATH + ";create=true");
   > ```
   
   It doesn't work - when compaction command is being analyzed it connects to the default derby in-memory db.
   It only works when this is added in `HiveIcebergStorageHandlerWithEngineBase#executeConcurrently`
   
   ```
               shell.setHiveSessionValue(HiveConf.ConfVars.METASTORE_CONNECT_URL_KEY.varname,
                 shell.metastore().getConnectionURL());
   ```



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "difin (via GitHub)" <gi...@apache.org>.
difin commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2783096874


##########
iceberg/iceberg-catalog/src/test/java/org/apache/iceberg/hive/TestHiveMetastore.java:
##########
@@ -195,6 +195,24 @@ public HiveConf hiveConf() {
     return hiveConf;
   }
 
+  /**
+   * Gets the actual connection URL used by the metastore handler.
+   * This is needed because hiveConf() returns the original conf passed to start(),
+   * which may not have the connection URL that was set in the handler's serverConf.
+   */
+  public String getConnectionURL() {

Review Comment:
   No, `MetaStoreInit.getConnectionURL(Configuration conf)` returns default db url - Derby in-memory:
   
   `jdbc:derby:memory:/Users/dfingerman/workspace/hive-upstream-difin/iceberg/iceberg-handler/target/tmp/junit_metastore_db;create=true`
   
   ```
     static String getConnectionURL(Configuration conf) {
       return MetastoreConf.getVar(conf, ConfVars.CONNECT_URL_KEY, "");
     }
   ```
   
   Current method returns the correct db url: 
   `shell.metastore().getConnectionURL()`: `jdbc:derby:/var/folders/ks/4pwh80t957gc8q2z7jdblpw80000gq/T/hive3437069780704791128/metastore_db;create=true`



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6292:
URL: https://github.com/apache/hive/pull/6292#issuecomment-3875150759

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6292) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [26 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6292&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6292&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6292&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6292&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.7% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6292&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6292)
   
   


-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2781493032


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/compaction/IcebergTableOptimizer.java:
##########
@@ -212,6 +202,77 @@ private List<Partition> findModifiedPartitions(org.apache.hadoop.hive.ql.metadat
     }
   }
 
+  /**
+   * Checks if there are any modified partitions (with added or deleted files) between a given past
+   * snapshot ID and the table's current (latest) snapshot. This method short-circuits as soon as
+   * it finds any modified partition, making it more efficient than findModifiedPartitions when
+   * only checking for existence.
+   * @param icebergTable The Iceberg table to inspect.
+   * @param pastSnapshotTimeMil The timestamp in milliseconds of the snapshot to check from (exclusive).
+   * @param latestSpecOnly when True, checks partitions with the current spec only;
+   *                       False - older specs only;
+   *                       Null - any spec
+   * @return true if at least one modified partition exists, false otherwise.
+   */
+  private boolean hasModifiedPartitions(org.apache.iceberg.Table icebergTable, Long pastSnapshotTimeMil,
+                                        Boolean latestSpecOnly) {
+    List<Snapshot> relevantSnapshots = getRelevantSnapshots(icebergTable, pastSnapshotTimeMil).toList();
+    if (relevantSnapshots.isEmpty()) {
+      return false;
+    }
+
+    try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
+      // Submit a task for each snapshot and collect the Futures
+      List<Future<Set<String>>> futures = createPartitionNameFutures(
+          executor, icebergTable, relevantSnapshots, latestSpecOnly);
+
+      // Check results as they complete and short-circuit on first non-empty result
+      for (Future<Set<String>> future : futures) {

Review Comment:
   that's not good, blocks in submission order
   
   ````
    CompletionService<Set<String>> completionService =
         new ExecutorCompletionService<>(executor);
   
     int taskCount = createPartitionNameTasks(
         completionService, icebergTable, relevantSnapshots, latestSpecOnly);
   
     for (int i = 0; i < taskCount; i++) {
       Set<String> partitionNames = completionService.take().get();
       if (!partitionNames.isEmpty()) {
         return true;
       }
     }
   ````



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2781493032


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/compaction/IcebergTableOptimizer.java:
##########
@@ -212,6 +202,77 @@ private List<Partition> findModifiedPartitions(org.apache.hadoop.hive.ql.metadat
     }
   }
 
+  /**
+   * Checks if there are any modified partitions (with added or deleted files) between a given past
+   * snapshot ID and the table's current (latest) snapshot. This method short-circuits as soon as
+   * it finds any modified partition, making it more efficient than findModifiedPartitions when
+   * only checking for existence.
+   * @param icebergTable The Iceberg table to inspect.
+   * @param pastSnapshotTimeMil The timestamp in milliseconds of the snapshot to check from (exclusive).
+   * @param latestSpecOnly when True, checks partitions with the current spec only;
+   *                       False - older specs only;
+   *                       Null - any spec
+   * @return true if at least one modified partition exists, false otherwise.
+   */
+  private boolean hasModifiedPartitions(org.apache.iceberg.Table icebergTable, Long pastSnapshotTimeMil,
+                                        Boolean latestSpecOnly) {
+    List<Snapshot> relevantSnapshots = getRelevantSnapshots(icebergTable, pastSnapshotTimeMil).toList();
+    if (relevantSnapshots.isEmpty()) {
+      return false;
+    }
+
+    try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
+      // Submit a task for each snapshot and collect the Futures
+      List<Future<Set<String>>> futures = createPartitionNameFutures(
+          executor, icebergTable, relevantSnapshots, latestSpecOnly);
+
+      // Check results as they complete and short-circuit on first non-empty result
+      for (Future<Set<String>> future : futures) {

Review Comment:
   that's not good, blocks in submission order
   
   ````
   private static <T, R> R executeAndConsume(
       ExecutorService executor,
       List<Callable<T>> tasks,
       BiFunction<R, T, Boolean> consumer,
       Supplier<R> resultSupplier
   ) throws InterruptedException, ExecutionException {
   
     CompletionService<T> cs = new ExecutorCompletionService<>(executor);
   
     for (Callable<T> task : tasks) {
       cs.submit(task);
     }
   
     R result = resultSupplier.get();
   
     for (int i = 0; i < tasks.size(); i++) {
       T value = cs.take().get();
       boolean shouldStop = consumer.apply(result, value);
       if (shouldStop) {
         return result;
       }
     }
   
     return result;
   }
   ````
   1. hasModifiedPartitions
   ````
   try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
   
     List<Callable<Set<String>>> tasks =
         createPartitionNameTasks(icebergTable, relevantSnapshots, latestSpecOnly);
   
     Boolean found = executeAndConsume(
         executor,
         tasks,
         (ignored, partitions) -> !partitions.isEmpty(),
         () -> false
     );
   
     return found;
   
   } 
   ````
   
   2. findModifiedPartitions
   
   ````
   try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
   
     List<Callable<Set<String>>> tasks =
         createPartitionNameTasks(icebergTable, relevantSnapshots, latestSpecOnly);
   
     Set<String> modifiedPartitions = executeAndConsume(
         executor,
         tasks,
         (acc, partitions) -> {
           acc.addAll(partitions);
           return false; // never short-circuit
         },
         Sets::newHashSet
     );
   
     return IcebergTableUtil.convertNameToMetastorePartition(
         hiveTable, modifiedPartitions);
   
   }
   ````



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2781981107


##########
iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandlerWithEngineBase.java:
##########
@@ -327,6 +329,15 @@ protected void executeConcurrently(
             HiveConf.setVar(shell.getHiveConf(), HiveConf.ConfVars.HIVE_QUERY_REEXECUTION_STRATEGIES,
                 retryStrategies);
 
+            HMSHandlerContext.clear();
+            String metastoreConnectUrl = shell.metastore().getConnectionURL();
+            Configuration shellConf = shell.getHiveConf();
+
+            if (metastoreConnectUrl != null) {
+              shellConf.set(HiveConf.ConfVars.METASTORE_CONNECT_URL_KEY.varname, metastoreConnectUrl);

Review Comment:
   i am not convinced we should be doing this. can't we set globally METASTORE_CONNECT_URL_KEY?
   like     System.setProperty(HiveConf.ConfVars.METASTORE_CONNECT_URL_KEY.varname,
           MetastoreConf.getVar(hiveConf, MetastoreConf.ConfVars.CONNECT_URL_KEY));



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6292:
URL: https://github.com/apache/hive/pull/6292#issuecomment-3850039545

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6292) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6292&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6292&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6292&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6292&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6292&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6292)
   
   


-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6292:
URL: https://github.com/apache/hive/pull/6292#issuecomment-3843288319

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6292) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6292&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6292&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6292&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6292&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6292&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6292)
   
   


-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2760699005


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/compaction/IcebergCompactionUtil.java:
##########
@@ -88,10 +89,10 @@ public static List<DataFile> getDataFiles(Table table, String partitionPath, lon
    * @param table the iceberg table
    * @param partitionPath partition path
    */
-  public static List<DeleteFile> getDeleteFiles(Table table, String partitionPath) {
+  public static List<DeleteFile> getDeleteFiles(Table table, Long snapshotId, String partitionPath) {
     Table deletesTable =
         MetadataTableUtils.createMetadataTableInstance(table, MetadataTableType.POSITION_DELETES);
-    CloseableIterable<ScanTask> deletesScanTasks = deletesTable.newBatchScan().planFiles();
+    CloseableIterable<ScanTask> deletesScanTasks = deletesTable.newBatchScan().useSnapshot(snapshotId).planFiles();

Review Comment:
   why do you use here newBatchScan() and in getDataFiles newScan()?



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2783560373


##########
iceberg/iceberg-catalog/src/test/java/org/apache/iceberg/hive/TestHiveMetastore.java:
##########
@@ -195,6 +195,24 @@ public HiveConf hiveConf() {
     return hiveConf;
   }
 
+  /**
+   * Gets the actual connection URL used by the metastore handler.
+   * This is needed because hiveConf() returns the original conf passed to start(),
+   * which may not have the connection URL that was set in the handler's serverConf.
+   */
+  public String getConnectionURL() {

Review Comment:
   are we using fallback here?
   // Fallback: construct from DERBY_PATH pattern
   return "jdbc:derby:" + DERBY_PATH + ";create=true";
   
   someone should be setting the CONNECT_URL_KEY, otherwise, how everything else works?
   is this the place?
   ````
     private static void setupMetastoreDB(String dbURL) throws Exception {
       HiveConf conf = new HiveConf();
       MetastoreConf.setVar(conf, MetastoreConf.ConfVars.CONNECT_URL_KEY,
           "jdbc:derby:" + DERBY_PATH + ";create=true");
       TestTxnDbUtil.prepDb(conf);
     }
   ````
   
   why not move to initConf
   ````
   MetastoreConf.setVar(conf, MetastoreConf.ConfVars.CONNECT_URL_KEY,
           "jdbc:derby:" + DERBY_PATH + ";create=true");
   ````



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2781493032


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/compaction/IcebergTableOptimizer.java:
##########
@@ -212,6 +202,77 @@ private List<Partition> findModifiedPartitions(org.apache.hadoop.hive.ql.metadat
     }
   }
 
+  /**
+   * Checks if there are any modified partitions (with added or deleted files) between a given past
+   * snapshot ID and the table's current (latest) snapshot. This method short-circuits as soon as
+   * it finds any modified partition, making it more efficient than findModifiedPartitions when
+   * only checking for existence.
+   * @param icebergTable The Iceberg table to inspect.
+   * @param pastSnapshotTimeMil The timestamp in milliseconds of the snapshot to check from (exclusive).
+   * @param latestSpecOnly when True, checks partitions with the current spec only;
+   *                       False - older specs only;
+   *                       Null - any spec
+   * @return true if at least one modified partition exists, false otherwise.
+   */
+  private boolean hasModifiedPartitions(org.apache.iceberg.Table icebergTable, Long pastSnapshotTimeMil,
+                                        Boolean latestSpecOnly) {
+    List<Snapshot> relevantSnapshots = getRelevantSnapshots(icebergTable, pastSnapshotTimeMil).toList();
+    if (relevantSnapshots.isEmpty()) {
+      return false;
+    }
+
+    try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
+      // Submit a task for each snapshot and collect the Futures
+      List<Future<Set<String>>> futures = createPartitionNameFutures(
+          executor, icebergTable, relevantSnapshots, latestSpecOnly);
+
+      // Check results as they complete and short-circuit on first non-empty result
+      for (Future<Set<String>> future : futures) {

Review Comment:
   that's not good, blocks in submission order
   
   ````
   private <R> R findModifiedPartitionsInternal(
       org.apache.iceberg.Table icebergTable,
       Long pastSnapshotTimeMil,
       Boolean latestSpecOnly,
       Supplier<R> resultSupplier,
       BiFunction<R, Set<String>, Boolean> resultConsumer
   ) {
   
     List<Snapshot> relevantSnapshots =
         getRelevantSnapshots(icebergTable, pastSnapshotTimeMil).toList();
   
     R result = resultSupplier.get();
     if (relevantSnapshots.isEmpty()) {
       return result;
     }
   
     List<Callable<Set<String>>> tasks =
         createPartitionNameTasks(icebergTable, relevantSnapshots, latestSpecOnly);
   
     try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
       CompletionService<Set<String>> cs = new ExecutorCompletionService<>(executor);
   
       // submit tasks
       for (Callable<Set<String>> task : tasks) {
         cs.submit(task);
       }
   
       // process results
       for (int i = 0; i < tasks.size(); i++) {
         if (resultConsumer.apply(result, cs.take().get())) {
           return (R) Boolean.TRUE; // short-circuit
         }
       }
   
       return result;
   
     } catch (InterruptedException e) {
       Thread.currentThread().interrupt();
       throw new RuntimeMetaException(
           e, "Interrupted while processing modified partitions");
     } catch (ExecutionException e) {
       throw new RuntimeMetaException(
           e, "Failed to process modified partitions in parallel");
     }
   }
   
   private boolean hasModifiedPartitions(
       org.apache.iceberg.Table icebergTable,
       Long pastSnapshotTimeMil,
       Boolean latestSpecOnly) {
   
     return findModifiedPartitionsInternal(
         icebergTable,
         pastSnapshotTimeMil,
         latestSpecOnly,
         () -> false,
         (ignored, partitions) -> !partitions.isEmpty()
     );
   }
   
   private List<Partition> findModifiedPartitions(
       org.apache.hadoop.hive.ql.metadata.Table hiveTable,
       org.apache.iceberg.Table icebergTable,
       Long pastSnapshotTimeMil,
       Boolean latestSpecOnly) {
   
     Set<String> modifiedPartitions = findModifiedPartitionsInternal(
         icebergTable,
         pastSnapshotTimeMil,
         latestSpecOnly,
         Sets::newHashSet,
         (acc, partitions) -> { 
             acc.addAll(partitions); 
             return false; // never short-circuit
         }
     );
   
     return IcebergTableUtil.convertNameToMetastorePartition(
         hiveTable, modifiedPartitions);
   }
   
   private List<Callable<Set<String>>> createPartitionNameTasks(
       org.apache.iceberg.Table icebergTable,
       List<Snapshot> relevantSnapshots,
       Boolean latestSpecOnly) {
   
     return relevantSnapshots.stream()
         .map(snapshot -> (Callable<Set<String>>) () ->
             IcebergTableUtil.getPartitionNames(
                 icebergTable,
                 getAffectedFiles(snapshot, icebergTable.io()),
                 latestSpecOnly))
         .toList();
   }
   
   private List<ContentFile<?>> getAffectedFiles(Snapshot snapshot, FileIO io) {
       return FluentIterable.<ContentFile<?>>concat(
               snapshot.addedDataFiles(io),
               snapshot.removedDataFiles(io),
               snapshot.addedDeleteFiles(io),
               snapshot.removedDeleteFiles(io))
           .toList();
   }
   
   ````



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "difin (via GitHub)" <gi...@apache.org>.
difin commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2784318656


##########
iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/test/utils/HiveIcebergStorageHandlerTestUtils.java:
##########
@@ -110,11 +112,35 @@ public static TestHiveShell shell(Map<String, String> configs) {
     shell.setHiveConfValue("hive.notification.event.poll.interval", "-1");
     shell.setHiveConfValue("hive.tez.exec.print.summary", "true");
     shell.setHiveConfValue("tez.counters.max", "1024");
+
+    // Settings for Hive Iceberg Compaction
+    shell.setHiveConfValue(HiveConf.ConfVars.HIVE_LOCK_MANAGER.varname,

Review Comment:
   HiveConf:
   
   `    HIVE_LOCK_MANAGER("hive.lock.manager", "org.apache.hadoop.hive.ql.lockmgr.zookeeper.ZooKeeperHiveLockManager", ""),`
   
   Where is this defined as default?



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6292:
URL: https://github.com/apache/hive/pull/6292#issuecomment-3879129528

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6292) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [2 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6292&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6292&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6292&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6292&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6292&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6292)
   
   


-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6292:
URL: https://github.com/apache/hive/pull/6292#issuecomment-3856756767

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6292) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [4 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6292&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6292&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6292&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6292&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6292&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6292)
   
   


-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2783560373


##########
iceberg/iceberg-catalog/src/test/java/org/apache/iceberg/hive/TestHiveMetastore.java:
##########
@@ -195,6 +195,24 @@ public HiveConf hiveConf() {
     return hiveConf;
   }
 
+  /**
+   * Gets the actual connection URL used by the metastore handler.
+   * This is needed because hiveConf() returns the original conf passed to start(),
+   * which may not have the connection URL that was set in the handler's serverConf.
+   */
+  public String getConnectionURL() {

Review Comment:
   are we using fallback here?
   ````
   // Fallback: construct from DERBY_PATH pattern
   return "jdbc:derby:" + DERBY_PATH + ";create=true";
   ````
   someone should be setting the CONNECT_URL_KEY, otherwise, how everything else works? 
   
   is this the place?
   
   ````
     private static void setupMetastoreDB(String dbURL) throws Exception {
       HiveConf conf = new HiveConf();
       MetastoreConf.setVar(conf, MetastoreConf.ConfVars.CONNECT_URL_KEY,
           "jdbc:derby:" + DERBY_PATH + ";create=true");
       TestTxnDbUtil.prepDb(conf);
     }
   ````
   



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2783560373


##########
iceberg/iceberg-catalog/src/test/java/org/apache/iceberg/hive/TestHiveMetastore.java:
##########
@@ -195,6 +195,24 @@ public HiveConf hiveConf() {
     return hiveConf;
   }
 
+  /**
+   * Gets the actual connection URL used by the metastore handler.
+   * This is needed because hiveConf() returns the original conf passed to start(),
+   * which may not have the connection URL that was set in the handler's serverConf.
+   */
+  public String getConnectionURL() {

Review Comment:
   are we using fallback here?
   ````
   // Fallback: construct from DERBY_PATH pattern
   return "jdbc:derby:" + DERBY_PATH + ";create=true";
   ````
   someone should be setting the CONNECT_URL_KEY, otherwise, how everything else works? 



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2784746364


##########
iceberg/iceberg-catalog/src/test/java/org/apache/iceberg/hive/TestHiveMetastore.java:
##########
@@ -195,6 +195,24 @@ public HiveConf hiveConf() {
     return hiveConf;
   }
 
+  /**
+   * Gets the actual connection URL used by the metastore handler.
+   * This is needed because hiveConf() returns the original conf passed to start(),
+   * which may not have the connection URL that was set in the handler's serverConf.
+   */
+  public String getConnectionURL() {

Review Comment:
   ok, but what about metastore().getConnectionURL() do we always go with fallback?



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2781376327


##########
iceberg/iceberg-catalog/src/test/java/org/apache/iceberg/hive/TestHiveMetastore.java:
##########
@@ -195,6 +195,24 @@ public HiveConf hiveConf() {
     return hiveConf;
   }
 
+  /**
+   * Gets the actual connection URL used by the metastore handler.
+   * This is needed because hiveConf() returns the original conf passed to start(),
+   * which may not have the connection URL that was set in the handler's serverConf.
+   */
+  public String getConnectionURL() {

Review Comment:
   could we use
   ````HiveSchemaHelper.getValidConfVar(MetastoreConf.ConfVars.CONNECT_URL_KEY, hiveConf)````?



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2781493032


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/compaction/IcebergTableOptimizer.java:
##########
@@ -212,6 +202,77 @@ private List<Partition> findModifiedPartitions(org.apache.hadoop.hive.ql.metadat
     }
   }
 
+  /**
+   * Checks if there are any modified partitions (with added or deleted files) between a given past
+   * snapshot ID and the table's current (latest) snapshot. This method short-circuits as soon as
+   * it finds any modified partition, making it more efficient than findModifiedPartitions when
+   * only checking for existence.
+   * @param icebergTable The Iceberg table to inspect.
+   * @param pastSnapshotTimeMil The timestamp in milliseconds of the snapshot to check from (exclusive).
+   * @param latestSpecOnly when True, checks partitions with the current spec only;
+   *                       False - older specs only;
+   *                       Null - any spec
+   * @return true if at least one modified partition exists, false otherwise.
+   */
+  private boolean hasModifiedPartitions(org.apache.iceberg.Table icebergTable, Long pastSnapshotTimeMil,
+                                        Boolean latestSpecOnly) {
+    List<Snapshot> relevantSnapshots = getRelevantSnapshots(icebergTable, pastSnapshotTimeMil).toList();
+    if (relevantSnapshots.isEmpty()) {
+      return false;
+    }
+
+    try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
+      // Submit a task for each snapshot and collect the Futures
+      List<Future<Set<String>>> futures = createPartitionNameFutures(
+          executor, icebergTable, relevantSnapshots, latestSpecOnly);
+
+      // Check results as they complete and short-circuit on first non-empty result
+      for (Future<Set<String>> future : futures) {

Review Comment:
   that's not good, blocks in submission order
   
   ````
   private <R> R findModifiedPartitionsInternal(
       org.apache.iceberg.Table icebergTable,
       Long pastSnapshotTimeMil,
       Boolean latestSpecOnly,
       Supplier<R> resultSupplier,
       BiFunction<R, Set<String>, Boolean> resultConsumer
   ) {
   
     List<Snapshot> relevantSnapshots =
         getRelevantSnapshots(icebergTable, pastSnapshotTimeMil).toList();
   
     R result = resultSupplier.get();
     if (relevantSnapshots.isEmpty()) {
       return result;
     }
   
     List<Callable<Set<String>>> tasks =
         createPartitionNameTasks(icebergTable, relevantSnapshots, latestSpecOnly);
   
     try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
       CompletionService<Set<String>> cs = new ExecutorCompletionService<>(executor);
   
       // submit tasks
       for (Callable<Set<String>> task : tasks) {
         cs.submit(task);
       }
   
       // process results
       for (int i = 0; i < tasks.size(); i++) {
         Set<String> partitions = cs.take().get();
         if (resultConsumer.apply(result, partitions)) {
           return (R) Boolean.TRUE; // short-circuit
         }
       }
   
       return result;
   
     } catch (InterruptedException e) {
       Thread.currentThread().interrupt();
       throw new RuntimeMetaException(
           e, "Interrupted while processing modified partitions");
     } catch (ExecutionException e) {
       throw new RuntimeMetaException(
           e, "Failed to process modified partitions in parallel");
     }
   }
   
   private boolean hasModifiedPartitions(
       org.apache.iceberg.Table icebergTable,
       Long pastSnapshotTimeMil,
       Boolean latestSpecOnly) {
   
     return findModifiedPartitionsInternal(
         icebergTable,
         pastSnapshotTimeMil,
         latestSpecOnly,
         () -> false,
         (ignored, partitions) -> !partitions.isEmpty()
     );
   }
   
   private List<Partition> findModifiedPartitions(
       org.apache.hadoop.hive.ql.metadata.Table hiveTable,
       org.apache.iceberg.Table icebergTable,
       Long pastSnapshotTimeMil,
       Boolean latestSpecOnly) {
   
     Set<String> modifiedPartitions = findModifiedPartitionsInternal(
         icebergTable,
         pastSnapshotTimeMil,
         latestSpecOnly,
         Sets::newHashSet,
         (acc, partitions) -> { 
             acc.addAll(partitions); 
             return false; // never short-circuit
         }
     );
   
     return IcebergTableUtil.convertNameToMetastorePartition(
         hiveTable, modifiedPartitions);
   }
   
   private List<Callable<Set<String>>> createPartitionNameTasks(
       org.apache.iceberg.Table icebergTable,
       List<Snapshot> relevantSnapshots,
       Boolean latestSpecOnly) {
   
     return relevantSnapshots.stream()
         .map(snapshot -> (Callable<Set<String>>) () -> {
           FileIO io = icebergTable.io();
           List<ContentFile<?>> affectedFiles =
               FluentIterable.<ContentFile<?>>concat(
                       snapshot.addedDataFiles(io),
                       snapshot.removedDataFiles(io),
                       snapshot.addedDeleteFiles(io),
                       snapshot.removedDeleteFiles(io))
                   .toList();
   
           return IcebergTableUtil.getPartitionNames(
               icebergTable, affectedFiles, latestSpecOnly);
         })
         .toList();
   }
   
   ````



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2781998193


##########
iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestConflictingDataFiles.java:
##########
@@ -309,4 +310,60 @@ public void testConcurrentInsertAndOverwrite() throws Exception {
     HiveIcebergTestUtils.validateData(expected,
         HiveIcebergTestUtils.valueForRow(schema, objects), 0);
   }
+
+  @Test
+  public void testConcurrentInsertAndCompaction() throws Exception {
+    Assume.assumeTrue(formatVersion >= 2);
+
+    Schema schema = new Schema(
+        required(1, "i", Types.IntegerType.get()),
+        required(2, "p", Types.IntegerType.get())
+    );
+
+    // create and insert an initial batch of records
+    testTables.createTable(shell, "ice_t", schema, PartitionSpec.unpartitioned(), fileFormat, null,
+        formatVersion, Map.of("compactor.threshold.target.size", "1500"), STORAGE_HANDLER_STUB);
+
+    shell.executeStatement("INSERT INTO ice_t values (1, 1), (2, 2), (3, 3)");
+    shell.executeStatement("INSERT INTO ice_t values (10, 10), (20, 20), (30, 30), (40, 40)");
+
+    String[] sql = new String[] {
+        "INSERT INTO ice_t SELECT i*100, p*100 FROM ice_t",
+        "ALTER TABLE ice_t compact 'MAJOR' and wait"

Review Comment:
   i don't think that is a proper test. 
   ALTER TABLE ice_t compact 'MAJOR' would initiate new IOW query, would it synchronize with INSERT?  HiveIcebergStorageHandlerStub#waitForAllWritesToComplete



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2783560373


##########
iceberg/iceberg-catalog/src/test/java/org/apache/iceberg/hive/TestHiveMetastore.java:
##########
@@ -195,6 +195,24 @@ public HiveConf hiveConf() {
     return hiveConf;
   }
 
+  /**
+   * Gets the actual connection URL used by the metastore handler.
+   * This is needed because hiveConf() returns the original conf passed to start(),
+   * which may not have the connection URL that was set in the handler's serverConf.
+   */
+  public String getConnectionURL() {

Review Comment:
   are we using fallback here?
   // Fallback: construct from DERBY_PATH pattern
   return "jdbc:derby:" + DERBY_PATH + ";create=true";
   
   someone should be setting the CONNECT_URL_KEY, otherwise, how everything else works?
   is this the place?
     private static void setupMetastoreDB(String dbURL) throws Exception {
       HiveConf conf = new HiveConf();
       MetastoreConf.setVar(conf, MetastoreConf.ConfVars.CONNECT_URL_KEY,
           "jdbc:derby:" + DERBY_PATH + ";create=true");
       TestTxnDbUtil.prepDb(conf);
     }
   
   why not move to initConf
   ````
   MetastoreConf.setVar(conf, MetastoreConf.ConfVars.CONNECT_URL_KEY,
           "jdbc:derby:" + DERBY_PATH + ";create=true");
   ````



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2781376327


##########
iceberg/iceberg-catalog/src/test/java/org/apache/iceberg/hive/TestHiveMetastore.java:
##########
@@ -195,6 +195,24 @@ public HiveConf hiveConf() {
     return hiveConf;
   }
 
+  /**
+   * Gets the actual connection URL used by the metastore handler.
+   * This is needed because hiveConf() returns the original conf passed to start(),
+   * which may not have the connection URL that was set in the handler's serverConf.
+   */
+  public String getConnectionURL() {

Review Comment:
   is this the code used to set the DB url? 
   ````
     private static void setupMetastoreDB(String dbURL) throws Exception {
       HiveConf conf = new HiveConf();
       MetastoreConf.setVar(conf, MetastoreConf.ConfVars.CONNECT_URL_KEY,
           "jdbc:derby:" + DERBY_PATH + ";create=true");
       TestTxnDbUtil.prepDb(conf);
     }
   ````
   why we use baseHandler.getConf()?
   
   could we reuse MetaStoreInit.getConnectionURL(Configuration conf)



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29437: Iceberg: Fix concurrency issues between compaction and co… [hive]

Posted by "difin (via GitHub)" <gi...@apache.org>.
difin commented on code in PR #6292:
URL: https://github.com/apache/hive/pull/6292#discussion_r2783669226


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/compaction/IcebergTableOptimizer.java:
##########
@@ -212,6 +202,77 @@ private List<Partition> findModifiedPartitions(org.apache.hadoop.hive.ql.metadat
     }
   }
 
+  /**
+   * Checks if there are any modified partitions (with added or deleted files) between a given past
+   * snapshot ID and the table's current (latest) snapshot. This method short-circuits as soon as
+   * it finds any modified partition, making it more efficient than findModifiedPartitions when
+   * only checking for existence.
+   * @param icebergTable The Iceberg table to inspect.
+   * @param pastSnapshotTimeMil The timestamp in milliseconds of the snapshot to check from (exclusive).
+   * @param latestSpecOnly when True, checks partitions with the current spec only;
+   *                       False - older specs only;
+   *                       Null - any spec
+   * @return true if at least one modified partition exists, false otherwise.
+   */
+  private boolean hasModifiedPartitions(org.apache.iceberg.Table icebergTable, Long pastSnapshotTimeMil,
+                                        Boolean latestSpecOnly) {
+    List<Snapshot> relevantSnapshots = getRelevantSnapshots(icebergTable, pastSnapshotTimeMil).toList();
+    if (relevantSnapshots.isEmpty()) {
+      return false;
+    }
+
+    try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
+      // Submit a task for each snapshot and collect the Futures
+      List<Future<Set<String>>> futures = createPartitionNameFutures(
+          executor, icebergTable, relevantSnapshots, latestSpecOnly);
+
+      // Check results as they complete and short-circuit on first non-empty result
+      for (Future<Set<String>> future : futures) {

Review Comment:
   Yes, this is better because it allows parallel unblocked execution until hitting short circuit, so it's faster.
   Fixed.



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org