MDB_INTEGERKEY and endianness

I am facing an issue while using range search using KeyRange.

In lmdb, the following is stored:

key: event timestamp in millis
value: event payload

What I want to do:

  • count query by for a given time range (how many events between 1000 hrs to 1010 hrs)
  • fetch all the events for a given time range

Issue:

  • if counts are queried using KeyRange.all(), correct count is returned.
  • but, if queried using specific range, it does not return current count:
    • KeyRange.closed(min, max) returns 0

Observations:

  • strangely, if queried using KeyRange.closed(min, max * numberOfKeys), it returns correct result.
  • if the keys are dense, then things work as expected
    • say,
    long start = toMillis(LocalDateTime.of(2018, Month.JANUARY, 1, 0, 0));
    for(int i = 0; i < numberOfKeys; i++) {
      dbi.put(bb(start + i), bb(i));
    }
    
    • in this scenario, KeyRange.closed() etc. work as expected.

My question is :
am I using the correct APIs for my usecase? is it a configuration issue?


Note:

  • Java version
    $ java -version
    java version "1.8.0_181"
    Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
    
  • Windows 10 dev environment

A reproducible test case: gist