Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
480e984
gh-249 Remove MDB_UNSIGNEDKEY, let CursorIterable call mdb_cmp
at055612 Mar 6, 2025
46f8d08
gh-249 Remove non-J8 features, use indent size 2
at055612 Mar 6, 2025
f92012e
gh-249 Fix indents
at055612 Mar 6, 2025
e1756d6
gh-249 Tidy code and refactor RangeComparator impls
at055612 Mar 6, 2025
9509f6b
gh-249 Remove commented code
at055612 Mar 6, 2025
67e2df1
gh-249 Add CursorIterableIntegerKeyTest
at055612 Mar 7, 2025
620a89f
gh-249 Remove MaskedFlag.isPropagatedToLmdb, add DbiBuilder WIP
at055612 Jun 5, 2025
75d87d0
Merge branch 'master' into mdb_cmp
at055612 Oct 26, 2025
47b4c4f
Merge branch 'master' into mdb_cmp
at055612 Oct 26, 2025
bfbf223
Add FlagSet, DbiFlagSet, PutFlagSet
at055612 Oct 27, 2025
0f66aaf
Rename FlagSet to AbstractFlagSet
at055612 Oct 27, 2025
aa000a1
Add remaining FlagSet impls
at055612 Oct 27, 2025
667dab3
Fix Javadoc
at055612 Oct 27, 2025
b46c916
Add more cursor tests to protect against future regression
stroomdev66 Oct 28, 2025
0234d32
Replace get(Uns|S)ignedComparator with getComparator(DbiFlagSet)
at055612 Oct 28, 2025
ef0c852
Add missing txn commit in DbiBuilder
at055612 Oct 28, 2025
1b3f94d
Change CursorIterableTest to use Parameterized
at055612 Oct 28, 2025
c0bbe73
Deprecate methods using varargs flags
at055612 Oct 28, 2025
4fd89ff
Add int key compare method to (Direct|Byte)BufferProxy
at055612 Oct 29, 2025
916b441
Merge branch 'master' of github.com:lmdbjava/lmdbjava into more-curso…
stroomdev66 Oct 29, 2025
58dcc6e
Tidy code
at055612 Oct 29, 2025
26665ba
Fix byte order issues with compareAsIntegerKeys
at055612 Oct 29, 2025
dc0b96b
#267 Fix to establish start key when iterating backwards from a start…
stroomdev66 Oct 29, 2025
9db91a5
Merge branch 'master' of github.com:lmdbjava/lmdbjava into gh-267
stroomdev66 Oct 30, 2025
c427801
Add/refactor tests
at055612 Nov 4, 2025
f606e7e
Merge branch 'master' into mdb_cmp
at055612 Nov 4, 2025
d6e0ca1
#269 Initial iterator performance enhancements and testing.
stroomdev66 Nov 4, 2025
71c53e7
Merge branch 'master' of github.com:lmdbjava/lmdbjava into iterator-p…
stroomdev66 Nov 4, 2025
d56b0d4
#269 Initial iterator performance enhancements and testing.
stroomdev66 Nov 5, 2025
8cecdd6
#269 Initial iterator performance enhancements and testing.
stroomdev66 Nov 5, 2025
e2be6bf
Add integer key comparator tests
at055612 Nov 5, 2025
aecdf51
#269 Initial iterator performance enhancements and testing.
stroomdev66 Nov 5, 2025
7374fde
#267 Fix to establish start key when iterating backwards from a start…
stroomdev66 Nov 5, 2025
79c0df6
Merge branch 'master' of github.com:lmdbjava/lmdbjava into gh-267
stroomdev66 Nov 5, 2025
787d6d3
#267 Fix to establish start key when iterating backwards from a start…
stroomdev66 Nov 5, 2025
c289763
#267 Fix to establish start key when iterating backwards from a start…
stroomdev66 Nov 5, 2025
a3b9dea
Merge branch 'gh-267' of github.com:lmdbjava/lmdbjava into iterator-p…
stroomdev66 Nov 5, 2025
a7a41f4
#269 Initial iterator performance enhancements and testing.
stroomdev66 Nov 5, 2025
f23de09
#269 Initial iterator performance enhancements and testing.
stroomdev66 Nov 5, 2025
1acd971
Add ComparatorFactory
at055612 Nov 5, 2025
69eb5b7
#269 Initial iterator performance enhancements and testing.
stroomdev66 Nov 5, 2025
915edce
#269 Initial iterator performance enhancements and testing.
stroomdev66 Nov 5, 2025
dea7975
Merge branch 'master' into mdb_cmp
at055612 Nov 5, 2025
7d04445
#269 Initial iterator performance enhancements and testing.
stroomdev66 Nov 5, 2025
5a62965
Merged new comparator code
stroomdev66 Nov 5, 2025
484a772
Merged new comparator code
stroomdev66 Nov 5, 2025
ad75cb2
Fix CodeQL issues, add setMapSizeXx methods
at055612 Nov 5, 2025
77a3494
Fix failing test
at055612 Nov 5, 2025
1d46e0b
Refactor deprecated method calls
at055612 Nov 6, 2025
577062f
Fix compile issue
at055612 Nov 6, 2025
12a9679
Improve FlagSet tests
at055612 Nov 6, 2025
7a6910b
Add licence header
at055612 Nov 6, 2025
167cdad
Rename buildDbi to createDbi to be consistent with Env.create()
at055612 Nov 6, 2025
d47694e
Remove ByteUnits dep, add ByteUnit enum, add setMapSize() overload
at055612 Nov 6, 2025
fb08779
Fix compile errors
at055612 Nov 6, 2025
a82d7f2
Add more test coverage
at055612 Nov 6, 2025
534b76b
Fix codeQL issue
at055612 Nov 6, 2025
e9f9ac4
Add test coverage on FlagSet
at055612 Nov 6, 2025
b0112bb
Add tests
at055612 Nov 6, 2025
c25a7d2
Run format plugin
at055612 Nov 7, 2025
cf3a11e
Remove class separators
at055612 Nov 7, 2025
0c97cf4
Run format plugin
at055612 Nov 7, 2025
72d4e3f
Remove binaries accidentally added, fix test
at055612 Nov 7, 2025
18013fb
Merged new comparator code
stroomdev66 Nov 7, 2025
6b40d0b
Merge branch 'gh-267_plus_new_comparators' into gh-249-remove-unsigne…
at055612 Nov 7, 2025
48aa0fd
Fix javadoc warnings and class visibility, fix licence warnings
at055612 Nov 7, 2025
72b5234
Auto-format
at055612 Nov 7, 2025
dd95dea
Add error handling for parse(Int|Long)
at055612 Nov 7, 2025
b53378a
Remove unused code
at055612 Nov 7, 2025
deb1f1b
Remove unused code
at055612 Nov 7, 2025
2bfe07c
Remove unused hashCode methods
at055612 Nov 7, 2025
a84ceaa
Change CursorIterableRangeTest to do default+native modes
at055612 Nov 9, 2025
a5e4cf2
Remove separator comments
at055612 Nov 9, 2025
f8e6e07
Add more tests to CursorIterableRangeTest
at055612 Nov 9, 2025
6982aca
Remove unused test, auto format
at055612 Nov 9, 2025
6966a33
Merge branch 'gh-249-remove-unsignedkey' of github.com:lmdbjava/lmdbj…
stroomdev66 Nov 10, 2025
9541da3
Merge branch 'gh-249-remove-unsignedkey' of github.com:lmdbjava/lmdbj…
stroomdev66 Nov 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' into mdb_cmp
  • Loading branch information
at055612 committed Oct 26, 2025
commit 47b4c4f4cfbf2412872e6dbb52a7615c781b3a8a
4 changes: 4 additions & 0 deletions src/main/java/org/lmdbjava/BufferProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ protected BufferProxy() {}

/**
* Get a suitable default {@link Comparator} to compare numeric key values as unsigned.
* <p>
* This should match the behaviour of the LMDB's mdb_cmp comparator as it may be used for
* {@link CursorIterable} start/stop keys comparisons, which must match LMDB's insertion order.
* </p>
*
* @return a comparator that can be used (never null)
*/
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/lmdbjava/CursorIterable.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ enum State {
TERMINATED
}


// --------------------------------------------------------------------------------


static class JavaRangeComparator<T> implements RangeComparator {

private final Comparator<T> comparator;
Expand Down Expand Up @@ -272,6 +276,10 @@ public void close() throws Exception {
}
}


// --------------------------------------------------------------------------------


/**
* Calls down to mdb_cmp to make use of the comparator that LMDB uses for insertion order. Has a
* very slight overhead as compared to {@link JavaRangeComparator}.
Expand Down
127 changes: 75 additions & 52 deletions src/main/java/org/lmdbjava/DbiBuilder.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright © 2016-2025 The LmdbJava Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.lmdbjava;

import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -35,8 +50,11 @@
* <p>
* The name will be converted into bytes using {@link StandardCharsets#UTF_8}.
* </p>
* @param name The name of the database or null for the unnamed database
* (see also {@link DbiBuilder#withoutDbName()})
* @return The next builder stage.
*/
public RequireComparator<T> withDbName(final String name) {
public DbiBuilderStage2<T> withDbName(final String name) {
// Null name is allowed so no null check
final byte[] nameBytes = name == null
? null
Expand All @@ -46,11 +64,13 @@

/**
* Create the {@link Dbi} with the passed name in byte[] form.
* @param name The name of the database in byte form.
* @return The next builder stage.
*/
public RequireComparator<T> withDbName(final byte[] name) {
public DbiBuilderStage2<T> withDbName(final byte[] name) {
// Null name is allowed so no null check
this.name = name;
return new RequireComparator<>(this);
return new DbiBuilderStage2<>(this);
}

/**
Expand All @@ -61,8 +81,9 @@
* Equivalent to passing null to
* {@link DbiBuilder#withDbName(String)} or {@link DbiBuilder#withDbName(byte[])}.
* </p>
* @return The next builder stage.
*/
public RequireComparator<T> withoutDbName() {
public DbiBuilderStage2<T> withoutDbName() {
return withDbName((byte[]) null);
}

Expand All @@ -75,14 +96,14 @@
*
* @param <T> buffer type
*/
public static class RequireComparator<T> {
public static class DbiBuilderStage2<T> {

private final DbiBuilder<T> dbiBuilder;

private Comparator<T> comparator;
private boolean useNativeCallback;

private RequireComparator(final DbiBuilder<T> dbiBuilder) {
private DbiBuilderStage2(final DbiBuilder<T> dbiBuilder) {
this.dbiBuilder = dbiBuilder;
}

Expand All @@ -94,24 +115,24 @@
* </p>
* <p>
* This option may be slightly less performant than when using
* {@link RequireComparator#withDefaultJavaComparator()} as it need to call down
* {@link DbiBuilderStage2#withDefaultIteratorComparator()} as it need to call down
* to LMDB to perform the comparisons, however it guarantees that {@link CursorIterable}
* key comparison matches LMDB key comparison.
* </p>
* <p>
* If you do not intend to use {@link CursorIterable} then it doesn't matter whether
* you choose {@link RequireComparator#withNativeComparator()},
* {@link RequireComparator#withDefaultJavaComparator()} or
* {@link RequireComparator#withIteratorComparator(Comparator)} as these comparators will
* you choose {@link DbiBuilderStage2#withNativeComparator()},
* {@link DbiBuilderStage2#withDefaultIteratorComparator()} or
* {@link DbiBuilderStage2#withIteratorComparator(Comparator)} as these comparators will
* never be used.
* </p>
*
* @return this builder instance.
* @return The next builder stage.
*/
public FinalStage<T> withNativeComparator() {
public DbiBuilderStage3<T> withNativeComparator() {
this.comparator = null;
this.useNativeCallback = false;
return new FinalStage<>(this);
return new DbiBuilderStage3<>(this);
}

/**
Expand All @@ -121,23 +142,23 @@
* </p>
* <p>
* This option may be slightly more performant than when using
* {@link RequireComparator#withNativeComparator()} but it relies on the default comparator
* {@link DbiBuilderStage2#withNativeComparator()} but it relies on the default comparator
* in LmdbJava behaving identically to the comparator in LMDB.
* </p>
* <p>
* If you do not intend to use {@link CursorIterable} then it doesn't matter whether
* you choose {@link RequireComparator#withNativeComparator()},
* {@link RequireComparator#withDefaultJavaComparator()} or
* {@link RequireComparator#withIteratorComparator(Comparator)} as these comparators will
* you choose {@link DbiBuilderStage2#withNativeComparator()},
* {@link DbiBuilderStage2#withDefaultIteratorComparator()} or
* {@link DbiBuilderStage2#withIteratorComparator(Comparator)} as these comparators will
* never be used.
* </p>
*
* @return this builder instance.
* @return The next builder stage.
*/
public FinalStage<T> withDefaultJavaComparator() {
public DbiBuilderStage3<T> withDefaultIteratorComparator() {
this.comparator = dbiBuilder.proxy.getUnsignedComparator();
this.useNativeCallback = false;
return new FinalStage<>(this);
return new DbiBuilderStage3<>(this);
}

/**
Expand All @@ -151,12 +172,12 @@
* </p>
*
* @param comparator for all key comparison operations.
* @return this builder instance.
* @return The next builder stage.
*/
public FinalStage<T> withCallbackComparator(final Comparator<T> comparator) {
public DbiBuilderStage3<T> withCallbackIteratorComparator(final Comparator<T> comparator) {
this.comparator = Objects.requireNonNull(comparator);
this.useNativeCallback = true;
return new FinalStage<>(this);
return new DbiBuilderStage3<>(this);
}

/**
Expand All @@ -171,26 +192,23 @@
* differently to the comparator in LMDB that controls the insert/iteration order.
* </p>
* <p>
* This option may be slightly less performant than when using
* {@link RequireComparator#withDefaultJavaComparator()} as it need to call down
* to LMDB to perform the comparisons, however it guarantees that {@link CursorIterable}
* key comparison matches LMDB key comparison.
* The supplied {@link Comparator} should match the behaviour of LMDB's mdb_cmp comparator.
* </p>
* <p>
* If you do not intend to use {@link CursorIterable} then it doesn't matter whether
* you choose {@link RequireComparator#withNativeComparator()},
* {@link RequireComparator#withDefaultJavaComparator()} or
* {@link RequireComparator#withIteratorComparator(Comparator)} as these comparators will
* you choose {@link DbiBuilderStage2#withNativeComparator()},
* {@link DbiBuilderStage2#withDefaultIteratorComparator()} or
* {@link DbiBuilderStage2#withIteratorComparator(Comparator)} as these comparators will
* never be used.
* </p>
*
* @param comparator The comparator to use with {@link CursorIterable}.
* @return this builder instance.
* @return The next builder stage.
*/
public FinalStage<T> withIteratorComparator(final Comparator<T> comparator) {
public DbiBuilderStage3<T> withIteratorComparator(final Comparator<T> comparator) {
this.comparator = Objects.requireNonNull(comparator);
this.useNativeCallback = false;
return new FinalStage<>(this);
return new DbiBuilderStage3<>(this);
}
}

Expand All @@ -203,14 +221,14 @@
*
* @param <T> buffer type
*/
public static class FinalStage<T> {
public static class DbiBuilderStage3<T> {

private final RequireComparator<T> requireComparator;
private final DbiBuilderStage2<T> dbiBuilderStage2;
private Set<DbiFlags> dbiFlags = null;
private Txn<T> txn = null;

private FinalStage(RequireComparator<T> requireComparator) {
this.requireComparator = requireComparator;
private DbiBuilderStage3(DbiBuilderStage2<T> dbiBuilderStage2) {
this.dbiBuilderStage2 = dbiBuilderStage2;
}

private void initDbiFlags() {
Expand All @@ -225,33 +243,36 @@
* </p>
* <p>
* Replaces any flags applies in previous calls to
* {@link FinalStage#withDbiFlags(Collection)}, {@link FinalStage#withDbiFlags(DbiFlags...)}
* or {@link FinalStage#addDbiFlag(DbiFlags)}.
* {@link DbiBuilderStage3#withDbiFlags(Collection)}, {@link DbiBuilderStage3#withDbiFlags(DbiFlags...)}
* or {@link DbiBuilderStage3#addDbiFlag(DbiFlags)}.
* </p>
*
* @param dbiFlags to open the database with.
*/
public FinalStage<T> withDbiFlags(final Collection<DbiFlags> dbiFlags) {
public DbiBuilderStage3<T> withDbiFlags(final Collection<DbiFlags> dbiFlags) {
initDbiFlags();
if (dbiFlags != null) {
this.dbiFlags.addAll(dbiFlags);
this.dbiFlags.stream()
.filter(Objects::nonNull)
.forEach(dbiFlags::add);
}
return this;
}

/**
* <p>
* Apply all the dbi flags supplied in dbiFlags.

Check notice

Code scanning / CodeQL

Possible confusion of local and field Note

Confusing name: method
open
also refers to field
txn
(without qualifying it with 'this').
* </p>
* <p>
* Replaces any flags applies in previous calls to
* {@link FinalStage#withDbiFlags(Collection)}, {@link FinalStage#withDbiFlags(DbiFlags...)}
* or {@link FinalStage#addDbiFlag(DbiFlags)}.
* {@link DbiBuilderStage3#withDbiFlags(Collection)}, {@link DbiBuilderStage3#withDbiFlags(DbiFlags...)}
* or {@link DbiBuilderStage3#addDbiFlag(DbiFlags)}.
* </p>
*
* @param dbiFlags to open the database with.
* A null array is a no-op. Null items are ignored.
*/
public FinalStage<T> withDbiFlags(final DbiFlags... dbiFlags) {
public DbiBuilderStage3<T> withDbiFlags(final DbiFlags... dbiFlags) {
initDbiFlags();
if (dbiFlags != null) {
Arrays.stream(dbiFlags)
Expand All @@ -262,12 +283,14 @@
}

/**
* Adds dbiFlag to those flags already added to this builder.
* Adds dbiFlag to those flags already added to this builder by
* {@link DbiBuilderStage3#withDbiFlags(DbiFlags...)}, {@link DbiBuilderStage3#withDbiFlags(Collection)}
* or {@link DbiBuilderStage3#addDbiFlag(DbiFlags)}.
*
* @param dbiFlag to open the database with.
* @param dbiFlag to open the database with. A null value is a no-op.
* @return this builder instance.
*/
public FinalStage<T> addDbiFlag(final DbiFlags dbiFlag) {
public DbiBuilderStage3<T> addDbiFlag(final DbiFlags dbiFlag) {
initDbiFlags();
if (dbiFlags != null) {
this.dbiFlags.add(dbiFlag);
Expand All @@ -278,14 +301,14 @@
/**
* Use the supplied transaction to open the {@link Dbi}.
* <p>
* The caller must commit the transaction after calling {@link FinalStage#open()}
* The caller MUST commit the transaction after calling {@link DbiBuilderStage3#open()},
* in order to retain the <code>Dbi</code> in the <code>Env</code>.
* </p>
*
* @param txn transaction to use (required; not closed)
* @return this builder instance.
*/
public FinalStage<T> withTxn(final Txn<T> txn) {
public DbiBuilderStage3<T> withTxn(final Txn<T> txn) {
this.txn = Objects.requireNonNull(txn);
return this;
}
Expand All @@ -300,7 +323,7 @@
* @return A newly constructed and opened {@link Dbi}.
*/
public Dbi<T> open() {
final DbiBuilder<T> dbiBuilder = requireComparator.dbiBuilder;
final DbiBuilder<T> dbiBuilder = dbiBuilderStage2.dbiBuilder;
if (txn == null) {
try (final Txn<T> txn = getTxn(dbiBuilder)) {
return open(txn, dbiBuilder);
Expand All @@ -326,8 +349,8 @@
dbiBuilder.env,
txn,
dbiBuilder.name,
requireComparator.comparator,
requireComparator.useNativeCallback,
dbiBuilderStage2.comparator,
dbiBuilderStage2.useNativeCallback,
dbiBuilder.proxy,
dbiFlagsArr);
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/lmdbjava/RangeComparator.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright © 2016-2025 The LmdbJava Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.lmdbjava;

/** For comparing a cursor's current key against a {@link KeyRange}'s start/stop key. */
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/lmdbjava/CursorIterablePerfTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright © 2016-2025 The LmdbJava Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.lmdbjava;

import static com.jakewharton.byteunits.BinaryByteUnit.GIBIBYTES;
Expand Down Expand Up @@ -37,12 +52,12 @@
private Dbi<ByteBuffer> dbCallbackComparator;
private List<Dbi<ByteBuffer>> dbs = new ArrayList<>();
private Env<ByteBuffer> env;
private List<Integer> data = new ArrayList<>(ITERATIONS);

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
Env.openDbi
should be avoided because it has been deprecated.

@Before

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
Env.openDbi
should be avoided because it has been deprecated.
public void before() throws IOException {
final File path = tmp.newFile();
final BufferProxy<ByteBuffer> bufferProxy = ByteBufferProxy.PROXY_OPTIMAL;

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
Env.openDbi
should be avoided because it has been deprecated.
env =
create(bufferProxy)
.setMapSize(GIBIBYTES.toBytes(1))
Expand Down Expand Up @@ -137,7 +152,7 @@

public void comparePerf(final boolean randomOrder) {
populateDatabases(randomOrder);
final ByteBuffer startKeyBuf = bb(data.get(0));

Check notice

Code scanning / CodeQL

Unread local variable Note test

Variable 'KeyVal kv' is never read.
final ByteBuffer stopKeyBuf = bb(data.get(data.size() - 1));
final KeyRange<ByteBuffer> keyRange = KeyRange.closed(startKeyBuf, stopKeyBuf);

Expand Down
Loading
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.