private synchronized short registerNewSegment(ISegment<ByteBuffer, ICachedMNode> seg)
      throws MetadataException {
    short thisIndex = (short) segOffsetLst.size();
    if (segCacheMap.containsKey(thisIndex)) {
      throw new MetadataException(
          String.format("Segment cache map inconsistent with segment list in page %d.", pageIndex));
    }

    segCacheMap.put(thisIndex, seg);
    segOffsetLst.add(spareOffset);

    spareOffset += seg.size();
    spareSize -= seg.size() + 2;
    memberNum += 1;

    return thisIndex;
  }
Register segment instance to segCacheMap and segOffList, modify pageSpareOffset and segNum
respectively

@param seg the segment to register
@return index of the segment
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/schemafile/SegmentedPage.java