private void spill() throws IOException {
        FileIOChannel.ID channel = ioManager.createChannel();

        final BlockChannelWriter<MemorySegment> writer =
                this.ioManager.createBlockChannelWriter(channel);
        int numRecordBuffers = inMemoryBuffer.getNumRecordBuffers();
        ArrayList<MemorySegment> segments = inMemoryBuffer.getRecordBufferSegments();
        try {
            // spill in memory buffer in zero-copy.
            for (int i = 0; i < numRecordBuffers; i++) {
                writer.writeBlock(segments.get(i));
            }
            LOG.info("here spill the reset buffer data with {} bytes", writer.getSize());
            writer.close();
        } catch (IOException e) {
            writer.closeAndDelete();
            throw e;
        }

        spillSize += numRecordBuffers * segmentSize;
        spilledChannelIDs.add(
                new ChannelWithMeta(
                        channel,
                        inMemoryBuffer.getNumRecordBuffers(),
                        inMemoryBuffer.getNumBytesInLastBuffer()));
        this.spilledChannelRowOffsets.add(numRows);

        inMemoryBuffer.reset();
    }
@Test
    public void testSpill() throws Exception {
        ResettableExternalBuffer buffer = newBuffer(DEFAULT_PAGE_SIZE * 2);

        int number = 5000; // 16 * 5000
        List<Long> expected = insertMulti(buffer, number);
        assertThat(number).isEqualTo(buffer.size());
        assertBuffer(expected, buffer);
        assertThat(buffer.getSpillChannels().size()).isGreaterThan(0);

        // repeat read
        assertBuffer(expected, buffer);
        buffer.newIterator();
        assertBuffer(expected, buffer);

        buffer.close();
    }