final int MAX_MILLIS = 3 * 1000;
try {
CheckedTransaction tx = datastore.beginTransaction();
try {
// TODO(ohler): put current version into cache
DeltaIterator result = mutationLogFactory.create(tx, slobId).forwardHistory(
startVersion, endVersion);
if (!result.hasNext()) {
return new HistoryResult(ImmutableList.<ChangeData<String>>of(), false);
}
ImmutableList.Builder<ChangeData<String>> list = ImmutableList.builder();
Stopwatch stopwatch = new Stopwatch().start();
do {
list.add(result.next());
} while (result.hasNext() && stopwatch.elapsedMillis() < MAX_MILLIS);
return new HistoryResult(list.build(), result.hasNext());
} finally {
tx.rollback();
}
} catch (PermanentFailure e) {
throw new IOException(e);