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

Allow users to update schema without restarting the connection #259

Closed

Conversation

rayman1104
Copy link

What has been done? Why? What problem is being solved?

If new space was created while the program is running, the schema is not updated and hence it's impossible to make queries to new spaces.

Right now if one wants to update the schema, they have to restart the connection completely, which is suboptimal. Making this loadSchema method public would allow them to trigger it manually at least. But of course in the future would be nice to update the schema automatically by the response from tarantool, as it's described in #7.

Copy link
Collaborator

@oleg-jukovec oleg-jukovec left a comment

Choose a reason for hiding this comment

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

Thank you for the pull request! We need tests for the pull request, since this functionality will be available in the public api.

If you are blocked by the issue, you could manually update the schema right now with a workaround:

schema := new(tarantool.Schema)
schema.SpacesById = make(map[uint32]*tarantool.Space)
schema.Spaces = make(map[string]*tarantool.Space)

// Reload spaces.
var spaces []*tarantool.Space
err = conn.SelectTyped(vspaceSpId, 0, 0, maxSchemas, IterAll, []interface{}{}, &spaces)
if err != nil {
	return err
}
for _, space := range spaces {
	schema.SpacesById[space.Id] = space
	schema.Spaces[space.Name] = space
}

// Reload indexes.
var indexes []*Index
err = conn.SelectTyped(vindexSpId, 0, 0, maxSchemas, IterAll, []interface{}{}, &indexes)
if err != nil {
	return err
}
for _, index := range indexes {
	schema.SpacesById[index.SpaceId].IndexesById[index.Id] = index
	schema.SpacesById[index.SpaceId].Indexes[index.Name] = index
}
conn.OverrideSchema(schema) // or conn.Schema = schema

But be careful, this is not safe for active requests:

#218
35939df

Therefore, I will be able to merge this pull request only after #258 .

@kokizzu
Copy link

kokizzu commented Jan 14, 2023

on code above what is vspaceSpId?

@oleg-jukovec
Copy link
Collaborator

on code above what is vspaceSpId?

281

vindexSpId:

289

You could execute in Tarantool:

tarantool> box.space._space:select()
---
...
  - [281, 1, '_vspace', 'sysview', 0, {}, [{'name': 'id', 'type': 'unsigned'}, {'name': 'owner',
        'type': 'unsigned'}, {'name': 'name', 'type': 'string'}, {'name': 'engine',
        'type': 'string'}, {'name': 'field_count', 'type': 'unsigned'}, {'name': 'flags',
        'type': 'map'}, {'name': 'format', 'type': 'array'}]]
...
  - [289, 1, '_vindex', 'sysview', 0, {}, [{'name': 'id', 'type': 'unsigned'}, {'name': 'iid',
        'type': 'unsigned'}, {'name': 'name', 'type': 'string'}, {'name': 'type',
        'type': 'string'}, {'name': 'opts', 'type': 'map'}, {'name': 'parts', 'type': 'array'}]]
...

@rayman1104
Copy link
Author

@oleg-jukovec can we merge it now since #258 is merged?

@oleg-jukovec
Copy link
Collaborator

@oleg-jukovec can we merge it now since #258 is merged?

First you need to add tests for the public API. At least you need to add an integration test with Tarantool to tarantool_test.go.

@oleg-jukovec
Copy link
Collaborator

The pull request closed due to inactivity. You can re-open it with tests for the public API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants