Skip to content

Commit 838a8a0

Browse files
authored
Fix build on aarch64 (e.g. Apple Silicon) (#218)
* Increase map size to multiple of larger page size Most architectures such as x86 and x86-64 use 4KiB, while aarch64 systems can use 4, 16 or 64KiB. Apple Silicon machines currently have 16KiB page sizes. The LMDB documentation states that map size should be a multiple of the page size, so a 100KiB default map size for tests fails for systems with a page size that is not 4 KiB. This commit simply increases the map size for tests. Of course, this applies only to these tests, as in production, users can choose the appropriate map size for their requirements and system architecture. It is not straightforward to determine architecture page size at runtime. Otherwise, it might be more appropriate to dynamically determine a minimum map size. * Tweak test of page size The options for determining architecture page size are a) environment variables, b) unsafe and undocumented JDK internals or c) looking to get answer using FFI. Given this test is asking checking the statistics returned by LMDB, on balance it is reasonable to simply validate we're getting a multiple of 4096 in the statistics report. * Fix test for cut-off given large map sizes
1 parent 533ae0f commit 838a8a0

4 files changed

Lines changed: 9 additions & 8 deletions

File tree

src/test/java/org/lmdbjava/CursorIterableTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public void atMostTest() {
126126
public void before() throws IOException {
127127
final File path = tmp.newFile();
128128
env = create()
129-
.setMapSize(KIBIBYTES.toBytes(100))
129+
.setMapSize(KIBIBYTES.toBytes(256))
130130
.setMaxReaders(1)
131131
.setMaxDbs(1)
132132
.open(path, POSIX_MODE, MDB_NOSUBDIR);

src/test/java/org/lmdbjava/DbiTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ public void stats() {
460460
assertThat(stat.entries, is(3L));
461461
assertThat(stat.leafPages, is(1L));
462462
assertThat(stat.overflowPages, is(0L));
463-
assertThat(stat.pageSize, is(4_096));
463+
assertThat(stat.pageSize % 4_096, is(0));
464464
}
465465

466466
@Test(expected = MapFullException.class)

src/test/java/org/lmdbjava/EnvTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
package org.lmdbjava;
2222

23+
import static com.jakewharton.byteunits.BinaryByteUnit.KIBIBYTES;
2324
import static com.jakewharton.byteunits.BinaryByteUnit.MEBIBYTES;
2425
import static java.nio.ByteBuffer.allocateDirect;
2526
import static org.hamcrest.CoreMatchers.containsString;
@@ -338,15 +339,15 @@ public void setMapSize() throws IOException {
338339
final Random rnd = new Random();
339340
try (Env<ByteBuffer> env = create()
340341
.setMaxReaders(1)
341-
.setMapSize(50_000)
342+
.setMapSize(KIBIBYTES.toBytes(256))
342343
.setMaxDbs(1)
343344
.open(path)) {
344345
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE);
345346

346347
db.put(bb(1), bb(42));
347348
boolean mapFullExThrown = false;
348349
try {
349-
for (int i = 0; i < 30; i++) {
350+
for (int i = 0; i < 70; i++) {
350351
rnd.nextBytes(k);
351352
key.clear();
352353
key.put(k).flip();
@@ -358,15 +359,15 @@ public void setMapSize() throws IOException {
358359
}
359360
assertThat(mapFullExThrown, is(true));
360361

361-
env.setMapSize(500_000);
362+
env.setMapSize(KIBIBYTES.toBytes(512));
362363

363364
try (Txn<ByteBuffer> roTxn = env.txnRead()) {
364365
assertThat(db.get(roTxn, bb(1)).getInt(), is(42));
365366
}
366367

367368
mapFullExThrown = false;
368369
try {
369-
for (int i = 0; i < 30; i++) {
370+
for (int i = 0; i < 70; i++) {
370371
rnd.nextBytes(k);
371372
key.clear();
372373
key.put(k).flip();
@@ -393,7 +394,7 @@ public void stats() throws IOException {
393394
assertThat(stat.entries, is(0L));
394395
assertThat(stat.leafPages, is(0L));
395396
assertThat(stat.overflowPages, is(0L));
396-
assertThat(stat.pageSize, is(4_096));
397+
assertThat(stat.pageSize % 4_096, is(0));
397398
assertThat(stat.toString(), containsString("pageSize="));
398399
}
399400
}

src/test/java/org/lmdbjava/TxnTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void after() {
8484
public void before() throws IOException {
8585
path = tmp.newFile();
8686
env = create()
87-
.setMapSize(KIBIBYTES.toBytes(100))
87+
.setMapSize(KIBIBYTES.toBytes(256))
8888
.setMaxReaders(1)
8989
.setMaxDbs(2)
9090
.open(path, POSIX_MODE, MDB_NOSUBDIR);

0 commit comments

Comments
 (0)