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

fix: schema sync is broken #2843

Merged
merged 1 commit into from
Sep 26, 2024
Merged

Conversation

stuartwdouglas
Copy link
Contributor

As the sync works on module name rather than deployment when a deployment is removed it will remove any newer version of the module.

This PR changes to build the schema in the same function as the route table, so they stay in sync.

At persent this is not an atomic operation however, so there is a slight possibility for a request to see a new schema for an old route table, however this is still way better than the current situation.

@stuartwdouglas stuartwdouglas added the run-all A PR with this label will run the full set of CI jobs in the PR rather than in the merge queue label Sep 26, 2024
@stuartwdouglas stuartwdouglas requested review from matt2e and removed request for a team September 26, 2024 07:12
modulesByName := map[string]*schema.Module{}
retry := backoff.Backoff{Max: time.Second * 5}
for {
err := s.watchModuleChanges(ctx, func(response *ftlv1.PullSchemaResponse) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this being used anymore? If not we should remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used for PullSchema

return orderedModules[i].Name < orderedModules[j].Name
})
combined := &schema.Schema{Modules: orderedModules}
s.schema.Store(ftlreflect.DeepCopy(combined))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think you need the DeepCopy anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point

retry.Reset()
}
}
s.routes.Store(newRoutes)
Copy link
Collaborator

Choose a reason for hiding this comment

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

To fix the lack of atomicity we could store both in a single atomic.Value as a single struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In practice I don't think it would matter, however the lack of atomicity just feels wrong. I will move it into a single struct.

This was referenced Sep 26, 2024
@stuartwdouglas stuartwdouglas enabled auto-merge (squash) September 26, 2024 07:57
@stuartwdouglas stuartwdouglas force-pushed the stuartwdouglas/fix-schema-sync branch 2 times, most recently from 29aa19a to 737068e Compare September 26, 2024 08:46
As the sync works on module name rather than deployment when a deployment is
removed it will remove any newer version of the module.

This PR changes to build the schema in the same function as the route table,
so they stay in sync.
@stuartwdouglas stuartwdouglas merged commit b980c86 into main Sep 26, 2024
91 checks passed
@stuartwdouglas stuartwdouglas deleted the stuartwdouglas/fix-schema-sync branch September 26, 2024 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-all A PR with this label will run the full set of CI jobs in the PR rather than in the merge queue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants