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

(cherry picked from commit 3a5f6e3bbbea0451004175cbf05fd5fe5dfe7142)