if (r != null && r.isCompactedAway() && !r.isReferencedInReads())
If above check fails then there will be some files which are compacted but not getting cleaned up. It is good to log which helps in debugging the issue. This would let us know why is getting cleaned. either with reference pending or compatedaway is not set.
This will help debug issues like :