-
Notifications
You must be signed in to change notification settings - Fork 103
[sql-24] firewalldb: thread contexts through for privacy mapper interfaces #1002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+349
−327
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7ce36d7
multi: thread contexts through privacy map interfaces
ellemouton 197ee3b
firewalldb: thread context to PrivMap NewPair
ellemouton 7e8e4a9
firewalldb: thread context to PseudoToReal
ellemouton 5b31f16
firewalldb: thread context to RealToPseudo
ellemouton ef93611
firewalldb: thread contexts to FetchAllPairs
ellemouton 62723bd
firewalldb: use DBExecutor for PrivacyMapDB
ellemouton a395cb9
firewaldb: single implementation of BBolt DBExecutor
ellemouton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package firewalldb | ||
|
||
import ( | ||
"context" | ||
|
||
"go.etcd.io/bbolt" | ||
) | ||
|
||
// kvdbExecutor is a concrete implementation of the DBExecutor interface that | ||
// uses a bbolt database as its backing store. | ||
type kvdbExecutor[T any] struct { | ||
db *bbolt.DB | ||
wrapTx func(tx *bbolt.Tx) T | ||
} | ||
|
||
// Update opens a database read/write transaction and executes the function f | ||
// with the transaction passed as a parameter. After f exits, if f did not | ||
// error, the transaction is committed. Otherwise, if f did error, the | ||
// transaction is rolled back. If the rollback fails, the original error | ||
// returned by f is still returned. If the commit fails, the commit error is | ||
// returned. | ||
// | ||
// NOTE: this is part of the DBExecutor interface. | ||
func (e *kvdbExecutor[T]) Update(ctx context.Context, | ||
fn func(ctx context.Context, tx T) error) error { | ||
|
||
return e.db.Update(func(tx *bbolt.Tx) error { | ||
return fn(ctx, e.wrapTx(tx)) | ||
}) | ||
} | ||
|
||
// View opens a database read transaction and executes the function f with the | ||
// transaction passed as a parameter. After f exits, the transaction is rolled | ||
// back. If f errors, its error is returned, not a rollback error (if any | ||
// occur). | ||
// | ||
// NOTE: this is part of the DBExecutor interface. | ||
func (e *kvdbExecutor[T]) View(ctx context.Context, | ||
fn func(ctx context.Context, tx T) error) error { | ||
|
||
return e.db.View(func(tx *bbolt.Tx) error { | ||
return fn(ctx, e.wrapTx(tx)) | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.