This adds logic to put segments into batches and retry them. Change-Id: I86450e2f5ab13edb3ae9a5d5b9417e0cced2892b