diff options
author | Karthik Nayak <knayak@gitlab.com> | 2023-05-09 10:40:19 +0300 |
---|---|---|
committer | Karthik Nayak <knayak@gitlab.com> | 2023-05-30 10:25:32 +0300 |
commit | 9595f59cafadc8f6b36d10d48baa3d264df52a8a (patch) | |
tree | 8d8e3917f479583dc6c949492af9f58f868a6194 | |
parent | 58851fe18b0291ed7b11c8821c7ae548c2a96337 (diff) |
gitaly: Remove the `repositoryHook`
We use the `repositoryHook` to add a hook before the `ResolveRevision`
function is called. In reality the use-case is to add a hook before the
log is stored into the database.
In `1ff6dcd1` we introduced a framework for panics in the hooks. Let's
use this to have a `beforeStoreLogEntry` hook instead and remove the
`ResolveRevision` hook. This is more inline with what we actually want
to test.
Overall, this is done so we can remove the `repositoryHook` and remove
the `repository` interface altogether.
-rw-r--r-- | internal/gitaly/transaction_manager_hook_test.go | 31 | ||||
-rw-r--r-- | internal/gitaly/transaction_manager_test.go | 4 |
2 files changed, 9 insertions, 26 deletions
diff --git a/internal/gitaly/transaction_manager_hook_test.go b/internal/gitaly/transaction_manager_hook_test.go index 3ecee4e14..e529ea8b4 100644 --- a/internal/gitaly/transaction_manager_hook_test.go +++ b/internal/gitaly/transaction_manager_hook_test.go @@ -1,7 +1,6 @@ package gitaly import ( - "context" "regexp" "runtime" "strings" @@ -9,7 +8,6 @@ import ( "github.com/dgraph-io/badger/v3" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/v16/internal/git" ) // hookFunc is a function that is executed at a specific point. It gets a hookContext that allows it to @@ -31,8 +29,8 @@ type hookContext struct { type hooks struct { // beforeReadLogEntry is invoked before a log entry is read from the database. beforeReadLogEntry hookFunc - // beforeResolveRevision is invoked before ResolveRevision is invoked. - beforeResolveRevision hookFunc + // beforeStoreLogEntry is invoked before the log entry is stored to the database. + beforeStoreLogEntry hookFunc // beforeDeferredStop is invoked before the deferred Stop is invoked in Run. beforeDeferredStop hookFunc // beforeDeleteLogEntry is invoked before a log entry is deleted from the database. @@ -66,26 +64,6 @@ func installHooks(tb testing.TB, transactionManager *TransactionManager, databas hooks: hooks, hookContext: hookContext, } - - transactionManager.repository = repositoryHook{ - repository: transactionManager.repository, - hookContext: hookContext, - hooks: hooks, - } -} - -type repositoryHook struct { - repository - hookContext - hooks -} - -func (hook repositoryHook) ResolveRevision(ctx context.Context, revision git.Revision) (git.ObjectID, error) { - if hook.beforeResolveRevision != nil { - hook.hooks.beforeResolveRevision(hook.hookContext) - } - - return hook.repository.ResolveRevision(ctx, revision) } type databaseHook struct { @@ -165,6 +143,11 @@ func (hook writeBatchHook) Set(key []byte, value []byte) error { if regexLogIndex.Match(key) && hook.hooks.beforeStoreAppliedLogIndex != nil { hook.hooks.beforeStoreAppliedLogIndex(hook.hookContext) } + + if regexLogEntry.Match(key) && hook.hooks.beforeStoreLogEntry != nil { + hook.hooks.beforeStoreLogEntry(hook.hookContext) + } + return hook.writeBatch.Set(key, value) } diff --git a/internal/gitaly/transaction_manager_test.go b/internal/gitaly/transaction_manager_test.go index 7c277f3b2..db1c8eb20 100644 --- a/internal/gitaly/transaction_manager_test.go +++ b/internal/gitaly/transaction_manager_test.go @@ -2911,8 +2911,8 @@ func TestTransactionManager(t *testing.T) { transactionManager = NewTransactionManager(database, storagePath, relativePath, stagingDir, setup.RepositoryFactory, setup.CommandFactory, noopTransactionFinalizer) installHooks(t, transactionManager, database, hooks{ - beforeReadLogEntry: step.Hooks.BeforeApplyLogEntry, - beforeResolveRevision: step.Hooks.BeforeAppendLogEntry, + beforeReadLogEntry: step.Hooks.BeforeApplyLogEntry, + beforeStoreLogEntry: step.Hooks.BeforeAppendLogEntry, beforeDeferredStop: func(hookContext) { if step.Hooks.WaitForTransactionsWhenStopping { inflightTransactions.Wait() |