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(GraphQL): Fix flaky tests caused by multiple increments of schemaUpdateCounter. #7489

Merged
merged 4 commits into from
Feb 26, 2021
Merged
Changes from 2 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
16 changes: 12 additions & 4 deletions graphql/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ type gqlSchema struct {
Schema string `json:"schema,omitempty"`
Version uint64
GeneratedSchema string
loaded bool // This indicate whether the schema has been loaded into graphql server or not
}

type adminServer struct {
Expand Down Expand Up @@ -571,10 +572,16 @@ func newAdminResolver(

server.incrementSchemaUpdateCounter(ns)
// if the schema hasn't been loaded yet, then we don't need to load it here
if !ok {
glog.Info("Skipping in-memory GraphQL schema update, it will be lazy-loaded later.")
currentSchema, ok = server.schema[ns]
if !(ok && currentSchema.loaded) {
// this just set schema in admin server, so that next invalid badger subscription update gets rejected upfront
server.schema[ns] = newSchema
glog.Infof("Skipping in-memory GraphQL schema update, it will be lazy-loaded later.", ns)
return
}

//update this schema in both admin and graphql server
newSchema.loaded = currentSchema.loaded
server.schema[ns] = newSchema
server.resetSchema(ns, gqlSchema)

Expand Down Expand Up @@ -689,7 +696,7 @@ func (as *adminServer) initServer() {
glog.Infof("Error reading GraphQL schema: %s.", err)
continue
}

sch.loaded = true
as.schema[x.GalaxyNamespace] = sch
// adding the actual resolvers for updateGQLSchema and getGQLSchema only after server has
// current GraphQL schema, if there was any.
Expand Down Expand Up @@ -848,7 +855,7 @@ func (as *adminServer) resetSchema(ns uint64, gqlSchema schema.Schema) {
func (as *adminServer) lazyLoadSchema(namespace uint64) {
// if the schema is already in memory, no need to fetch it from disk
as.mux.RLock()
if _, ok := as.schema[namespace]; ok {
if currentSchema, ok := as.schema[namespace]; ok && currentSchema.loaded {
as.mux.RUnlock()
return
}
Expand All @@ -874,6 +881,7 @@ func (as *adminServer) lazyLoadSchema(namespace uint64) {

as.mux.Lock()
defer as.mux.Unlock()
sch.loaded = true
as.schema[namespace] = sch
as.resetSchema(namespace, generatedSchema)

Expand Down