Fixed bugs in compaction.

- Fixed bug in the fileid_end: files that were not part of the
  compaction ended up being deleted by mistake, creating inconsistencies
  between the index and actual data on secondary storage, making the
  program crash.
- Made sure that fileid_end_expected for the compation is never higher
  than the unfinished files (the files that still have incoming data).