ENG-6251: optimized flush and tests for flush.