diff options
author | Karthik Nayak <knayak@gitlab.com> | 2023-02-03 14:41:08 +0300 |
---|---|---|
committer | Karthik Nayak <knayak@gitlab.com> | 2023-02-15 17:48:24 +0300 |
commit | e4084894d8d74053dcdc97834d902f68a52bb3a4 (patch) | |
tree | e70b36c58411fc5f9c6e6140ff517e69bbcf91a2 /internal | |
parent | 9b1bb2480275c22dd2157e08a2ec2f7db835657b (diff) |
gitaly: Add `deleteKey` operation to `TransactionManager`
When we apply an operation from the write-ahead log, we also want to
remove that entry from the log. Before we add this logic, it is
necessary that `TransactionManager` supports deletion.
This commit modifies the `databaseTransaction` interface to add a
`Delete` function and also adds a `deleteKey` function to the
`TransactionManager`.
Diffstat (limited to 'internal')
-rw-r--r-- | internal/gitaly/database.go | 9 | ||||
-rw-r--r-- | internal/gitaly/transaction_manager.go | 11 |
2 files changed, 19 insertions, 1 deletions
diff --git a/internal/gitaly/database.go b/internal/gitaly/database.go index 2015de710..b2b1bb040 100644 --- a/internal/gitaly/database.go +++ b/internal/gitaly/database.go @@ -31,16 +31,22 @@ func (db databaseAdapter) NewWriteBatch() writeBatch { return db.DB.NewWriteBatch() } -// NewWriteBatch calls badger.*DB.View. Refer to Badger's documentation for details. +// View calls badger.*DB.View. Refer to Badger's documentation for details. func (db databaseAdapter) View(handler func(databaseTransaction) error) error { return db.DB.View(func(txn *badger.Txn) error { return handler(txn) }) } +// Update calls badger.*DB.View. Refer to Badger's documentation for details. +func (db databaseAdapter) Update(handler func(databaseTransaction) error) error { + return db.DB.Update(func(txn *badger.Txn) error { return handler(txn) }) +} + // database is the Badger.DB interface used by TransactionManager. Refer to Badger's documentation // for details. type database interface { NewWriteBatch() writeBatch View(func(databaseTransaction) error) error + Update(func(databaseTransaction) error) error } // writeBatch is the interface of Badger.WriteBatch used by TransactionManager. Refer to Badger's @@ -55,5 +61,6 @@ type writeBatch interface { // documentation for details type databaseTransaction interface { Get([]byte) (*badger.Item, error) + Delete([]byte) error NewIterator(badger.IteratorOptions) *badger.Iterator } diff --git a/internal/gitaly/transaction_manager.go b/internal/gitaly/transaction_manager.go index c9c89bf81..7603dc3aa 100644 --- a/internal/gitaly/transaction_manager.go +++ b/internal/gitaly/transaction_manager.go @@ -514,6 +514,17 @@ func (mgr *TransactionManager) readKey(key []byte, destination proto.Message) er }) } +// deleteKey deletes a key from the database. +func (mgr *TransactionManager) deleteKey(key []byte) error { + return mgr.db.Update(func(txn databaseTransaction) error { + if err := txn.Delete(key); err != nil { + return fmt.Errorf("delete: %w", err) + } + + return nil + }) +} + // getRepositoryID returns a repository's ID. The ID should never change as it is used in the database // keys. Gitaly does not have a permanent ID to use yet so the repository's storage name and relative // path are used as a composite key. |