private void tryCommitFinalizedRecords() throws IOException {
    CAS_LOOP:
    while (true) {
      long firstUnCommittedRecordOffset = firstUnCommittedOffset();

      long nextUncommittedRecordOffset = firstUnCommittedRecordOffset;
      long allocatedUpTo = firstUnAllocatedOffset();
      int dataRecordsToCommit = 0;//padding records not counted
      while (nextUncommittedRecordOffset < allocatedUpTo) {//scanning through all finalized-not-yet-commited records
        MMappedFileStorage.Page page = storage.pageByOffset(nextUncommittedRecordOffset);
        int offsetInPage = storage.toOffsetInPage(nextUncommittedRecordOffset);
        int recordHeader = RecordLayout.readHeader(page.rawPageBuffer(), offsetInPage);
        int totalRecordLength = RecordLayout.extractRecordLength(recordHeader);
        if (totalRecordLength == 0) {
          break; //record is not finalized (yet)
        }
        if (RecordLayout.isDataHeader(recordHeader)) {
          dataRecordsToCommit++;
        }

        nextUncommittedRecordOffset = nextRecordOffset(nextUncommittedRecordOffset, totalRecordLength);
      }

      if (nextUncommittedRecordOffset == firstUnCommittedRecordOffset) {
        return;
      }

      if (!casFirstUnCommittedOffset(firstUnCommittedRecordOffset, nextUncommittedRecordOffset)) {
        continue CAS_LOOP;
      }

      addToDataRecordsCount(dataRecordsToCommit);
      return;
    }
  }
private void tryCommitFinalizedRecords()