TEZ-1701. ATS fixes to flush all history events and also using batching. (hitesh)

(cherry picked from commit a6c8006c37334099a8a77befa3b687113514a35c)