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

Use system database when retrieving routing table #138

Merged
merged 1 commit into from
Aug 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions neo4j/internal/bolt/bolt4.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,13 +618,19 @@ func (b *bolt4) GetRoutingTable(database string, context map[string]string) (*db
return nil, err
}

// The query should run in system database, preserve current setting and restore it when
// done.
originalDatabaseName := b.databaseName
b.databaseName = "system"

Choose a reason for hiding this comment

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

Shouldn't this be the passed in variable database?

The routing table will be different for each database, so I don't think just system is the right call here. I guess we need to something like:

b.databaseName = database with the added deferred func to restore the previous one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

b.databaseName is the database that is used to execute within, there is a parameter to getRoutingTable that is set to database, that is we query for routing for "database" in "system"
It would be great if you could verify it with your setup. I'm working on another patch to include in the release.

defer func() { b.databaseName = originalDatabaseName }()

// Query for the users default database or a specific database
const (
queryDefault = "CALL dbms.routing.getRoutingTable($context)"
queryDatabase = "CALL dbms.routing.getRoutingTable($context, $db)"
)
query := queryDefault
params := map[string]interface{}{"context": context}

if database != db.DefaultDatabase {
query = queryDatabase
params["db"] = database
Expand All @@ -634,7 +640,6 @@ func (b *bolt4) GetRoutingTable(database string, context map[string]string) (*db
if err != nil {
return nil, err
}

rec, _, err := b.Next(stream.Handle)
if err != nil {
return nil, err
Expand All @@ -649,7 +654,6 @@ func (b *bolt4) GetRoutingTable(database string, context map[string]string) (*db
if table == nil {
return nil, errors.New("Unable to parse routing table")
}

return table, nil
}

Expand Down