diff options
author | Sami Hiltunen <shiltunen@gitlab.com> | 2021-09-09 11:13:12 +0300 |
---|---|---|
committer | Sami Hiltunen <shiltunen@gitlab.com> | 2021-09-09 11:13:12 +0300 |
commit | d1a878846a856fae5c0b9e08cda9d87dce0f7072 (patch) | |
tree | d98734dc2b4a6e0fe0702eb0a32ac0d8d65d6209 | |
parent | 8a08db5bdc19de6417f887807f553f1f21bda33c (diff) | |
parent | 2e30806ce11682b803552a04c80a44de988c1eca (diff) |
Merge branch 'smh-fs-id-14-1' into '14-1-stable'
Derive virtual storage's filesystem id from its name (14.1)
See merge request gitlab-org/gitaly!3835
-rw-r--r-- | internal/praefect/server_test.go | 38 | ||||
-rw-r--r-- | internal/praefect/service/server/info.go | 21 |
2 files changed, 57 insertions, 2 deletions
diff --git a/internal/praefect/server_test.go b/internal/praefect/server_test.go index 71812100e..ed2a9b6f7 100644 --- a/internal/praefect/server_test.go +++ b/internal/praefect/server_test.go @@ -8,6 +8,7 @@ import ( "net" "os" "path/filepath" + "sort" "strings" "sync" "testing" @@ -34,8 +35,10 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/nodes" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/nodes/tracker" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/protoregistry" + serversvc "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/service/server" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/service/transaction" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/transactions" + "gitlab.com/gitlab-org/gitaly/v14/internal/storage" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/promtest" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" @@ -122,9 +125,22 @@ func TestGitalyServerInfo(t *testing.T) { secondCfg := testcfg.Build(t, testcfg.WithStorages("praefect-internal-2")) secondCfg.SocketPath = testserver.RunGitalyServer(t, secondCfg, nil, setup.RegisterAll, testserver.WithDisablePraefect()) + require.NoError(t, storage.WriteMetadataFile(firstCfg.Storages[0].Path)) + firstMetadata, err := storage.ReadMetadataFile(firstCfg.Storages[0].Path) + require.NoError(t, err) + conf := config.Config{ VirtualStorages: []*config.VirtualStorage{ { + Name: "passthrough-filesystem-id", + Nodes: []*config.Node{ + { + Storage: firstCfg.Storages[0].Name, + Address: firstCfg.SocketPath, + }, + }, + }, + { Name: "virtual-storage", Nodes: []*config.Node{ { @@ -156,7 +172,20 @@ func TestGitalyServerInfo(t *testing.T) { ServerVersion: version.GetVersion(), GitVersion: gitVersion.String(), StorageStatuses: []*gitalypb.ServerInfoResponse_StorageStatus{ - {StorageName: conf.VirtualStorages[0].Name, Readable: true, Writeable: true, ReplicationFactor: 2}, + { + StorageName: conf.VirtualStorages[0].Name, + FilesystemId: firstMetadata.GitalyFilesystemID, + Readable: true, + Writeable: true, + ReplicationFactor: 1, + }, + { + StorageName: conf.VirtualStorages[1].Name, + FilesystemId: serversvc.DeriveFilesystemID(conf.VirtualStorages[1].Name).String(), + Readable: true, + Writeable: true, + ReplicationFactor: 2, + }, }, } @@ -165,8 +194,13 @@ func TestGitalyServerInfo(t *testing.T) { require.NoError(t, err) for _, ss := range actual.StorageStatuses { ss.FsType = "" - ss.FilesystemId = "" } + + // sort the storages by name so they match the expected + sort.Slice(actual.StorageStatuses, func(i, j int) bool { + return actual.StorageStatuses[i].StorageName < actual.StorageStatuses[j].StorageName + }) + require.True(t, proto.Equal(expected, actual), "expected: %v, got: %v", expected, actual) }) diff --git a/internal/praefect/service/server/info.go b/internal/praefect/service/server/info.go index 4650981b6..1ca09a871 100644 --- a/internal/praefect/service/server/info.go +++ b/internal/praefect/service/server/info.go @@ -4,11 +4,21 @@ import ( "context" "sync" + "github.com/google/uuid" "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc" ) +// filesystemIDNamespace is the UUID that is used as the namespace component when generating the UUIDv5 filesystem +// ID from a virtual storage's name. +var filesystemIDNamespace = uuid.MustParse("1ef1a8c6-cf52-4d0a-92a6-ca643e8bc7c5") + +// DeriveFilesystemID derives the virtual storage's filesystem ID from its name. +func DeriveFilesystemID(virtualStorage string) uuid.UUID { + return uuid.NewSHA1(filesystemIDNamespace, []byte(virtualStorage)) +} + // ServerInfo sends ServerInfoRequest to all of a praefect server's internal gitaly nodes and aggregates the results into // a response func (s *Server) ServerInfo(ctx context.Context, in *gitalypb.ServerInfoRequest) (*gitalypb.ServerInfoResponse, error) { @@ -74,6 +84,17 @@ func (s *Server) ServerInfo(ctx context.Context, in *gitalypb.ServerInfoRequest) storageStatuses[i].StorageName = virtualStorage storageStatuses[i].Writeable = storageStatus.Writeable storageStatuses[i].ReplicationFactor = uint32(len(storages)) + + // Rails tests configure Praefect in front of tests that drive the direct git access with Rugged patches. + // This is not a real world scenario and would not work. The tests only configure a single Gitaly node, + // so as a workaround for these tests, we only override the filesystem id if we have more than one Gitaly node. + // The filesystem ID and this workaround can be removed once the Rugged patches and NFS are gone in 15.0. + if len(storages) > 1 { + // Each of the Gitaly nodes have a different filesystem ID they've generated. To have a stable filesystem + // ID for a given virtual storage, the filesystem ID is generated from the virtual storage's name. + storageStatuses[i].FilesystemId = DeriveFilesystemID(storageStatus.StorageName).String() + } + break } } |