private void reinitializeCellSet(int numOfCells, KeyValueScanner segmentScanner,
    CellSet<ExtendedCell> oldCellSet, MemStoreSizing memstoreSizing,
    MemStoreCompactionStrategy.Action action) {
    ExtendedCell curCell;
    Chunk[] chunks = allocIndexChunks(numOfCells);

    int currentChunkIdx = 0;
    int offsetInCurentChunk = ChunkCreator.SIZEOF_CHUNK_HEADER;

    int numUniqueKeys = 0;
    ExtendedCell prev = null;
    try {
      while ((curCell = segmentScanner.next()) != null) {
        if (curCell.getChunkId() == ExtendedCell.CELL_NOT_BASED_ON_CHUNK) {
          // CellChunkMap assumes all cells are allocated on MSLAB.
          // Therefore, cells which are not allocated on MSLAB initially,
          // are copied into MSLAB here.
          curCell = copyCellIntoMSLAB(curCell, memstoreSizing);
        }
        if (offsetInCurentChunk + ClassSize.CELL_CHUNK_MAP_ENTRY > chunks[currentChunkIdx].size) {
          // continue to the next metadata chunk
          currentChunkIdx++;
          offsetInCurentChunk = ChunkCreator.SIZEOF_CHUNK_HEADER;
        }
        offsetInCurentChunk = createCellReference((ByteBufferKeyValue) curCell,
          chunks[currentChunkIdx].getData(), offsetInCurentChunk);
        if (action == MemStoreCompactionStrategy.Action.FLATTEN_COUNT_UNIQUE_KEYS) {
          // counting number of unique keys
          if (prev != null) {
            if (!CellUtil.matchingRowColumn(prev, curCell)) {
              numUniqueKeys++;
            }
          } else {
            numUniqueKeys++;
          }
        }
        prev = curCell;
      }
      if (action != MemStoreCompactionStrategy.Action.FLATTEN_COUNT_UNIQUE_KEYS) {
        numUniqueKeys = CellSet.UNKNOWN_NUM_UNIQUES;
      }
    } catch (IOException ie) {
      throw new IllegalStateException(ie);
    } finally {
      segmentScanner.close();
    }

    CellChunkMap<ExtendedCell> ccm =
      new CellChunkMap<>(getComparator(), chunks, 0, numOfCells, false);
    // update the CellSet of this Segment
    this.setCellSet(oldCellSet, new CellSet<>(ccm, numUniqueKeys));
  }
------------------------------------------------------------------------ C-tor to be used when
new CellChunkImmutableSegment is built as a result of flattening of CSLMImmutableSegment The
given iterator returns the Cells that "survived" the compaction.
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellChunkImmutableSegment.java