Source:
<code>private void checkBlockSizeReached() throws IOException { if (recordCount >= recordCountForNextMemCheck) { boolean startNewRowGroup = false; long memSize = columnStore.getBufferedSize(); long recordSize = memSize / recordCount; if (memSize > nextRowGroupSize) { columnStore.writePages(); final long newMemSize = columnStore.getBufferedSize(); LOG.debug("mem size > {}: closing pages. Mem size after closing pages: {}. Min size for starting new row group: {}", memSize, nextRowGroupSize, newMemSize, minSizeForAlignment); memSize = newMemSize; recordSize = memSize / recordCount; if (memSize > minSizeForAlignment) { startNewRowGroup = true; LOG.debug("mem size > {}: flushing records to disk.", memSize, minSizeForAlignment, recordCount); } } <START> if (startNewRowGroup) { <END> flushRowGroupToStore(); initStore(); recordCountForNextMemCheck = min(max(MINIMUM_RECORD_COUNT_FOR_CHECK, recordCount / 2), MAXIMUM_RECORD_COUNT_FOR_CHECK); this.lastRowGroupEndPos = parquetFileWriter.getPos(); } else { long estimatedRecordCountInRowGroup = nextRowGroupSize / recordSize; LOG.debug("Estimated record count is {}", estimatedRecordCountInRowGroup); recordCountForNextMemCheck = recordCount/2 + estimatedRecordCountInRowGroup/2; if (recordCountForNextMemCheck < MINIMUM_RECORD_COUNT_FOR_CHECK) { recordCountForNextMemCheck = MINIMUM_RECORD_COUNT_FOR_CHECK; } if (recordCountForNextMemCheck > recordCount + MAXIMUM_RECORD_COUNT_FOR_CHECK) { recordCountForNextMemCheck = recordCount + MAXIMUM_RECORD_COUNT_FOR_CHECK; } LOG.debug("Checked mem at will check again at: {}", recordCount, recordCountForNextMemCheck); } } }</code><technical_language>nit: this flagging concept in method. I suggest putting related code place flag is true</technical_language>

Target:
private void checkBlockSizeReached() throws IOException { if (recordCount >= recordCountForNextMemCheck) { long memSize = columnStore.getBufferedSize(); if (memSize > nextRowGroupSize) { columnStore.writePages(); final long newMemSize = columnStore.getBufferedSize(); LOG.debug("mem size > {}: closing pages. Mem size after closing pages: {}. Min size for starting new row group: {}", memSize, nextRowGroupSize, newMemSize, minSizeForAlignment); memSize = newMemSize; if (memSize > minSizeForAlignment) { LOG.debug("mem size > {}: flushing records to disk.", memSize, minSizeForAlignment, recordCount); flushRowGroupToStore(); initStore(); recordCountForNextMemCheck = min(max(MINIMUM_RECORD_COUNT_FOR_CHECK, recordCount/5), MAXIMUM_RECORD_COUNT_FOR_CHECK); this.lastRowGroupEndPos = parquetFileWriter.getPos(); return; } } final long estimatedRecordCountInRowGroup = nextRowGroupSize / memSize * recordCount; LOG.debug("Estimated record count is {}", estimatedRecordCountInRowGroup); recordCountForNextMemCheck = recordCount/5*4 + estimatedRecordCountInRowGroup/5; if (recordCountForNextMemCheck < MINIMUM_RECORD_COUNT_FOR_CHECK) { recordCountForNextMemCheck = MINIMUM_RECORD_COUNT_FOR_CHECK; } if (recordCountForNextMemCheck > recordCount + MAXIMUM_RECORD_COUNT_FOR_CHECK) { recordCountForNextMemCheck = recordCount + MAXIMUM_RECORD_COUNT_FOR_CHECK; } LOG.debug("Checked mem at will check again at: {}", recordCount, recordCountForNextMemCheck); } }