public long getStartOffsetByTimeStamp(long timestamp) {
        Segment recordSeg = indexSegments.findSegmentByTimeStamp(timestamp);
        if (recordSeg == null || this.closed.get()) {
            return -1;
        }
        long endPos = (recordSeg.getCommitLast() - recordSeg.getStart())
                / DataStoreUtils.STORE_INDEX_HEAD_LEN - 1;
        final long curDataMinOffset = getDataMinOffset();
        final ByteBuffer readBuffer =
                ByteBuffer.allocate(DataStoreUtils.STORE_INDEX_HEAD_LEN);
        // check boundaries
        if (endPos <= 0) {
            return recordSeg.getStart();
        }
        long foundTime = getTimeStamp(recordSeg,
                0, curDataMinOffset, readBuffer);
        if (timestamp < foundTime) {
            return recordSeg.getStart();
        }
        foundTime = getTimeStamp(recordSeg,
                endPos * DataStoreUtils.STORE_INDEX_HEAD_LEN,
                curDataMinOffset, readBuffer);
        if (timestamp > foundTime) {
            return recordSeg.getStart() + endPos * DataStoreUtils.STORE_INDEX_HEAD_LEN;
        }
        long midPos = 0;
        long startPos = 0;
        long firstLowPos = 0;
        long firstEqualPos = -1;
        // Dichotomy finds the first offset position less than the specified time
        while (startPos <= endPos) {
            midPos = endPos + startPos >>> 1;
            foundTime = getTimeStamp(recordSeg,
                    midPos * DataStoreUtils.STORE_INDEX_HEAD_LEN,
                    curDataMinOffset, readBuffer);
            if (foundTime < timestamp) {
                firstLowPos = midPos;
                startPos = midPos + 1;
            } else {
                endPos = midPos - 1;
                if (foundTime == timestamp) {
                    firstEqualPos = midPos;
                }
            }
        }
        if (firstEqualPos != -1) {
            return recordSeg.getStart() + firstEqualPos * DataStoreUtils.STORE_INDEX_HEAD_LEN;
        } else {
            return recordSeg.getStart() + firstLowPos * DataStoreUtils.STORE_INDEX_HEAD_LEN;
        }
    }
Get the segment start Offset that contains the specified timestamp

@param timestamp           the specified timestamp

@return                    the start offset
inlong-tubemq/tubemq-server/src/main/java/org/apache/inlong/tubemq/server/broker/msgstore/disk/MsgFileStore.java