Skip to content

[FOLLOW-UP] HIVE-28373: Iceberg: Refactor the code of HadoopTableOptions#6345

Open
BsoBird wants to merge 4 commits intoapache:masterfrom
BsoBird:followup-HIVE-28373
Open

[FOLLOW-UP] HIVE-28373: Iceberg: Refactor the code of HadoopTableOptions#6345
BsoBird wants to merge 4 commits intoapache:masterfrom
BsoBird:followup-HIVE-28373

Conversation

@BsoBird
Copy link
Contributor

@BsoBird BsoBird commented Mar 3, 2026

What changes were proposed in this pull request?

Modify the test case to ensure it can run on macOS environments.

Why are the changes needed?

Since a considerable number of developers use macOS as their local development environment, the test case code should avoid relying on Linux-specific commands.

Does this PR introduce any user-facing change?

No

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please drop the unnecessary casts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

String cmd = String.format("mv -n %s %s", srcPathStr, dstPathStr);
Process process = Runtime.getRuntime().exec(cmd);
assertThat(process.waitFor()).isZero();
Files.move(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why such a massive copy-paste?

try {
        HadoopTableOperations tableOperations = (HadoopTableOperations) baseTable.operations();
        HadoopTableOperations spyOps = spy(tableOperations);
        doNothing().when(spyOps).tryLock(any(), any());
        doAnswer(x -> {
          countDownLatch.countDown();
          countDownLatch.await();
          return x.callRealMethod();
        }).when(spyOps).renameMetaDataFileAndCheck(any(), any(), any(), anyBoolean());
        doAnswer(x -> {
          Path srcPath = x.getArgument(1);
          Path dstPath = x.getArgument(2);
          Files.move(
              Paths.get(srcPath.toUri()), Paths.get(dstPath.toUri()),
              StandardCopyOption.ATOMIC_MOVE
          );
          return true;
        }).when(spyOps).renameMetaDataFile(any(), any(), any());
        TableMetadata metadataV1 = spyOps.current();
        SortOrder dataSort = SortOrder.builderFor(baseTable.schema()).asc("data").build();
        TableMetadata metadataV2 = metadataV1.replaceSortOrder(dataSort);
        spyOps.commit(metadataV1, metadataV2);
      } catch (CommitFailedException e) {
        expectedException.set(e);
      } catch (Throwable e) {
        unexpectedException.set(e);
      }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 8 threads? Executors.newFixedThreadPool(8)
use virtual threads instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    Runnable commitTask = () -> {
      try {
        HadoopTableOperations tableOperations = (HadoopTableOperations) baseTable.operations();
        HadoopTableOperations spyOps = spy(tableOperations);
        doNothing().when(spyOps).tryLock(any(), any());
        doAnswer(x -> {
          countDownLatch.countDown();
          countDownLatch.await();
          return x.callRealMethod();
        }).when(spyOps).renameMetaDataFileAndCheck(any(), any(), any(), anyBoolean());
        doAnswer(x -> {
          Path srcPath = x.getArgument(1);
          Path dstPath = x.getArgument(2);

          var src = Paths.get(srcPath.toUri());
          var dst = Paths.get(dstPath.toUri());
          Files.move(src, dst, StandardCopyOption.ATOMIC_MOVE);

          return Files.exists(dst) && Files.notExists(src);
        }).when(spyOps).renameMetaDataFile(any(), any(), any());

        TableMetadata metadataV1 = spyOps.current();
        SortOrder dataSort = SortOrder.builderFor(baseTable.schema()).asc("data").build();
        TableMetadata metadataV2 = metadataV1.replaceSortOrder(dataSort);
        spyOps.commit(metadataV1, metadataV2);
      } catch (CommitFailedException e) {
        expectedException.set(e);
      } catch (Throwable e) {
        unexpectedException.set(e);
      }
    };

    Tasks.range(2)
        .executeWith(executorService)
        .run(i -> commitTask.run());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

@BsoBird BsoBird marked this pull request as draft March 3, 2026 17:39
2.remove unnecessary casts
3.remove massive copy-paste
@deniskuzZ
Copy link
Member

deniskuzZ commented Mar 3, 2026

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 4, 2026

@BsoBird BsoBird marked this pull request as ready for review March 5, 2026 10:20
@BsoBird
Copy link
Contributor Author

BsoBird commented Mar 5, 2026

@deniskuzZ
Hello, I've updated the test code for cross-platform stability.
The root cause was that macOS lacks the renameat2 syscall available in Linux, forcing rename to follow basic POSIX behavior (overwriting targets). To eliminate these filesystem behavioral differences between test environments, I've moved the rename logic into Java code to simulate HDFS rename semantics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants