Title: ByteBuf.nioBuffer() returns a buffer with all zeros · Issue #215 · lmdbjava/lmdbjava · GitHub
Open Graph Title: ByteBuf.nioBuffer() returns a buffer with all zeros · Issue #215 · lmdbjava/lmdbjava
X Title: ByteBuf.nioBuffer() returns a buffer with all zeros · Issue #215 · lmdbjava/lmdbjava
Description: Hi, I'm running into a weird issue where calling nioBuffer on a ByteBuf received from lmdb-java results in a NIO ByteBuffer with the desired size but a value of all zeros. I'm on Netty 4.1.90.Final and lmdbjava 0.8.3 and JDK 19 . The rep...
Open Graph Description: Hi, I'm running into a weird issue where calling nioBuffer on a ByteBuf received from lmdb-java results in a NIO ByteBuffer with the desired size but a value of all zeros. I'm on Netty 4.1.90.Final...
X Description: Hi, I'm running into a weird issue where calling nioBuffer on a ByteBuf received from lmdb-java results in a NIO ByteBuffer with the desired size but a value of all zeros. I'm on Netty 4.1....
Opengraph URL: https://github.com/lmdbjava/lmdbjava/issues/215
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ByteBuf.nioBuffer() returns a buffer with all zeros","articleBody":"Hi,\r\n\r\nI'm running into a weird issue where calling `nioBuffer` on a `ByteBuf` received from `lmdb-java` results in a `NIO ByteBuffer` with the desired size but a value of all zeros.\r\n\r\nI'm on `Netty 4.1.90.Final` and `lmdbjava 0.8.3` and JDK 19 . The repro is as follows:\r\n\r\n```\r\npackage foo;\r\n\r\nimport io.netty.buffer.ByteBufUtil;\r\nimport io.netty.buffer.PooledByteBufAllocator;\r\nimport io.netty.buffer.Unpooled;\r\nimport org.junit.jupiter.api.Test;\r\nimport org.junit.jupiter.api.io.TempDir;\r\nimport org.lmdbjava.ByteBufProxy;\r\nimport org.lmdbjava.DbiFlags;\r\nimport org.lmdbjava.Env;\r\n\r\nimport java.io.File;\r\n\r\nimport static java.nio.charset.StandardCharsets.UTF_8;\r\nimport static org.junit.jupiter.api.Assertions.assertNotNull;\r\n\r\npublic class ByteBufMinimalReproTest {\r\n @TempDir\r\n File tmp;\r\n\r\n @Test\r\n void minimalRepro() {\r\n var env = Env.create(ByteBufProxy.PROXY_NETTY)\r\n .setMapSize(10_485_760)\r\n .setMaxDbs(1)\r\n .open(tmp);\r\n var db = env.openDbi(\"testdb\", DbiFlags.MDB_CREATE);\r\n var alloc = PooledByteBufAllocator.DEFAULT;\r\n\r\n var key = alloc.directBuffer(env.getMaxKeySize());\r\n var value = alloc.directBuffer(700);\r\n\r\n key.writeCharSequence(\"greeting\", UTF_8);\r\n value.writeCharSequence(\"Hello World\", UTF_8);\r\n\r\n System.out.println(\"Sanity -- Key\");\r\n System.out.println(ByteBufUtil.prettyHexDump(key));\r\n System.out.println(\"Sanity -- Key NIO\");\r\n System.out.println(ByteBufUtil.prettyHexDump(Unpooled.wrappedBuffer(key.nioBuffer())));\r\n\r\n System.out.println(\"Sanity -- Value\");\r\n System.out.println(ByteBufUtil.prettyHexDump(value));\r\n System.out.println(\"Sanity -- Value NIO\");\r\n System.out.println(ByteBufUtil.prettyHexDump(Unpooled.wrappedBuffer(value.nioBuffer())));\r\n\r\n\r\n db.put(key, value);\r\n // need a transaction to read values.\r\n try (var txn = env.txnRead()) {\r\n var found = db.get(txn, key);\r\n assertNotNull(found);\r\n\r\n System.out.println(\"Found Value\");\r\n System.out.println(ByteBufUtil.prettyHexDump(found));\r\n System.out.println(\"Found Value - NIO (Bad: all zeros)\");\r\n System.out.println(ByteBufUtil.prettyHexDump(Unpooled.wrappedBuffer(\r\n found.nioBuffer())));\r\n\r\n var fetchedVal = txn.val();\r\n System.out.println(\"val via txn\");\r\n System.out.println(ByteBufUtil.prettyHexDump(fetchedVal));\r\n System.out.println(\"val via txn - NIO (Bad: all zeros)\");\r\n System.out.println(ByteBufUtil.prettyHexDump(Unpooled.wrappedBuffer(\r\n txn.val().nioBuffer())));\r\n }\r\n env.close();\r\n }\r\n}\r\n```\r\n\r\nWhich prints:\r\n\r\n```\r\nSanity -- Key\r\n +-------------------------------------------------+\r\n | 0 1 2 3 4 5 6 7 8 9 a b c d e f |\r\n+--------+-------------------------------------------------+----------------+\r\n|00000000| 67 72 65 65 74 69 6e 67 |greeting |\r\n+--------+-------------------------------------------------+----------------+\r\nSanity -- Key NIO\r\n +-------------------------------------------------+\r\n | 0 1 2 3 4 5 6 7 8 9 a b c d e f |\r\n+--------+-------------------------------------------------+----------------+\r\n|00000000| 67 72 65 65 74 69 6e 67 |greeting |\r\n+--------+-------------------------------------------------+----------------+\r\nSanity -- Value\r\n +-------------------------------------------------+\r\n | 0 1 2 3 4 5 6 7 8 9 a b c d e f |\r\n+--------+-------------------------------------------------+----------------+\r\n|00000000| 48 65 6c 6c 6f 20 57 6f 72 6c 64 |Hello World |\r\n+--------+-------------------------------------------------+----------------+\r\nSanity -- Value NIO\r\n +-------------------------------------------------+\r\n | 0 1 2 3 4 5 6 7 8 9 a b c d e f |\r\n+--------+-------------------------------------------------+----------------+\r\n|00000000| 48 65 6c 6c 6f 20 57 6f 72 6c 64 |Hello World |\r\n+--------+-------------------------------------------------+----------------+\r\nFound Value\r\n +-------------------------------------------------+\r\n | 0 1 2 3 4 5 6 7 8 9 a b c d e f |\r\n+--------+-------------------------------------------------+----------------+\r\n|00000000| 48 65 6c 6c 6f 20 57 6f 72 6c 64 |Hello World |\r\n+--------+-------------------------------------------------+----------------+\r\nFound Value - NIO (Bad: all zeros)\r\n +-------------------------------------------------+\r\n | 0 1 2 3 4 5 6 7 8 9 a b c d e f |\r\n+--------+-------------------------------------------------+----------------+\r\n|00000000| 00 00 00 00 00 00 00 00 00 00 00 |........... |\r\n+--------+-------------------------------------------------+----------------+\r\nval via txn\r\n +-------------------------------------------------+\r\n | 0 1 2 3 4 5 6 7 8 9 a b c d e f |\r\n+--------+-------------------------------------------------+----------------+\r\n|00000000| 48 65 6c 6c 6f 20 57 6f 72 6c 64 |Hello World |\r\n+--------+-------------------------------------------------+----------------+\r\nval via txn - NIO (Bad: all zeros)\r\n +-------------------------------------------------+\r\n | 0 1 2 3 4 5 6 7 8 9 a b c d e f |\r\n+--------+-------------------------------------------------+----------------+\r\n|00000000| 00 00 00 00 00 00 00 00 00 00 00 |........... |\r\n+--------+-------------------------------------------------+----------------+\r\n```\r\n\r\nMy repro is using the prettyHexDump from ByteBuf, which is why i need to re-wrap nioBuffer. I'm pretty sure this isn't causing any problems because when I write the bytebuf to file, I see all zeros.\r\n\r\nThe reason I'm doing nioBuffer on this netty buffer is because I need to pass it to Zstd java for decompression.\r\n\r\nI'm new to both lmdb java and netty, and it's possible i'm doing something wrong, but I'd appreciate your help with this.","author":{"url":"https://github.com/kanak","@type":"Person","name":"kanak"},"datePublished":"2023-04-02T17:55:24.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/215/lmdbjava/issues/215"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b9225884-07b6-1cc0-7041-4882c40595bc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CFEA:EB10B:1C7688B:268A933:69707AE8 |
| html-safe-nonce | 1041daa94e508e00e656056a085b0585b41796a10a8908af088f7e7384484b20 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRkVBOkVCMTBCOjFDNzY4OEI6MjY4QTkzMzo2OTcwN0FFOCIsInZpc2l0b3JfaWQiOiI5MTk4MzY5NjcyNDg5MTA2MTUyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 9a418ea5fb4749dd8938fe94b16f3df1eb5bf01d7589c9cf05600322960c401e |
| hovercard-subject-tag | issue:1651037139 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/lmdbjava/lmdbjava/215/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4f220bff1c735983145f1fbbac040cb08f4c65b2a505ae8673be0815a295a128/lmdbjava/lmdbjava/issues/215 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4f220bff1c735983145f1fbbac040cb08f4c65b2a505ae8673be0815a295a128/lmdbjava/lmdbjava/issues/215 |
| og:image:alt | Hi, I'm running into a weird issue where calling nioBuffer on a ByteBuf received from lmdb-java results in a NIO ByteBuffer with the desired size but a value of all zeros. I'm on Netty 4.1.90.Final... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kanak |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9920a62ba22d06470388e2904804fb7e5ec51c9e35f81784e9191394c74b2bd2 |
| turbo-cache-control | no-preview |
| go-import | github.com/lmdbjava/lmdbjava git https://github.com/lmdbjava/lmdbjava.git |
| octolytics-dimension-user_id | 19765602 |
| octolytics-dimension-user_login | lmdbjava |
| octolytics-dimension-repository_id | 60480511 |
| octolytics-dimension-repository_nwo | lmdbjava/lmdbjava |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 60480511 |
| octolytics-dimension-repository_network_root_nwo | lmdbjava/lmdbjava |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7d6181066430cc06553c8396ca201e194ae33cb9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width