diff options
author | Sami Hiltunen <shiltunen@gitlab.com> | 2021-09-13 09:57:57 +0300 |
---|---|---|
committer | Sami Hiltunen <shiltunen@gitlab.com> | 2021-09-13 09:57:57 +0300 |
commit | fa6eb13ccb4f2d5a36d3c010eeb197eb2bfdc825 (patch) | |
tree | 5b858faef2224f127772dff26b3703f82cc4783b | |
parent | ffaf216dd0c5cbdc385b43f43d8cfec491fffb72 (diff) | |
parent | 28b284581b5156f27fdf551e04e9fad302a51610 (diff) |
Merge branch 'smh-replica-path' into 'master'
Add replica path column to repositories table
See merge request gitlab-org/gitaly!3840
3 files changed, 56 insertions, 38 deletions
diff --git a/internal/praefect/datastore/migrations/20210906130405_add_replica_path.go b/internal/praefect/datastore/migrations/20210906130405_add_replica_path.go new file mode 100644 index 000000000..5efa8280e --- /dev/null +++ b/internal/praefect/datastore/migrations/20210906130405_add_replica_path.go @@ -0,0 +1,13 @@ +package migrations + +import migrate "github.com/rubenv/sql-migrate" + +func init() { + m := &migrate.Migration{ + Id: "20210906130405_add_replica_path", + Up: []string{"ALTER TABLE repositories ADD COLUMN replica_path TEXT"}, + Down: []string{"ALTER TABLE repositories DROP COLUMN replica_path"}, + } + + allMigrations = append(allMigrations, m) +} diff --git a/internal/praefect/datastore/repository_store.go b/internal/praefect/datastore/repository_store.go index d0bc48661..49bb6e547 100644 --- a/internal/praefect/datastore/repository_store.go +++ b/internal/praefect/datastore/repository_store.go @@ -351,9 +351,10 @@ WITH repo AS ( repository_id, virtual_storage, relative_path, + replica_path, generation, "primary" - ) VALUES ($8, $1, $2, 0, CASE WHEN $4 THEN $3 END) + ) VALUES ($8, $1, $2, $2, 0, CASE WHEN $4 THEN $3 END) ), assignments AS ( @@ -462,7 +463,8 @@ func (rs *PostgresRepositoryStore) RenameRepository(ctx context.Context, virtual const q = ` WITH repo AS ( UPDATE repositories - SET relative_path = $4 + SET relative_path = $4, + replica_path = $4 WHERE virtual_storage = $1 AND relative_path = $2 ) diff --git a/internal/praefect/datastore/repository_store_test.go b/internal/praefect/datastore/repository_store_test.go index 0e12c5d12..caee75ce8 100644 --- a/internal/praefect/datastore/repository_store_test.go +++ b/internal/praefect/datastore/repository_store_test.go @@ -17,6 +17,7 @@ import ( // repositoryRecord represents Praefect's records related to a repository. type repositoryRecord struct { repositoryID int64 + replicaPath string primary string assignments []string } @@ -44,7 +45,7 @@ func requireState(t testing.TB, ctx context.Context, db glsql.Querier, vss virtu requireVirtualStorageState := func(t testing.TB, ctx context.Context, exp virtualStorageState) { rows, err := db.QueryContext(ctx, ` -SELECT repository_id, virtual_storage, relative_path, "primary", assigned_storages +SELECT repository_id, virtual_storage, relative_path, replica_path, "primary", assigned_storages FROM repositories LEFT JOIN ( SELECT repository_id, virtual_storage, relative_path, array_agg(storage ORDER BY storage) AS assigned_storages @@ -59,18 +60,19 @@ LEFT JOIN ( act := make(virtualStorageState) for rows.Next() { var ( - repositoryID sql.NullInt64 - virtualStorage, relativePath string - primary sql.NullString - assignments pq.StringArray + repositoryID sql.NullInt64 + virtualStorage, relativePath, replicaPath string + primary sql.NullString + assignments pq.StringArray ) - require.NoError(t, rows.Scan(&repositoryID, &virtualStorage, &relativePath, &primary, &assignments)) + require.NoError(t, rows.Scan(&repositoryID, &virtualStorage, &relativePath, &replicaPath, &primary, &assignments)) if act[virtualStorage] == nil { act[virtualStorage] = make(map[string]repositoryRecord) } act[virtualStorage][relativePath] = repositoryRecord{ repositoryID: repositoryID.Int64, + replicaPath: replicaPath, primary: primary.String, assignments: assignments, } @@ -221,7 +223,7 @@ func TestRepositoryStore_incrementGenerationConcurrently(t *testing.T) { secondTx.Commit(t) requireState(t, ctx, db, - virtualStorageState{"virtual-storage": {"relative-path": {repositoryID: 1}}}, + virtualStorageState{"virtual-storage": {"relative-path": {repositoryID: 1, replicaPath: "relative-path"}}}, tc.state, ) }) @@ -293,7 +295,7 @@ func testRepositoryStore(t *testing.T, newStore repositoryStoreFactory) { requireState(t, ctx, virtualStorageState{ "virtual-storage-1": { - "repository-1": {repositoryID: 1}, + "repository-1": {repositoryID: 1, replicaPath: "repository-1"}, }, }, storageState{ @@ -326,11 +328,11 @@ func testRepositoryStore(t *testing.T, newStore repositoryStoreFactory) { requireState(t, ctx, virtualStorageState{ "virtual-storage-1": { - "repository-1": {repositoryID: 1}, - "other-relative-path": {repositoryID: 2}, + "repository-1": {repositoryID: 1, replicaPath: "repository-1"}, + "other-relative-path": {repositoryID: 2, replicaPath: "other-relative-path"}, }, "other-virtual-storage": { - "repository-1": {repositoryID: 3}, + "repository-1": {repositoryID: 3, replicaPath: "repository-1"}, }, }, storageState{ @@ -362,11 +364,11 @@ func testRepositoryStore(t *testing.T, newStore repositoryStoreFactory) { requireState(t, ctx, virtualStorageState{ "virtual-storage-1": { - "repository-1": {repositoryID: 1}, - "other-relative-path": {repositoryID: 2}, + "repository-1": {repositoryID: 1, replicaPath: "repository-1"}, + "other-relative-path": {repositoryID: 2, replicaPath: "other-relative-path"}, }, "other-virtual-storage": { - "repository-1": {repositoryID: 3}, + "repository-1": {repositoryID: 3, replicaPath: "repository-1"}, }, }, storageState{ @@ -421,7 +423,7 @@ func testRepositoryStore(t *testing.T, newStore repositoryStoreFactory) { requireState(t, ctx, virtualStorageState{ "virtual-storage-1": { - "repository-1": {repositoryID: 1}, + "repository-1": {repositoryID: 1, replicaPath: "repository-1"}, }, }, storageState{ @@ -450,7 +452,7 @@ func testRepositoryStore(t *testing.T, newStore repositoryStoreFactory) { requireState(t, ctx, virtualStorageState{ "virtual-storage-1": { - "repository-1": {repositoryID: 1}, + "repository-1": {repositoryID: 1, replicaPath: "repository-1"}, }, }, storageState{ @@ -467,7 +469,7 @@ func testRepositoryStore(t *testing.T, newStore repositoryStoreFactory) { requireState(t, ctx, virtualStorageState{ "virtual-storage-1": { - "repository-1": {repositoryID: 1}, + "repository-1": {repositoryID: 1, replicaPath: "repository-1"}, }, }, storageState{ @@ -626,6 +628,7 @@ func testRepositoryStore(t *testing.T, newStore repositoryStoreFactory) { vs: { repo: { repositoryID: 1, + replicaPath: repo, primary: tc.expectedPrimary, assignments: tc.expectedAssignments, }, @@ -676,14 +679,14 @@ func testRepositoryStore(t *testing.T, newStore repositoryStoreFactory) { requireState(t, ctx, virtualStorageState{ "deleted": { - "deleted": {repositoryID: 1}, + "deleted": {repositoryID: 1, replicaPath: "deleted"}, }, "virtual-storage-1": { - "other-storages-remain": {repositoryID: 2}, + "other-storages-remain": {repositoryID: 2, replicaPath: "other-storages-remain"}, }, "virtual-storage-2": { - "deleted-repo": repositoryRecord{repositoryID: 3}, - "other-repo-remains": {repositoryID: 4}, + "deleted-repo": {repositoryID: 3, replicaPath: "deleted-repo"}, + "other-repo-remains": {repositoryID: 4, replicaPath: "other-repo-remains"}, }, }, storageState{ @@ -716,7 +719,7 @@ func testRepositoryStore(t *testing.T, newStore repositoryStoreFactory) { requireState(t, ctx, virtualStorageState{ "virtual-storage-2": { - "other-repo-remains": {repositoryID: 4}, + "other-repo-remains": {repositoryID: 4, replicaPath: "other-repo-remains"}, }, }, storageState{ @@ -741,7 +744,7 @@ func testRepositoryStore(t *testing.T, newStore repositoryStoreFactory) { requireState(t, ctx, virtualStorageState{ "virtual-storage-1": { - "repository-1": {repositoryID: 1}, + "repository-1": {repositoryID: 1, replicaPath: "repository-1"}, }, }, storageState{ @@ -784,11 +787,11 @@ func testRepositoryStore(t *testing.T, newStore repositoryStoreFactory) { requireState(t, ctx, virtualStorageState{ "virtual-storage-1": { - "relative-path-1": {repositoryID: 1}, - "relative-path-2": {repositoryID: 2}, + "relative-path-1": {repositoryID: 1, replicaPath: "relative-path-1"}, + "relative-path-2": {repositoryID: 2, replicaPath: "relative-path-2"}, }, "virtual-storage-2": { - "relative-path-1": {repositoryID: 3}, + "relative-path-1": {repositoryID: 3, replicaPath: "relative-path-1"}, }, }, storageState{ @@ -814,11 +817,11 @@ func testRepositoryStore(t *testing.T, newStore repositoryStoreFactory) { requireState(t, ctx, virtualStorageState{ "virtual-storage-1": { - "relative-path-1": {repositoryID: 1}, - "relative-path-2": {repositoryID: 2}, + "relative-path-1": {repositoryID: 1, replicaPath: "relative-path-1"}, + "relative-path-2": {repositoryID: 2, replicaPath: "relative-path-2"}, }, "virtual-storage-2": { - "relative-path-1": {repositoryID: 3}, + "relative-path-1": {repositoryID: 3, replicaPath: "relative-path-1"}, }, }, storageState{ @@ -859,8 +862,8 @@ func testRepositoryStore(t *testing.T, newStore repositoryStoreFactory) { requireState(t, ctx, virtualStorageState{ "virtual-storage-1": { - "renamed-all": repositoryRecord{repositoryID: 1}, - "renamed-some": {repositoryID: 2}, + "renamed-all": {repositoryID: 1, replicaPath: "renamed-all"}, + "renamed-some": {repositoryID: 2, replicaPath: "renamed-some"}, }, }, storageState{ @@ -882,8 +885,8 @@ func testRepositoryStore(t *testing.T, newStore repositoryStoreFactory) { requireState(t, ctx, virtualStorageState{ "virtual-storage-1": { - "renamed-all-new": repositoryRecord{repositoryID: 1}, - "renamed-some-new": {repositoryID: 2}, + "renamed-all-new": {repositoryID: 1, replicaPath: "renamed-all-new"}, + "renamed-some-new": {repositoryID: 2, replicaPath: "renamed-some-new"}, }, }, storageState{ @@ -920,7 +923,7 @@ func testRepositoryStore(t *testing.T, newStore repositoryStoreFactory) { requireState(t, ctx, virtualStorageState{ "virtual-storage-1": { - "repository-1": {repositoryID: 1}, + "repository-1": {repositoryID: 1, replicaPath: "repository-1"}, }, }, storageState{ @@ -954,7 +957,7 @@ func testRepositoryStore(t *testing.T, newStore repositoryStoreFactory) { requireState(t, ctx, virtualStorageState{ "virtual-storage-1": { - "repository-1": {repositoryID: 1}, + "repository-1": {repositoryID: 1, replicaPath: "repository-1"}, }, }, storageState{ @@ -1010,7 +1013,7 @@ func testRepositoryStore(t *testing.T, newStore repositoryStoreFactory) { requireState(t, ctx, virtualStorageState{ "virtual-storage-1": { - "repository-1": {repositoryID: 1}, + "repository-1": {repositoryID: 1, replicaPath: "repository-1"}, }, }, storageState{ |