Fix busy-wait loop in Watermark (#920)
Fix busy-wait loop in Watermark (#920)

When doneUntil is very large, process loop in watermark can end up in a busy-wait loop. Fix that by choosing to iterate either over integer range or over waiters, depending upon whichever produces a shorter loop.

Fixes #908 .

Changes:
* When doneUntil is very large, process loop in watermark can end up in a busy-wait loop. Fix that.
* Only call notifyAndRemove if a waiter is present.
* Move updating of w.doneUntil before notifying waiters.

dgraph-io/badger,dgraph-io/badger