@Override
  public long update(short segIdx, String key, ByteBuffer buffer) throws MetadataException {
    ISegment<ByteBuffer, ICachedMNode> seg = getSegment(segIdx);

    if (seg.updateRecord(key, buffer) < 0) {
      short spare = spareSize;
      seg =
          relocateSegment(
              seg, segIdx, SchemaFile.reEstimateSegSize(seg.size() + buffer.capacity()));

      if (seg == null) {
        return -1;
      }

      if (seg.updateRecord(key, buffer) < 0) {
        throw new MetadataException("failed to update buffer upon relocated segment");
      }
      return spare >= spareSize ? 0 : spareSize - spare;
    }
    return 0L;
  }
This class is aimed to manage space inside one page.

<p>A segment inside a page has 3 representation: index, offset and instance. <br>

<ul>
  <li>Index is meant to decouple file-wide indexing with in-page compaction
  <li>Offset is meant for in-page indexing
  <li>Segment instance is meant for records manipulations
</ul>

<b>Page Header Structure as in {@linkplain ISchemaPage}.</b>

<p>Page Body Structure:

<ul>
  <li>var length * memberNum: {@linkplain WrappedSegment} contains serialized ICacheMNodes.
  <li>... spare space...
  <li>2 bytes * memberNum: offset of segments, using marking deletion as {@linkplain
      #deleteSegment} mentioned.
</ul>
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/schemafile/SegmentedPage.java