Skip to content
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

[no-release-notes] go: sqle: DatabaseProvider: Fix double-creation of push-on-write commit hooks in registerNewDatabase. #8830

Merged
merged 2 commits into from
Feb 11, 2025

Conversation

reltuk
Copy link
Contributor

@reltuk reltuk commented Feb 6, 2025

No description provided.

… push-on-write commit hooks in registerNewDatabase.
@reltuk reltuk requested a review from zachmu February 6, 2025 22:56

func (ddb *DoltDB) PrependCommitHook(ctx context.Context, hook CommitHook) *DoltDB {
ddb.db = ddb.db.SetCommitHooks(ctx, append([]CommitHook{hook}, ddb.db.PostCommitHooks()...))
func (ddb *DoltDB) PrependCommitHooks(ctx context.Context, hooks ...CommitHook) *DoltDB {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SetCommitHooks was destructive and potentially dangerous. For now, it seems easier to make hook writers coordinate on these things upstream.

return err
}
dbs, err := ApplyReplicationConfig(ctx, sql.NewBackgroundThreads(), mrEnv, cli.CliErr, db)
sdb, err := applyReadReplicationConfigToDatabase(ctx, newEnv, db)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ApplyReplicationConfig creates the commit hooks and is responsible for the transform of the dsess.SqlDatabase into a ReadOnlyDatabase if it needs to be configured as such. Here, we just need the later functionality: the other functionality is already handled (and more) by our InitDatabaseHook.

@coffeegoddd
Copy link
Contributor

@reltuk DOLT

comparing_percentages
100.000000 to 100.000000
version result total
5a6caad ok 5937457
version total_tests
5a6caad 5937457
correctness_percentage
100.0

Copy link
Member

@zachmu zachmu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

if replicationRemoteName == "" {
return nil
}
func NewConfigureReplicationDatabaseHook(bThreads *sql.BackgroundThreads) func(ctx *sql.Context, p *DoltDatabaseProvider, name string, newEnv *env.DoltEnv, _ dsess.SqlDatabase) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda hate that the hook is a func instead of an interface but I guess that's not new

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crazy this is a new file, what would uncle bob martin say

@@ -115,6 +115,22 @@ func newReplicaDatabase(ctx context.Context, name string, remoteName string, dEn
return rrd, nil
}

func applyReadReplicationConfigToDatabase(ctx context.Context, dEnv *env.DoltEnv, db dsess.SqlDatabase) (dsess.SqlDatabase, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should comment similar to the PR note here

@coffeegoddd
Copy link
Contributor

@reltuk DOLT

comparing_percentages
100.000000 to 100.000000
version result total
78bab82 ok 5937457
version total_tests
78bab82 5937457
correctness_percentage
100.0

@reltuk reltuk merged commit 209e669 into main Feb 11, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants