public int append(MemoryRecords records, long lastOffset) throws IOException {
        if (!status.writable()) {
            throw new IOException("Cannot append to a fenced log segment due to status " + status);
        }
        if (records.sizeInBytes() > Integer.MAX_VALUE - size.get())
            throw new IllegalArgumentException("Append of size " + records.sizeInBytes() +
                    " bytes is too large for segment with current file position at " + size.get());
        int appendSize = records.sizeInBytes();
        // Note that the calculation of count requires strong consistency between nextOffset and the baseOffset of records.
        int count = (int) (lastOffset - nextOffset());
        com.automq.stream.DefaultRecordBatch batch = new com.automq.stream.DefaultRecordBatch(count, 0, Collections.emptyMap(), records.buffer());

        AppendContext context = ContextUtils.createAppendContext();
        CompletableFuture<?> cf;
        try {
            cf = TraceUtils.runWithSpanAsync(context, Attributes.empty(), "ElasticLogFileRecords::append",
                    () -> streamSlice.append(context, batch));
        } catch (Throwable ex) {
            throw new IOException("Failed to append to stream " + streamSlice.stream().streamId(), ex);
        }

        size.getAndAdd(appendSize);
        cf.whenComplete((rst, e) -> {
            if (e instanceof IOException) {
                status = ElasticResourceStatus.FENCED;
                LOGGER.error("ElasticLogFileRecords[stream={}, baseOffset={}] fencing with ex: {}", streamSlice.stream().streamId(), baseOffset, e.getMessage());
            }
        });
        lastAppend = cf;
        return appendSize;
    }
Append records to segment.
Note that lastOffset is the expected value of nextOffset after append. lastOffset = (the real last offset of the
records) + 1

@param records    records to append
@param lastOffset expected next offset after append
@return the size of the appended records
@throws IOException
core/src/main/scala/kafka/log/streamaspect/ElasticLogFileRecords.java