There are some unexpected behaviors of rank indexing when adding records concurrently. I’m having a record that has rank index. When i try to adding multiple records concurrently, there is something wrong with ranking. I tried to scan all records on the store, it has all records but using scoreForRank and rankForScore gave me wrong result.
I’m trying to re-procedure my use case on RankIndexTest.java (sorry, i’m not really familiar with java).
I change the loadRecords to concurrently load records
public static class RunnableSaveRecord implements Runnable {
        private final String name;
        private final Integer score;
        private final String sex;
        private final FDBRecordStore recordStore;
        private final CountDownLatch cd;
        RunnableSaveRecord(String _name, Integer _score, String _sex, FDBRecordStore _store, CountDownLatch _cd) {
            this.name = _name;
            this.score = _score;
            this.sex = _sex;
            this.recordStore = _store;
            this.cd = _cd;
        }
        @Override
        public void run() {
            System.out.printf("------------ write %s %d %s", name, score, sex);
            recordStore.saveRecord(TestRecordsRankProto.BasicRankedRecord.newBuilder()
                    .setName(name)
                    .setScore(score)
                    .setGender(sex)
                    .build());
            cd.countDown();
        }
    }
    @BeforeEach
    public void loadRecords() throws Exception {
        CountDownLatch cd = new CountDownLatch(RECORDS.length);
        ExecutorService executor = Executors.newFixedThreadPool(RECORDS.length);
        try (FDBRecordContext context = openContext()) {
            openRecordStore(context);
            for (Object[] rec : RECORDS) {
                RunnableSaveRecord saver = new RunnableSaveRecord((String)rec[0], (Integer)rec[1], (String)rec[2], recordStore, cd);
                executor.execute(saver);
            }
            cd.await();
            commit(context);
        }
    }
With the code above, test will be failed. (Randomly, i think it’s because of concurrency).