private void swapWriteCache(final StringBuilder strBuffer) throws Throwable {
        long lastDataPos;
        long lastIndexPos;
        MsgMemStore tmpStore = null;
        boolean isRealloc = false;
        writeCacheMutex.writeLock().lock();
        try {
            lastDataPos = msgMemStore.getDataLastWritePos();
            lastIndexPos = msgMemStore.getIndexLastWritePos();
            tmpStore = msgMemStoreBeingFlush;
            msgMemStoreBeingFlush = msgMemStore;
            if (tmpStore.getMaxAllowedMsgCount() == writeCacheMaxCnt
                    && tmpStore.getMaxDataCacheSize() == writeCacheMaxSize) {
                msgMemStore = tmpStore;
                msgMemStore.resetMemStoreStatus(lastDataPos, lastIndexPos);
            } else {
                isRealloc = true;
                msgMemStore = new MsgMemStore(writeCacheMaxSize,
                        writeCacheMaxCnt, lastDataPos, lastIndexPos);
            }
            hasFlushBeenTriggered.set(false);
            flushWriteCacheCondition.signalAll();
        } finally {
            isFlushOngoing.set(true);
            writeCacheMutex.writeLock().unlock();
            if (isRealloc) {
                tmpStore.close();
                msgStoreStatsHolder.addCacheReAlloc();
                logger.info(strBuffer.append("[Data Store] Found ").append(getStoreKey())
                        .append(" Cache capacity change, new MemSize=")
                        .append(writeCacheMaxSize).append(", new CacheCnt=")
                        .append(writeCacheMaxCnt).toString());
                strBuffer.delete(0, strBuffer.length());
            }
        }
        msgMemStoreBeingFlush.batchFlush(msgFileStore, strBuffer);
    }
Append message and trigger flush operation.

@param needAdd           whether to add a message
@param isTimeTrigger     whether is timer trigger
@param partitionId       the partitionId for reading messages
@param keyCode           the filter item hash code
@param receivedTime      the received time of message
@param indexEntry        the stored index entry
@param dataLength        the stored data entry length
@param dataEntry         the stored data entry
@param appendResult      the append result

@return                  the append result
@throws IOException      the exception during processing
inlong-tubemq/tubemq-server/src/main/java/org/apache/inlong/tubemq/server/broker/msgstore/MessageStore.java