private void checkUnAllocatedRegionIsZeroed(int recordsToCheck) throws IOException {
    int maxAllocatedID = maxAllocatedID();
    int firstUnAllocatedId = maxAllocatedID + 1;
    long unallocatedRegionStartingOffsetInFile = recordOffsetInFileUnchecked(firstUnAllocatedId);
    int unallocatedRegionStartingOffsetOnPage = storage.toOffsetInPage(unallocatedRegionStartingOffsetInFile);
    long actualFileSize = storage.actualFileSize();
    if (unallocatedRegionStartingOffsetOnPage >= actualFileSize) {
      return;//un-allocated file region is definitely empty
    }

    Page lastPage = storage.pageByOffset(unallocatedRegionStartingOffsetInFile);
    ByteBuffer lastPageBuffer = lastPage.rawPageBuffer();

    int maxBytesRemainsOnPage = lastPageBuffer.limit() - unallocatedRegionStartingOffsetOnPage;
    int bytesToCheck = Math.min(
      recordsToCheck * RecordLayout.RECORD_SIZE_IN_BYTES,
      maxBytesRemainsOnPage
    );

    int firstNonZeroOffsetInPage = firstNonZeroByteOffset(lastPageBuffer, unallocatedRegionStartingOffsetOnPage, bytesToCheck);
    if (firstNonZeroOffsetInPage >= 0) {
      //if we already found non-0 record, no reason for economy:
      // => better to collect AMAP diagnostic info
      // => lets check more bytes (but not too many: i.e. scanning 64Mb byte-by-byte could be quite offensive for UX,
      // and for our TeamCity tests as well!)
      int bytesToCheckAdditionally = Math.min(maxBytesRemainsOnPage, 1 << 16);
      int lastNonZeroOffsetInPage = lastNonZeroByteOffset(lastPageBuffer, unallocatedRegionStartingOffsetOnPage, bytesToCheckAdditionally);
      int nonZeroBytesBeyondEOF = lastNonZeroOffsetInPage - unallocatedRegionStartingOffsetOnPage + 1;
      int nonZeroedRecordsCount = (nonZeroBytesBeyondEOF / RecordLayout.RECORD_SIZE_IN_BYTES) + 1;

      throw new CorruptedException(
        "Non-empty records detected beyond current EOF => storage is corrupted.\n" +
        "\tmax allocated id(=" + maxAllocatedID + ")\n" +
        "\tfirst un-allocated offset: " + unallocatedRegionStartingOffsetInFile + "\n" +
        "\tcontent beyond allocated region(" + recordsToCheck + " records max): \n" +
        dumpRecordsAsHex(firstUnAllocatedId, firstUnAllocatedId + recordsToCheck) + "\n" +
        "=" + nonZeroedRecordsCount + " total non-zero records on the page, in range " +
        "[" + unallocatedRegionStartingOffsetInFile + ".." + (unallocatedRegionStartingOffsetInFile + nonZeroBytesBeyondEOF) + "), " +
        "wasClosedProperly=" + wasClosedProperly
      );
    }
  }
private void checkUnAllocatedRegionIsZeroed(int recordsToCheck)