diff options
author | Sami Hiltunen <shiltunen@gitlab.com> | 2021-07-29 18:26:06 +0300 |
---|---|---|
committer | Sami Hiltunen <shiltunen@gitlab.com> | 2021-08-02 11:45:38 +0300 |
commit | 394d5e0e78bf31f8b579e6a334380eee59488c4a (patch) | |
tree | 2e50ec9bae47dd001a0ae54c275d22c2b894d48c | |
parent | 5a0ddf78420d2889ea2b460ff5915ff78d730933 (diff) |
Only create the replica's record in SetGeneration
SetGeneration is used to set a replica's generation after it has been
replicated to. In the past, it also created a record for the repository
if it was missing one. This has been abused in the tests to create
records for the repositories while setting a desired generation for a
replica. Repository creation logic has since expanded, and the tests
should also create repositories by using CreateRepository. SetGeneration
should never create a repository record, so this commit drops the behavior
now that tests have been updated to properly create the repository records
they expect.
-rw-r--r-- | internal/praefect/coordinator_pg_test.go | 20 | ||||
-rw-r--r-- | internal/praefect/datastore/repository_store.go | 12 |
2 files changed, 17 insertions, 15 deletions
diff --git a/internal/praefect/coordinator_pg_test.go b/internal/praefect/coordinator_pg_test.go index 632398d14..1bf110d69 100644 --- a/internal/praefect/coordinator_pg_test.go +++ b/internal/praefect/coordinator_pg_test.go @@ -47,9 +47,10 @@ func TestStreamDirectorMutator_Transaction(t *testing.T) { } testcases := []struct { - desc string - primaryFails bool - nodes []node + desc string + primaryFails bool + nodes []node + expectedRequestFinalizerErrorMessage string }{ { desc: "successful vote should not create replication jobs", @@ -109,11 +110,12 @@ func TestStreamDirectorMutator_Transaction(t *testing.T) { }, }, { - desc: "secondaries should not participate when primary's generation is unknown", + desc: "write is not acknowledged if it only targets outdated nodes", nodes: []node{ - {primary: true, subtransactions: subtransactions{{vote: "foobar", shouldSucceed: true}}, shouldParticipate: true, generation: datastore.GenerationUnknown, expectedGeneration: 0}, - {shouldParticipate: false, shouldGetRepl: true, generation: datastore.GenerationUnknown, expectedGeneration: datastore.GenerationUnknown}, + {primary: true, subtransactions: subtransactions{{vote: "foobar", shouldSucceed: true}}, shouldParticipate: true, generation: datastore.GenerationUnknown, expectedGeneration: datastore.GenerationUnknown}, + {shouldParticipate: false, shouldGetRepl: false, generation: datastore.GenerationUnknown, expectedGeneration: datastore.GenerationUnknown}, }, + expectedRequestFinalizerErrorMessage: `increment generation: repository "praefect"/"/path/to/hashed/repository" not found`, }, { // All transactional RPCs are expected to cast vote if they are successful. If they don't, something is wrong @@ -284,7 +286,11 @@ func TestStreamDirectorMutator_Transaction(t *testing.T) { } err = streamParams.RequestFinalizer() - require.NoError(t, err) + if tc.expectedRequestFinalizerErrorMessage != "" { + require.EqualError(t, err, tc.expectedRequestFinalizerErrorMessage) + } else { + require.NoError(t, err) + } // Nodes that successfully committed should have their generations incremented. // Nodes that did not successfully commit or did not participate should remain on their diff --git a/internal/praefect/datastore/repository_store.go b/internal/praefect/datastore/repository_store.go index 9248e9b2a..0b53c3444 100644 --- a/internal/praefect/datastore/repository_store.go +++ b/internal/praefect/datastore/repository_store.go @@ -215,14 +215,10 @@ SELECT func (rs *PostgresRepositoryStore) SetGeneration(ctx context.Context, virtualStorage, relativePath, storage string, generation int) error { const q = ` WITH repository AS ( - INSERT INTO repositories ( - virtual_storage, - relative_path, - generation - ) VALUES ($1, $2, $4) - ON CONFLICT (virtual_storage, relative_path) DO - UPDATE SET generation = EXCLUDED.generation - WHERE COALESCE(repositories.generation, -1) < EXCLUDED.generation + UPDATE repositories SET generation = $4 + WHERE virtual_storage = $1 + AND relative_path = $2 + AND COALESCE(repositories.generation, -1) < $4 ) INSERT INTO storage_repositories ( |