Skip to content
Snippets Groups Projects
Commit d1a87884 authored by Sami Hiltunen's avatar Sami Hiltunen
Browse files

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 !3835
parents 8a08db5b 2e30806c
No related branches found
No related tags found
Loading
......@@ -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,8 +125,21 @@ 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)
})
......
......@@ -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
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment