/**
     * Advance the iterator. Should only be called if {@link #isValid()} returned true. Valid can
     * only chance after calls to {@link #next()}.
     */
    public void next() {
      newKeyGroup = false;
      newKVState = false;

      final RocksIterator rocksIterator = currentSubIterator.getIterator();
      rocksIterator.next();

      byte[] oldKey = currentSubIterator.getCurrentKey();
      if (rocksIterator.isValid()) {
        currentSubIterator.currentKey = rocksIterator.key();

        if (isDifferentKeyGroup(oldKey, currentSubIterator.getCurrentKey())) {
          heap.offer(currentSubIterator);
          currentSubIterator = heap.poll();
          newKVState = currentSubIterator.getIterator() != rocksIterator;
          detectNewKeyGroup(oldKey);
        }
      } else {
        rocksIterator.close();

        if (heap.isEmpty()) {
          currentSubIterator = null;
          valid = false;
        } else {
          currentSubIterator = heap.poll();
          newKVState = true;
          detectNewKeyGroup(oldKey);
        }
      }
    }
    @Override
    public void close() {

      if (null != currentSubIterator) {
        currentSubIterator.close();
        currentSubIterator = null;
      }

      for (MergeIterator iterator : heap) {
        iterator.close();
      }

      heap.clear();
    }
 public byte[] value() {
   return currentSubIterator.getIterator().value();
 }
 /**
  * Returns the Id of the k/v state to which the current key belongs.
  *
  * @return Id of K/V state to which the current key belongs.
  */
 public int kvStateId() {
   return currentSubIterator.getKvStateId();
 }
 public byte[] key() {
   return currentSubIterator.getCurrentKey();
 }