Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSami Hiltunen <shiltunen@gitlab.com>2021-09-09 11:12:38 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2021-09-09 11:12:38 +0300
commita0d69dd64f049b7bd1ccc4c9ed361a67d41c17dd (patch)
tree3add8685b956a0dfea23d701e5bc2bc61f135d2f
parent066007999b4cc5ec3749ef29d914e0b08cb5d02c (diff)
parenta889114230771cf457394b3f154eed674aace4b7 (diff)
Merge branch 'smh-fs-id-13-12' into '13-12-stable'
Derive virtual storage's filesystem id from its name (13.12) See merge request gitlab-org/gitaly!3833
-rw-r--r--internal/praefect/server_test.go38
-rw-r--r--internal/praefect/service/server/info.go21
2 files changed, 57 insertions, 2 deletions
diff --git a/internal/praefect/server_test.go b/internal/praefect/server_test.go
index b54163a36..9eba2ed4f 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"
@@ -33,8 +34,10 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/praefect/nodes"
"gitlab.com/gitlab-org/gitaly/internal/praefect/nodes/tracker"
"gitlab.com/gitlab-org/gitaly/internal/praefect/protoregistry"
+ serversvc "gitlab.com/gitlab-org/gitaly/internal/praefect/service/server"
"gitlab.com/gitlab-org/gitaly/internal/praefect/service/transaction"
"gitlab.com/gitlab-org/gitaly/internal/praefect/transactions"
+ "gitlab.com/gitlab-org/gitaly/internal/storage"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/internal/testhelper/promtest"
"gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg"
@@ -115,9 +118,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{
{
@@ -149,7 +165,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,
+ },
},
}
@@ -158,8 +187,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 b66208346..a9fa65b7d 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/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
}
}