Restore multiple ranges in a kvranges file are failed

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:

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:

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:

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:

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!

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.

1 Like

Thanks

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