diff options
author | Toon Claes <toon@gitlab.com> | 2020-12-01 15:18:14 +0300 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2020-12-01 18:23:09 +0300 |
commit | c854b74ed7ae0af2ee2a9ccc0320ebfc90bc31b1 (patch) | |
tree | 3f3f36923c40e854df678ac344888f6233c23702 /internal/praefect/replicator_test.go | |
parent | 3154e9cb4c1df03c5405e2bd8a429838ebde03f2 (diff) |
No longer compare checksums after replication
Prior to this change, the checksums of primary and replica were
calculated after completing the replication. In some cases, i.e. when
the primary did receive more updates after replication was initiated,
these checksums did not match.
This change removes the checksum calculation and comparison because it
was only added for demos in the first place. Removing this checksumming
will reduce load on the cluster.
Closes https://gitlab.com/gitlab-org/gitaly/-/issues/3110
Diffstat (limited to 'internal/praefect/replicator_test.go')
-rw-r--r-- | internal/praefect/replicator_test.go | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/internal/praefect/replicator_test.go b/internal/praefect/replicator_test.go index c186eb74f..9bfdad5c2 100644 --- a/internal/praefect/replicator_test.go +++ b/internal/praefect/replicator_test.go @@ -39,6 +39,7 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/testhelper/promtest" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "gitlab.com/gitlab-org/labkit/correlation" + "golang.org/x/sync/errgroup" "google.golang.org/grpc" "google.golang.org/grpc/health" healthpb "google.golang.org/grpc/health/grpc_health_v1" @@ -234,13 +235,8 @@ func TestReplMgr_ProcessBacklog(t *testing.T) { require.Equal(t, []string{"backup", "default"}, []string{dequeuedEvent.Job.TargetNodeStorage, dequeuedEvent.Job.SourceNodeStorage}) require.Equal(t, - []interface{}{"checksum comparison completed", "default", "correlation-id"}, - []interface{}{logEntries[2].Message, logEntries[2].Data["virtual_storage"], logEntries[2].Data[logWithCorrID]}, - ) - - require.Equal(t, []interface{}{"replication job processing finished", "default", datastore.JobStateCompleted, "correlation-id"}, - []interface{}{logEntries[3].Message, logEntries[3].Data["virtual_storage"], logEntries[3].Data["new_state"], logEntries[3].Data[logWithCorrID]}, + []interface{}{logEntries[2].Message, logEntries[2].Data["virtual_storage"], logEntries[2].Data["new_state"], logEntries[2].Data[logWithCorrID]}, ) relativeRepoPath, err := filepath.Rel(testhelper.GitlabTestStoragePath(), testRepoPath) @@ -568,9 +564,7 @@ func TestConfirmReplication(t *testing.T) { conn, err := grpc.Dial(srvSocketPath, connOpts...) require.NoError(t, err) - var replicator defaultReplicator - - equal, err := replicator.confirmChecksums(ctx, testhelper.DiscardTestLogger(t), gitalypb.NewRepositoryServiceClient(conn), gitalypb.NewRepositoryServiceClient(conn), testRepoA, testRepoB) + equal, err := confirmChecksums(ctx, testhelper.DiscardTestLogger(t), gitalypb.NewRepositoryServiceClient(conn), gitalypb.NewRepositoryServiceClient(conn), testRepoA, testRepoB) require.NoError(t, err) require.True(t, equal) @@ -578,11 +572,44 @@ func TestConfirmReplication(t *testing.T) { Message: "a commit", }) - equal, err = replicator.confirmChecksums(ctx, testhelper.DiscardTestLogger(t), gitalypb.NewRepositoryServiceClient(conn), gitalypb.NewRepositoryServiceClient(conn), testRepoA, testRepoB) + equal, err = confirmChecksums(ctx, testhelper.DiscardTestLogger(t), gitalypb.NewRepositoryServiceClient(conn), gitalypb.NewRepositoryServiceClient(conn), testRepoA, testRepoB) require.NoError(t, err) require.False(t, equal) } +func confirmChecksums(ctx context.Context, logger logrus.FieldLogger, primaryClient, replicaClient gitalypb.RepositoryServiceClient, primary, replica *gitalypb.Repository) (bool, error) { + g, gCtx := errgroup.WithContext(ctx) + + var primaryChecksum, replicaChecksum string + + g.Go(getChecksumFunc(gCtx, primaryClient, primary, &primaryChecksum)) + g.Go(getChecksumFunc(gCtx, replicaClient, replica, &replicaChecksum)) + + if err := g.Wait(); err != nil { + return false, err + } + + logger.WithFields(logrus.Fields{ + "primary_checksum": primaryChecksum, + "replica_checksum": replicaChecksum, + }).Info("checksum comparison completed") + + return primaryChecksum == replicaChecksum, nil +} + +func getChecksumFunc(ctx context.Context, client gitalypb.RepositoryServiceClient, repo *gitalypb.Repository, checksum *string) func() error { + return func() error { + primaryChecksumRes, err := client.CalculateChecksum(ctx, &gitalypb.CalculateChecksumRequest{ + Repository: repo, + }) + if err != nil { + return err + } + *checksum = primaryChecksumRes.GetChecksum() + return nil + } +} + func TestProcessBacklog_FailedJobs(t *testing.T) { backupStorageName := "backup" |