protected void cleanFiles()
 	throws Exception
 {
  final Logger log = log();
  if (null == epoch)
  {
   log.fine("Epoch is not set, cleanup skipped");
   return;
  }
  Manager db = getDb();
  PathFilter filter;
  try {
   filter = getEffectiveFilter();
  }
  catch (IOException invalid)
  {
   throw new RuntimeException("Unexpected exception probing a null replica", invalid);
  }
  final long estimatedCount = stats.countFiles();
  FileDAO fileDAO = db.findDAO(FileDAO.class);
  NodeNameDAO nameDAO = db.findDAO(NodeNameDAO.class);
  VersionDAO versionDAO = db.findDAO(VersionDAO.class);
  Cursor<FileDTO> files = fileDAO.fetchAllFiles();
  long deleted = 0L;
  try
  {
   log.info("Removing versions prior to " + epoch + " from shared storage ...");
   for (long count = 0L, threshold = 10L;;)
   {
    FileDTO file = files.next();
    if (null == file) break;
    String[] splitPath = nameDAO.toSplitPath(file.getNameId());
    if (filter.pathMatches(splitPath))
    {
     if (versionDAO.isFileObsolete(file, epoch))
      deleted += purgeObsoleteFile(file);
     else
      deleted += purgeNonObsoleteFile(file);
    }
    count++;
    if (count >= threshold)
    {
     log.info("Cleaned up " + count + " file(s), "
       + (100L * count / estimatedCount) + '%'
       + ", deleted " + deleted + " version(s)");
     threshold += estimatedCount / 10L;
     if (count >= threshold)
      threshold = estimatedCount;
    }
   }
  }
  finally
  {
   try { files.close(); }
   catch (DBException ex) {
    log().log(Level.WARNING, "Error closing cursor over all shared files", ex);
   }
  }
 }