From bbe065e8dda522d97b2d1d9263bf5851261147eb Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Fri, 26 Feb 2021 13:10:51 +0530 Subject: [PATCH 1/3] fix multiple schema counter test --- graphql/admin/admin.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/graphql/admin/admin.go b/graphql/admin/admin.go index fab9fda5615..cb17882be03 100644 --- a/graphql/admin/admin.go +++ b/graphql/admin/admin.go @@ -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 { @@ -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) @@ -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. @@ -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 } @@ -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) From f3e01384394328d24aa7fbe7630d67148fae9023 Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Fri, 26 Feb 2021 15:51:21 +0530 Subject: [PATCH 2/3] address abhimanyu's comments --- graphql/admin/admin.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graphql/admin/admin.go b/graphql/admin/admin.go index f453c7822e4..60a82ce873b 100644 --- a/graphql/admin/admin.go +++ b/graphql/admin/admin.go @@ -576,12 +576,12 @@ func newAdminResolver( 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) + glog.Infof("Skipping in-memory GraphQL schema update, it will be lazy-loaded later.") return } //update this schema in both admin and graphql server - newSchema.loaded = currentSchema.loaded + newSchema.loaded = true server.schema[ns] = newSchema server.resetSchema(ns, gqlSchema) From 24b6aee48ebc711e2ea6df6b4adb19af8b796eed Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Fri, 26 Feb 2021 15:52:47 +0530 Subject: [PATCH 3/3] clean code --- graphql/admin/admin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphql/admin/admin.go b/graphql/admin/admin.go index 60a82ce873b..7f665a6c0af 100644 --- a/graphql/admin/admin.go +++ b/graphql/admin/admin.go @@ -580,7 +580,7 @@ func newAdminResolver( return } - //update this schema in both admin and graphql server + // update this schema in both admin and graphql server newSchema.loaded = true server.schema[ns] = newSchema server.resetSchema(ns, gqlSchema)