@Override
    public void appendOrOverwriteRegion(int subpartition, T newRegion) throws IOException {
        // This method will only be called when we want to eliminate a region. We can't let the
        // region be reloaded into the cache, otherwise it will lead to an infinite loop.
        long oldRegionOffset = findRegion(subpartition, newRegion.getFirstBufferIndex(), false);
        if (oldRegionOffset != -1) {
            // if region is already exists in file, overwrite it.
            writeRegionToOffset(oldRegionOffset, newRegion);
        } else {
            // otherwise, append region to region group.
            appendRegion(subpartition, newRegion);
        }
    }
@Test
    void testWriteBigRegion() throws Exception {
        int regionGroupSize = 4;
        try (FileDataIndexSpilledRegionManager<TestingFileDataIndexRegion> spilledRegionManager =
                createSpilledRegionManager(regionGroupSize, (ignore1, ignore2) -> {})) {
            List<TestingFileDataIndexRegion> regions = createTestRegions(0, 0L, 1, 2);
            TestingFileDataIndexRegion region1 = regions.get(0);
            TestingFileDataIndexRegion region2 = regions.get(1);
            assertThat(region1.getSize()).isGreaterThan(regionGroupSize);
            assertThat(region2.getSize()).isGreaterThan(regionGroupSize);

            spilledRegionManager.appendOrOverwriteRegion(0, region1);
            spilledRegionManager.appendOrOverwriteRegion(0, region2);
            FileChannel indexFileChannel = FileChannel.open(indexFilePath, StandardOpenOption.READ);
            TestingFileDataIndexRegion readRegion1 = readRegionFromFile(indexFileChannel, 0L);
            assertRegionEquals(readRegion1, region1);

            TestingFileDataIndexRegion readRegion2 =
                    readRegionFromFile(indexFileChannel, readRegion1.getSize());
            assertRegionEquals(readRegion2, region2);
        }
    }