A non-transitory computer-readable medium storing program code, the program code executable by a computing system to:
- receive a first request to copy a database of a first tenant stored in a plurality of storage nodes to a second tenant, the database including a first database table, where a backup of a first shard of the first database table is stored in a first backup location and a backup of a second shard of the first database table is stored in a second backup location, the first shard including a first key range of the first database table and the second shard including a second key range of the first database table;
- in response to the first request, copy a root shard of the database of the first tenant, the root shard including metadata specifying the first backup location of the first shard and the second backup location of the second shard, change a first identifier of the first tenant in the copied root shard to a second identifier of the second tenant, and store the modified root shard in one of the plurality of storage nodes;
- receive a second request to access the first shard from a requestor associated with the second tenant;
- in response to the second request:
- determine, based on the stored root shard, that the first shard is not stored in any of a plurality of storage nodes and
- in response to the determination:
- determining, based on the stored root shard, that the backup of the first shard is stored in the first backup location;
- issue an instruction to copy the first shard to a first storage node of the plurality of storage nodes from the first backup location;
- modify the stored root shard to associate the first shard with an identifier of the first storage node;
- and
- return the identifier of the first storage node to the requestor;
- receive a third request to access the first shard and the second shard from a second requestor;
- and
- in response to the third request:
- determine based on the stored root shard that the first shard is stored in the first storage node and the second shard is not stored in any of the plurality of other storage nodes;
- and
- in response to the determination that the first shard is stored in the first storage node and the second shard is not stored in any of the plurality of other storage nodes:
- determine, based on the stored root shard, that the backup of the second shard is stored in the second backup location;
- issue an instruction to copy the second shard to a second storage node of the plurality of storage nodes from the second backup location;
- modify the stored root shard to associate the second shard with an identifier of the second storage node;
- and
- return the identifier of the first storage node and an identifier of the second storage node to the second requestor.