infrastructure for retrying queries