You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "luhenry (via GitHub)" <gi...@apache.org> on 2023/02/06 15:36:21 UTC

[GitHub] [spark] luhenry opened a new pull request, #39909: Fix constructor for java.nio.DirectByteBuffer

luhenry opened a new pull request, #39909:
URL: https://github.com/apache/spark/pull/39909

   <!--
   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://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'core/src/main/resources/error/README.md'.
   -->
   
   ### 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.
   -->
   
   In the latest JDK, the constructor `DirectByteBuffer(long, int)` was replaced with `DirectByteBuffer(long, long)`. We just want to support both by probing for the legacy one first and falling back to the newer one second.
   
   This change is completely transparent for the end-user, and makes sure Spark works transparently on the latest JDK as well.
   
   ### 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.
   -->
   
   It's required to support the latest versions of the JDK.
   
   ### 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 and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   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.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   
   It was built and ran locally against the newest JDK.
   


-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] srowen commented on pull request #39909: Fix constructor for java.nio.DirectByteBuffer

Posted by "srowen (via GitHub)" <gi...@apache.org>.
srowen commented on PR #39909:
URL: https://github.com/apache/spark/pull/39909#issuecomment-1419396484

   (Please make a JIRA, etc. though - https://spark.apache.org/contributing.html )


-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] mridulm commented on pull request #39909: Fix constructor for java.nio.DirectByteBuffer

Posted by "mridulm (via GitHub)" <gi...@apache.org>.
mridulm commented on PR #39909:
URL: https://github.com/apache/spark/pull/39909#issuecomment-1419313662

   The type mismatch at invocation time (`int` vs `long` now) would work fine due to promotion I guess ? I did not see this documented in `Constructor`, so wanted to clarify,


-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AlanBateman commented on pull request #39909: [SPARK-42369][CORE] Fix constructor for java.nio.DirectByteBuffer

Posted by "AlanBateman (via GitHub)" <gi...@apache.org>.
AlanBateman commented on PR #39909:
URL: https://github.com/apache/spark/pull/39909#issuecomment-1443699370

   The elements in a ByteBuffer are addressed by an int so the capacity is limited to Integer.MAX_VALUE. Using standard APIs such as JNI NewDirectByteBuffer or FileChannel.map allows you have ByteBuffer views over memory/mappings that are much larger. I really hope the Spark maintainers will re-examine this code as these hacks are way too fragile.


-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on pull request #39909: [SPARK-42369][CORE] Fix constructor for java.nio.DirectByteBuffer

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on PR #39909:
URL: https://github.com/apache/spark/pull/39909#issuecomment-1420992651

   Thank you, @luhenry , @mridulm , @srowen , @LuciferYang , @wangyum .
   Merged to master for Apache Spark 3.5.0.


-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] srowen commented on pull request #39909: [SPARK-42369][CORE] Fix constructor for java.nio.DirectByteBuffer

Posted by "srowen (via GitHub)" <gi...@apache.org>.
srowen commented on PR #39909:
URL: https://github.com/apache/spark/pull/39909#issuecomment-1443745553

   Yes I agree with all that, but it isn't true for Java 8, which is still supported. 
   I agree, could break. If it does this just 'falls back' to normal limits and you have to set a command line flag or something.


-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] LuciferYang commented on pull request #39909: Fix constructor for java.nio.DirectByteBuffer

Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on PR #39909:
URL: https://github.com/apache/spark/pull/39909#issuecomment-1420124430

   > Thank you for making a PR, @luhenry . Is this isolated for **Java 21 LTS** only? Do you know which Java versions will have the original patch?
   
   It should start from Java 21. Java 20 still uses Int.
   
   https://github.com/openjdk/jdk/blob/jdk-20+34/src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template
   


-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AlanBateman commented on pull request #39909: [SPARK-42369][CORE] Fix constructor for java.nio.DirectByteBuffer

Posted by "AlanBateman (via GitHub)" <gi...@apache.org>.
AlanBateman commented on PR #39909:
URL: https://github.com/apache/spark/pull/39909#issuecomment-1443741735

   Strong encapsulation has been enabled by default since JDK 16 so presumably the setAccessible has been failing with InaccessibleObjectException since then, unless it is run with --add-opens to open this package? If there is somewhere to put command line options then maybe you could put -XX:MaxDirectMemorySize=100g or some other large value? If there there is a compelling case for running without limits on direct memory then maybe you can bring it to the OpenJDK mailing lists for discussion, nio-dev or core-libs-dev in this case. The concern with the hack is that they can break at any time and prevents upgrading the JDK. In this case, we fixed an issue with JNI NewDirectByteBuffer for JDK 21 and that required change a private constructor.
   
   The issue came to light with the renaissance benchmark:
      https://github.com/renaissance-benchmarks/renaissance/issues/370


-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AlanBateman commented on pull request #39909: [SPARK-42369][CORE] Fix constructor for java.nio.DirectByteBuffer

Posted by "AlanBateman (via GitHub)" <gi...@apache.org>.
AlanBateman commented on PR #39909:
URL: https://github.com/apache/spark/pull/39909#issuecomment-1443397556

   Would it be possible to provide a summary on what Spark is doing? It's untenable to rely on JDK internals like this as it could break at any time. In this case, I'm guessing that you want to create a ByteBuffer that is backed by some off-heap memory. The standard API for that is JNI NewDirectByteBuffer. Going forward, the j.l.foreign API might be what you want. In the current preview it can be done with a restricted method like `MemorySegment.ofAddress(address, size).asByteBuffer()`


-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] srowen commented on pull request #39909: [SPARK-42369][CORE] Fix constructor for java.nio.DirectByteBuffer

Posted by "srowen (via GitHub)" <gi...@apache.org>.
srowen commented on PR #39909:
URL: https://github.com/apache/spark/pull/39909#issuecomment-1443704665

   No, that's not it. It relates to `MaxDirectMemorySize` and its default. I think this is all to avoid that limit without having everyone set it differently. What problem are you seeing with this? 


-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] luhenry commented on pull request #39909: Fix constructor for java.nio.DirectByteBuffer

Posted by "luhenry (via GitHub)" <gi...@apache.org>.
luhenry commented on PR #39909:
URL: https://github.com/apache/spark/pull/39909#issuecomment-1419321233

   Yes, and it wouldn't work the other way since `long` doesn't fit in `int`. It's the implicit conversion of `int` to `long` that comes into play 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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AlanBateman commented on pull request #39909: [SPARK-42369][CORE] Fix constructor for java.nio.DirectByteBuffer

Posted by "AlanBateman (via GitHub)" <gi...@apache.org>.
AlanBateman commented on PR #39909:
URL: https://github.com/apache/spark/pull/39909#issuecomment-1445042515

   It's the same issue for JDK 8 where it was completely unsupported to be make use of the JDK private constructor. For the JDK side, all we can do it strongly courage the Spark project to move away from these hacks. If there are compelling cases for introducing new APIs or interfaces then please bring them to the OpenJDK mailing lists for discussion.


-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] luhenry commented on pull request #39909: [SPARK-42369][Common] Fix constructor for java.nio.DirectByteBuffer

Posted by "luhenry (via GitHub)" <gi...@apache.org>.
luhenry commented on PR #39909:
URL: https://github.com/apache/spark/pull/39909#issuecomment-1420360829

   The change happens in https://github.com/openjdk/jdk/commit/a56598f5a534cc9223367e7faa8433ea38661db9 which will be released first in Java 21.


-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun closed pull request #39909: [SPARK-42369][CORE] Fix constructor for java.nio.DirectByteBuffer

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun closed pull request #39909: [SPARK-42369][CORE] Fix constructor for java.nio.DirectByteBuffer
URL: https://github.com/apache/spark/pull/39909


-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] srowen commented on pull request #39909: [SPARK-42369][CORE] Fix constructor for java.nio.DirectByteBuffer

Posted by "srowen (via GitHub)" <gi...@apache.org>.
srowen commented on PR #39909:
URL: https://github.com/apache/spark/pull/39909#issuecomment-1443683514

   It's in the comments, to some extent. I believe it's to allow larger allocations than normally possible.
   The catch is we need to support Java 8 for now, so the foreign APIs won't help.


-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org