@Override
    public long findRegion(int subpartition, int bufferIndex, boolean loadToCache) {
        // first of all, find the region from current writing region group.
        RegionGroup regionGroup = currentRegionGroup[subpartition];
        if (regionGroup != null) {
            long regionOffset =
                    findRegionInRegionGroup(subpartition, bufferIndex, regionGroup, loadToCache);
            if (regionOffset != -1) {
                return regionOffset;
            }
        }

        // next, find the region from finished region groups.
        TreeMap<Integer, RegionGroup> subpartitionRegionGroupMetaTreeMap =
                subpartitionFinishedRegionGroupMetas.get(subpartition);
        // all region groups with a minBufferIndex less than or equal to this target buffer index
        // may contain the target region.
        for (RegionGroup meta :
                subpartitionRegionGroupMetaTreeMap.headMap(bufferIndex, true).values()) {
            long regionOffset =
                    findRegionInRegionGroup(subpartition, bufferIndex, meta, loadToCache);
            if (regionOffset != -1) {
                return regionOffset;
            }
        }
        return -1;
    }
@Test
    void testFindNonExistentRegion() throws Exception {
        CompletableFuture<Void> cachedRegionFuture = new CompletableFuture<>();
        try (FileDataIndexSpilledRegionManager<TestingFileDataIndexRegion> spilledRegionManager =
                createSpilledRegionManager(
                        (ignore1, ignore2) -> cachedRegionFuture.complete(null))) {
            long regionOffset = spilledRegionManager.findRegion(0, 0, true);
            assertThat(regionOffset).isEqualTo(-1);
            assertThat(cachedRegionFuture).isNotCompleted();
        }
    }