protected int binaryInsertOnKeys(String key) throws RecordDuplicatedException {
    if (recordNum == 0) {
      return 0;
    }

    int tarIdx = 0;
    int head = 0;
    int tail = recordNum - 1;

    if (getKeyByIndex(head).compareTo(key) == 0 || getKeyByIndex(tail).compareTo(key) == 0) {
      throw new RecordDuplicatedException(key);
    }

    if (key.compareTo(getKeyByIndex(head)) < 0) {
      return 0;
    }

    if (key.compareTo(getKeyByIndex(tail)) > 0) {
      return recordNum;
    }

    int pivot;
    while (head != tail) {
      pivot = (head + tail) / 2;
      // notice pivot always smaller than list.size()-1
      if (getKeyByIndex(pivot).compareTo(key) == 0
          || getKeyByIndex(pivot + 1).compareTo(key) == 0) {
        throw new RecordDuplicatedException(key);
      }

      if (getKeyByIndex(pivot).compareTo(key) < 0 && getKeyByIndex(pivot + 1).compareTo(key) > 0) {
        return pivot + 1;
      }

      if (pivot == head || pivot == tail) {
        if (getKeyByIndex(head).compareTo(key) > 0) {
          return head;
        }
        if (getKeyByIndex(tail).compareTo(key) < 0) {
          return tail + 1;
        }
      }

      // impossible for pivot.cmp > 0 and (pivot+1).cmp < 0
      if (getKeyByIndex(pivot).compareTo(key) > 0) {
        tail = pivot;
      }

      if (getKeyByIndex(pivot + 1).compareTo(key) < 0) {
        head = pivot;
      }
    }
    return tarIdx;
  }
@param key
@return -1 if not existed, otherwise correspondent position of target offset
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/schemafile/WrappedSegment.java