# Large Range Scans - avoid 5s limit

**URL:** <https://forums.foundationdb.org/t/large-range-scans-avoid-5s-limit/292>\
**Category:** Using FoundationDB\
**Created:** [April 27, 2018, 4:55pm UTC](https://forums.foundationdb.org/t/large-range-scans-avoid-5s-limit/292 "2018-04-27T16:55:36Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![gaurav](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gaurav](https://forums.foundationdb.org/u/gaurav)\
**Post date:** [January 1, 2020, 11:51am UTC](https://forums.foundationdb.org/t/large-range-scans-avoid-5s-limit/292/10 "2020-01-01T11:51:53Z")

</div>

Here is the almost complete code snippet that I currently use for this purpose. It should be straight forward to extend/update it:

```auto
// input byte[] start, byte[] end, boolean reverse
final AtomicReference<byte[]> seen = new AtomicReference<>(null);

fdb.readAsync(tx -> {
    // DO: Set timeout, num retries on the transaction object (tx)
    byte[] en = end;
    byte[] st = start;

    if (reverse) {
        en = seen.get() != null ? seen.get() : end;
    } else {
        // Note: nextKey is merged in master branch and not present on 6.2; copy it from github
        st = seen.get() != null ? ByteArrayUtil.nextKey(seen.get()) : start; 
    }

    return AsyncUtil.forEach(
            tx.getRange(st, en, ROW_LIMIT_UNLIMITED, reverse),
            kv -> {
                seen.set(kv.getKey());
                // DO: Consume the KV here...
            });
}, executor).join();
```

---

_[View the full topic](https://forums.foundationdb.org/t/large-range-scans-avoid-5s-limit/292)._
