-
-
Notifications
You must be signed in to change notification settings - Fork 584
Invalidate all sessions' db state for drop database
#5556
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
Changes from all commits
23f1ffe
242ae97
4c63da2
f39524e
00af2c5
cc45562
37c5ca6
ed4e3c3
224d258
f191745
fe1a824
5e416eb
471f755
e4155d9
21ce51f
d8c3187
8e6cde6
f4b265e
3463860
b0fc1aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ import ( | |
| "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions" | ||
| "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dprocedures" | ||
| "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" | ||
| "github.com/dolthub/dolt/go/libraries/doltcore/sqlserver" | ||
| "github.com/dolthub/dolt/go/libraries/doltcore/table/editor" | ||
| "github.com/dolthub/dolt/go/libraries/utils/filesys" | ||
| "github.com/dolthub/dolt/go/store/types" | ||
|
|
@@ -109,6 +110,13 @@ func NewDoltDatabaseProviderWithDatabases(defaultBranch string, fs filesys.Files | |
| externalProcedures.Register(esp) | ||
| } | ||
|
|
||
| // If the specified |fs| is an in mem file system, default to using the InMemDoltDB dbFactoryUrl so that all | ||
| // databases are created with the same file system type. | ||
| dbFactoryUrl := doltdb.LocalDirDoltDB | ||
| if _, ok := fs.(*filesys.InMemFS); ok { | ||
| dbFactoryUrl = doltdb.InMemDoltDB | ||
| } | ||
|
|
||
| return DoltDatabaseProvider{ | ||
| dbLocations: dbLocations, | ||
| databases: dbs, | ||
|
|
@@ -117,7 +125,7 @@ func NewDoltDatabaseProviderWithDatabases(defaultBranch string, fs filesys.Files | |
| mu: &sync.RWMutex{}, | ||
| fs: fs, | ||
| defaultBranch: defaultBranch, | ||
| dbFactoryUrl: doltdb.LocalDirDoltDB, | ||
| dbFactoryUrl: dbFactoryUrl, | ||
| InitDatabaseHook: ConfigureReplicationDatabaseHook, | ||
| isStandby: new(bool), | ||
| }, nil | ||
|
|
@@ -698,6 +706,35 @@ func (p DoltDatabaseProvider) DropDatabase(ctx *sql.Context, name string) error | |
| } | ||
|
|
||
| delete(p.databases, dbKey) | ||
|
|
||
| return p.invalidateDbStateInAllSessions(ctx, name) | ||
| } | ||
|
|
||
| // invalidateDbStateInAllSessions removes the db state for this database from every session. This is necessary when a | ||
| // database is dropped, so that other sessions don't use stale db state. | ||
| func (p DoltDatabaseProvider) invalidateDbStateInAllSessions(ctx *sql.Context, name string) error { | ||
| runningServer := sqlserver.GetRunningServer() | ||
| if runningServer != nil { | ||
| sessionManager := runningServer.SessionManager() | ||
| err := sessionManager.Iter(func(session sql.Session) (bool, error) { | ||
| dsess, ok := session.(*dsess.DoltSession) | ||
| if !ok { | ||
| return false, fmt.Errorf("unexpected session type: %T", session) | ||
| } | ||
|
|
||
| // We need to invalidate this database state for EVERY session, even if other sessions aren't actively | ||
| // using this database, since they could still reference it with a db-qualified table name. | ||
| err := dsess.RemoveDbState(ctx, name) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is all a bit crunchy. Probably fine to check in for now, but it seems like this is a sign of missing abstractions on the GMS side. Historically the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Totally agree. I briefly thought about pushing some of this down to SessionManager (seems appropriate), but the state is at the Dolt layer of course, so it needed a callback hook and felt like the scope was increasing. You're right that it definitely smells like the abstraction is not ideal here. |
||
| if err != nil { | ||
| return true, err | ||
| } | ||
| return false, nil | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This global is super spooky! Can we thread the server through when we construct the database provider for the engine? Definitely not related to this PR per se, but seeing this global makes me want to immediately go try to remove it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking a look! Yeah... looks like we could change
sqlengine.goandserver.goa little bit to set the MySQL server directly intoDoltDatabaseProviderso that it doesn't have to reach into that global var. I'll push a commit with that and we can see how it looks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well... this turned out to be a little messier than I was expecting... It looks like we're always using
DoltDatabaseProvideras a struct for some reason, and not as a pointer to a struct. TheDoltDatabaseProviderstruct gets created when we create the engine and then passed (as a copy) into GMS. After that, thesqlEngineis instantiated and we can start the sql-server at which point we get the server reference that we want to set in the provider, but we can't change the provider registered in GMS, because a copy was passed in, and we don't have a reference to that memory.I'm happy to change
DoltDatabaseProviderto be used as a pointer (seems like a good change to make for several reasons), but it feels like that might be cleaner in a separate PR since it'll be more than just a couple real quick changes like I thought this was going to be.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation and investigating this. I agree this doesn't need to be addressed here :).