@Override
  public void deleteRecord(int recordId) throws IOException {
    checkRecordIdExists(recordId);

    long recordOffset = idToOffset(recordId);
    Page page = storage.pageByOffset(recordOffset);
    int offsetOnPage = storage.toOffsetInPage(recordOffset);
    ByteBuffer buffer = page.rawPageBuffer();
    RecordLayout recordLayout = RecordLayout.recordLayout(buffer, offsetOnPage);
    int recordCapacity = recordLayout.capacity(buffer, offsetOnPage);
    int recordActualLength = recordLayout.length(buffer, offsetOnPage);
    byte recordType = recordLayout.recordType();
    switch (recordType) {
      case RecordLayout.RECORD_TYPE_MOVED -> {
        int redirectToId = recordLayout.redirectToId(buffer, offsetOnPage);
        if (redirectToId == NULL_ID) {
          throw new RecordAlreadyDeletedException("Can't delete record[" + recordId + "]: it was already deleted");
        }

        // (redirectToId=NULL) <=> 'record deleted' ('moved nowhere')
        ((RecordLayout.MovedRecord)recordLayout).putRedirectTo(buffer, offsetOnPage, NULL_ID);
      }
      case RecordLayout.RECORD_TYPE_ACTUAL -> {
        RecordLayout.MovedRecord movedRecordLayout = RecordLayout.MovedRecord.INSTANCE;
        //Total space occupied by record must remain constant, but record capacity should be
        // changed since MovedRecord has another headerSize than Small|LargeRecord
        int deletedRecordCapacity = recordLayout.fullRecordSize(recordCapacity) - movedRecordLayout.headerSize();
        // set (redirectToId=NULL) to mark record as deleted ('moved nowhere')
        movedRecordLayout.putRecord(buffer, offsetOnPage, deletedRecordCapacity, /* length: */ 0, NULL_ID, null);
      }
      default -> throw new AssertionError("RecordType(" + recordType + ") should not appear in the chain: " +
                                          "it is either not implemented yet, or all wrong");
    }

    recordsDeleted.incrementAndGet();
    totalLiveRecordsPayloadBytes.addAndGet(-recordActualLength);
    totalLiveRecordsCapacityBytes.addAndGet(-recordCapacity);
  }
@Override
  public void deleteRecord(int recordId)