# Restore multiple ranges in a kvranges file are failed

**URL:** <https://forums.foundationdb.org/t/restore-multiple-ranges-in-a-kvranges-file-are-failed/3972>\
**Category:** FoundationDB Core\
**Created:** [May 22, 2023, 8:20am UTC](https://forums.foundationdb.org/t/restore-multiple-ranges-in-a-kvranges-file-are-failed/3972 "2023-05-22T08:20:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![walter](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/walter/32/1592_2.png) [@walter](https://forums.foundationdb.org/u/walter)\
**Post date:** [May 22, 2023, 8:20am UTC](https://forums.foundationdb.org/t/restore-multiple-ranges-in-a-kvranges-file-are-failed/3972/1 "2023-05-22T08:20:49Z")

</div>

I am working on a recovery service, attempting to recover multiple key ranges from backup as needed, so I conducted a test and found this issue.

Now here is a backup that contains keys `aa`, `aaa`, `b`, `bb` and `bbb`. Now I need to use restore to recover data and filter out a certain range, eg: `b`. I try to restore it with cmd:

```auto
fdbrestore start --dest-cluster-file /home/xxxx/workspace/fdb_test_env/fdb_cluster/fdb.cluster -r file:///home/xxxx/workspace/fdb_test_env/backups/backup-2023-05-22-11-56-40.011576/ -k 'bb bbbb' -k 'aa aaaa'

```

After the restore is finished, I try to use `getrange` to verify whether the restore was successfully executed, but I found that there was no range `bb bbbb` in the results:

```auto
Welcome to the fdbcli. For help, type `help'.
fdb> getrange a z

Range limited to 25 keys
`aa' is `2a'
`aaa' is `3a'

```

The excepted results should be:

```auto
Welcome to the fdbcli. For help, type `help'.
fdb> getrange a z

Range limited to 25 keys
`aa' is `2a'
`aaa' is `3a'
`bb' is `2b'
`bbb' is `3b'

```

I tracked the code and found that the problem may be caused by adjusting the `fileRange` during the `RestoreRangeTaskFunc::_execute`:

> <https://github.com/apple/foundationdb/blob/main/fdbclient/FileBackupAgent.actor.cpp#L3803-L3844>

Line 3809, determine if there is an intersection between `fileRange` and `restoreRange`.  
Line 3834-3840, update `fileRange` to the dest `restoreRange`.

When the program executes to 3809 again, the data in `fileRange` is no longer correct, so it does not intersect with `restoreRange`.

BTW, I am interested in fixing this issue, but I do not have permission to provide PR for Apple/Foundationdb’s repo. Can someone help invite me? My github ID is w41ter, thank you!

---

<div class="post-metadata">

**Author:** ![jzhou](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/jzhou/32/445_2.png) [@jzhou](https://forums.foundationdb.org/u/jzhou)\
**Post date:** [May 23, 2023, 4:13am UTC](https://forums.foundationdb.org/t/restore-multiple-ranges-in-a-kvranges-file-are-failed/3972/2 "2023-05-23T04:13:03Z")

</div>

I’m actually surprised the test didn’t find this issue. Looks like line 3803 should be moved inside the `for` loop. Thanks for finding this bug and @ammolitor can invite you to create PRs.

---

<div class="post-metadata">

**Author:** ![walter](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/walter/32/1592_2.png) [@walter](https://forums.foundationdb.org/u/walter)\
**Post date:** [May 24, 2023, 2:34am UTC](https://forums.foundationdb.org/t/restore-multiple-ranges-in-a-kvranges-file-are-failed/3972/3 "2023-05-24T02:34:55Z")

</div>

Thanks

Hi, @ammolitor, could I get permission to open pull requests to the foundationdb repository? My github id is w41ter.
