private ISegment<ByteBuffer, ICachedMNode> getSegment(short index)
      throws SegmentNotFoundException {
    if (segOffsetLst.size() <= index || segOffsetLst.get(index) < 0) {
      throw new SegmentNotFoundException(pageIndex, index);
    }

    synchronized (segCacheMap) {
      if (segCacheMap.containsKey(index)) {
        return segCacheMap.get(index);
      }
    }

    // duplicate for concurrent event
    ByteBuffer bufferR = this.pageBuffer.duplicate();
    bufferR.clear();
    bufferR.position(getSegmentOffset(index));
    bufferR.limit(bufferR.position() + WrappedSegment.getSegBufLen(bufferR));

    ISegment<ByteBuffer, ICachedMNode> res;
    try {
      res = WrappedSegment.loadAsSegment(bufferR.slice());
    } catch (RecordDuplicatedException e) {
      throw new SegmentNotFoundException(e.getMessage());
    }

    synchronized (segCacheMap) {
      if (segCacheMap.containsKey(index)) {
        return segCacheMap.get(index);
      }

      segCacheMap.put(index, res);
      return res;
    }
  }
Retrieve leaf segment instance by index, instantiated and add to cache map if not yet.

@param index index rather than offset of the segment
@return null if InternalSegment, otherwise instance
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/schemafile/SegmentedPage.java