CreateRepositoryFromSnapshot will fail with error 'Promoting temporary directory failed' if parent directories of target path do not already exist
If CreateRepositoryFromSnapshot
is called when the parent directory of the target path does not exist, the request will fail with error:
rpc error: code = Internal desc = Promoting temporary directory failed: rename /var/opt/gitlab/git-data/repositories/+gitaly/tmp/repo446863582 /var/opt/gitlab/git-data/repositories/@geo-temporary/@hashed/
19/58/19581e27de7ced00ff1ce50b2047e7a567c76b1cbaebabe5ef03f7c3017bb5b7.git: no such file or directory
Stracing this, we find that the renameat
call fails with ENOENT:
18192 22:01:24.772985 renameat(AT_FDCWD, "/var/opt/gitlab/git-data/repositories/+gitaly/tmp/repo446863582", AT_FDCWD, "/var/opt/gitlab/git-data/repositories/@ge
o-temporary/@hashed/19/58/19581e27de7ced00ff1ce50b2047e7a567c76b1cbaebabe5ef03f7c3017bb5b7.git") = -1 ENOENT (No such file or directory) <0.000013>
Generally this RPC is only called on a second attempt to create a repository, so the directory has already been created, but due to gitlab#9803 (comment 422414267) these calls were the first attempt, exposing this issue.
ReplicateRepository
will ensure the directories are present before renaming the tmp directory, we should do the same in this RPC.