Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Fargher <jfargher@gitlab.com>2023-01-30 05:05:00 +0300
committerJames Fargher <jfargher@gitlab.com>2023-02-10 00:18:47 +0300
commit4fe0039dbe010b329872fc05f7a949141c6136ee (patch)
treef6f2f2debd382ddba8c55868ecf31118c9b3bc13
parent5010f808b5ea7e2509d9fbf6b9c77c0d28984af6 (diff)
Add RemoveAllRepositories to repositories store
The RPC will eventually want to bulk erase all repositories from the praefect DB, as well as telling each gitaly to remove the physical storage.
-rw-r--r--internal/praefect/datastore/repository_store.go16
-rw-r--r--internal/praefect/datastore/repository_store_test.go53
2 files changed, 69 insertions, 0 deletions
diff --git a/internal/praefect/datastore/repository_store.go b/internal/praefect/datastore/repository_store.go
index 8ec1a03ea..71fe9016e 100644
--- a/internal/praefect/datastore/repository_store.go
+++ b/internal/praefect/datastore/repository_store.go
@@ -112,6 +112,9 @@ type RepositoryStore interface {
// which are known to have a replica at the time of deletion. commonerr.RepositoryNotFoundError is returned when
// the repository is not tracked by the Praefect datastore.
DeleteRepository(ctx context.Context, virtualStorage, relativePath string) (string, []string, error)
+ // DeleteAllRepositories deletes the database records associated with
+ // repositories in the specified virtual storage.
+ DeleteAllRepositories(ctx context.Context, virtualStorage string) error
// DeleteReplica deletes a replica of a repository from a storage without affecting other state in the virtual storage.
DeleteReplica(ctx context.Context, repositoryID int64, storage string) error
// RenameRepository updates a repository's relative path. It renames the virtual storage wide record as well
@@ -518,6 +521,19 @@ GROUP BY replica_path
return replicaPath, storages.Slice(), nil
}
+//nolint:revive // This is unintentionally missing documentation.
+func (rs *PostgresRepositoryStore) DeleteAllRepositories(ctx context.Context, virtualStorage string) error {
+ _, err := rs.db.ExecContext(ctx, `
+DELETE FROM repositories
+WHERE virtual_storage = $1
+ `, virtualStorage)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
// DeleteReplica deletes a record from the `storage_repositories`. See the interface documentation for details.
func (rs *PostgresRepositoryStore) DeleteReplica(ctx context.Context, repositoryID int64, storage string) error {
result, err := rs.db.ExecContext(ctx, `
diff --git a/internal/praefect/datastore/repository_store_test.go b/internal/praefect/datastore/repository_store_test.go
index edb9e77b4..c3410ee3c 100644
--- a/internal/praefect/datastore/repository_store_test.go
+++ b/internal/praefect/datastore/repository_store_test.go
@@ -621,6 +621,59 @@ func TestRepositoryStore_Postgres(t *testing.T) {
})
})
+ t.Run("DeleteAllRepositories", func(t *testing.T) {
+ rs := newRepositoryStore(t, nil)
+
+ require.NoError(t, rs.CreateRepository(ctx, 1, "virtual-storage-1", "repository-1", "replica-path-1", "storage-1", nil, nil, false, false))
+ require.NoError(t, rs.CreateRepository(ctx, 2, "virtual-storage-2", "repository-1", "replica-path-2", "storage-1", []string{"storage-2"}, nil, false, false))
+ require.NoError(t, rs.CreateRepository(ctx, 3, "virtual-storage-2", "repository-2", "replica-path-3", "storage-1", nil, nil, false, false))
+
+ requireState(t, ctx, db,
+ virtualStorageState{
+ "virtual-storage-1": {
+ "repository-1": {repositoryID: 1, replicaPath: "replica-path-1"},
+ },
+ "virtual-storage-2": {
+ "repository-1": {repositoryID: 2, replicaPath: "replica-path-2"},
+ "repository-2": {repositoryID: 3, replicaPath: "replica-path-3"},
+ },
+ },
+ storageState{
+ "virtual-storage-1": {
+ "repository-1": {
+ "storage-1": {repositoryID: 1},
+ },
+ },
+ "virtual-storage-2": {
+ "repository-1": {
+ "storage-1": {repositoryID: 2},
+ "storage-2": {repositoryID: 2},
+ },
+ "repository-2": {
+ "storage-1": {repositoryID: 3},
+ },
+ },
+ },
+ )
+
+ require.NoError(t, rs.DeleteAllRepositories(ctx, "virtual-storage-2"))
+
+ requireState(t, ctx, db,
+ virtualStorageState{
+ "virtual-storage-1": {
+ "repository-1": {repositoryID: 1, replicaPath: "replica-path-1"},
+ },
+ },
+ storageState{
+ "virtual-storage-1": {
+ "repository-1": {
+ "storage-1": {repositoryID: 1},
+ },
+ },
+ },
+ )
+ })
+
t.Run("DeleteRepository", func(t *testing.T) {
t.Run("delete non-existing", func(t *testing.T) {
rs := newRepositoryStore(t, nil)