code: func (db *DB) CompactRange(r util.Range) error {
  	if err := db.ok(); err != nil {
  		return err
  	}
  
  	// Lock writer.
  	select {
  	case db.writeLockC <- struct{}{}:
  	case err := <-db.compPerErrC:
  		return err
  	case <-db.closeC:
  		return ErrClosed
  	}
  
  	// Check for overlaps in memdb.
  	mdb := db.getEffectiveMem()
  	if mdb == nil {
  		return ErrClosed
  	}
  	defer mdb.decref()
  	if isMemOverlaps(db.s.icmp, mdb.DB, r.Start, r.Limit) {
  		// Memdb compaction.
  		if _, err := db.rotateMem(0, false); err != nil {
  			<-db.writeLockC
  			return err
  		}
  		<-db.writeLockC
  		if err := db.compTriggerWait(db.mcompCmdC); err != nil {
  			return err
  		}
  	} else {
  		<-db.writeLockC
  	}
  
  	// Table compaction.
  	return db.compTriggerRange(db.tcompCmdC, -1, r.Start, r.Limit)
  }
docs: // CompactRange compacts the underlying DB for the given key range.
  // In particular, deleted and overwritten versions are discarded,
  // and the data is rearranged to reduce the cost of operations
  // needed to access the data. This operation should typically only
  // be invoked by users who understand the underlying implementation.
  //
  // A nil Range.Start is treated as a key before all keys in the DB.
  // And a nil Range.Limit is treated as a key after all keys in the DB.
  // Therefore if both is nil then it will compact entire DB.