diff options
author | Sami Hiltunen <shiltunen@gitlab.com> | 2023-10-11 17:15:25 +0300 |
---|---|---|
committer | Sami Hiltunen <shiltunen@gitlab.com> | 2023-10-31 12:19:16 +0300 |
commit | d4e1bbd89f8bf7b5ab773481d52981a5c281b22f (patch) | |
tree | 406abb988093016cf9c64e528cb6a9ef2298611e | |
parent | 5867f71c734a055e3af41e237ce19f992dd68120 (diff) |
Take in storage and relative path instead of Repository in PartitionManager
PartitionManager is currently taking in a storage.Repository to determine
the target repository of a transaction. This worked reasonably for a single
repository. It's not as convenient as an interface when a transaction may
span multiple repositories. Each of the repositories must be in the same
storage, so storage should be given as a parameter only once. The quarantine
parameters may also be set in Repository yet they are completely ignored
by the transaction code. Change the interface to instead take in a storage
name and the relative path of the repository directly. This removes the
unnecessary fields inside Repository from the interface. When we start
supporting multi-repo transactions, we'll only take in the storage name
once and can take in the other relative paths a simple slice.
-rw-r--r-- | internal/gitaly/storage/storagemgr/middleware.go | 2 | ||||
-rw-r--r-- | internal/gitaly/storage/storagemgr/partition_manager.go | 10 | ||||
-rw-r--r-- | internal/gitaly/storage/storagemgr/partition_manager_test.go | 7 |
3 files changed, 9 insertions, 10 deletions
diff --git a/internal/gitaly/storage/storagemgr/middleware.go b/internal/gitaly/storage/storagemgr/middleware.go index 101376463..8a3d2f66b 100644 --- a/internal/gitaly/storage/storagemgr/middleware.go +++ b/internal/gitaly/storage/storagemgr/middleware.go @@ -249,7 +249,7 @@ func transactionalizeRequest(ctx context.Context, logger log.Logger, txRegistry return transactionalizedRequest{}, err } - tx, err := mgr.Begin(ctx, repo, TransactionOptions{ReadOnly: methodInfo.Operation == protoregistry.OpAccessor}) + tx, err := mgr.Begin(ctx, repo.StorageName, repo.RelativePath, TransactionOptions{ReadOnly: methodInfo.Operation == protoregistry.OpAccessor}) if err != nil { return transactionalizedRequest{}, fmt.Errorf("begin transaction: %w", err) } diff --git a/internal/gitaly/storage/storagemgr/partition_manager.go b/internal/gitaly/storage/storagemgr/partition_manager.go index 4349d5a8d..1491f36ac 100644 --- a/internal/gitaly/storage/storagemgr/partition_manager.go +++ b/internal/gitaly/storage/storagemgr/partition_manager.go @@ -283,13 +283,15 @@ func stagingDirectoryPath(storagePath string) string { // Begin gets the TransactionManager for the specified repository and starts a transaction. If a // TransactionManager is not already running, a new one is created and used. The partition tracks // the number of pending transactions and this counter gets incremented when Begin is invoked. -func (pm *PartitionManager) Begin(ctx context.Context, repo storage.Repository, opts TransactionOptions) (*finalizableTransaction, error) { - storageMgr, ok := pm.storages[repo.GetStorageName()] +// +// storageName and relativePath specify the target repository to begin a transaction against. +func (pm *PartitionManager) Begin(ctx context.Context, storageName, relativePath string, opts TransactionOptions) (*finalizableTransaction, error) { + storageMgr, ok := pm.storages[storageName] if !ok { - return nil, structerr.NewNotFound("unknown storage: %q", repo.GetStorageName()) + return nil, structerr.NewNotFound("unknown storage: %q", storageName) } - relativePath, err := storage.ValidateRelativePath(storageMgr.path, repo.GetRelativePath()) + relativePath, err := storage.ValidateRelativePath(storageMgr.path, relativePath) if err != nil { return nil, structerr.NewInvalidArgument("validate relative path: %w", err) } diff --git a/internal/gitaly/storage/storagemgr/partition_manager_test.go b/internal/gitaly/storage/storagemgr/partition_manager_test.go index d13a7f703..be8f8d6c0 100644 --- a/internal/gitaly/storage/storagemgr/partition_manager_test.go +++ b/internal/gitaly/storage/storagemgr/partition_manager_test.go @@ -717,7 +717,7 @@ func TestPartitionManager(t *testing.T) { beginCtx = step.ctx } - txn, err := partitionManager.Begin(beginCtx, step.repo, TransactionOptions{}) + txn, err := partitionManager.Begin(beginCtx, step.repo.GetStorageName(), step.repo.GetRelativePath(), TransactionOptions{}) require.Equal(t, step.expectedError, err) blockOnPartitionClosing(t, partitionManager) @@ -811,10 +811,7 @@ func TestPartitionManager_concurrentClose(t *testing.T) { require.NoError(t, err) defer partitionManager.Close() - tx, err := partitionManager.Begin(ctx, &gitalypb.Repository{ - StorageName: cfg.Storages[0].Name, - RelativePath: "relative-path", - }, TransactionOptions{}) + tx, err := partitionManager.Begin(ctx, cfg.Storages[0].Name, "relative-path", TransactionOptions{}) require.NoError(t, err) start := make(chan struct{}) |