@@ -30,6 +30,7 @@ import (
30
30
"net/url"
31
31
"os"
32
32
"os/signal"
33
+ "strconv"
33
34
"strings"
34
35
"sync/atomic"
35
36
"syscall"
@@ -462,14 +463,23 @@ func setupServer(closer *z.Closer) {
462
463
// Implementation for server exit:
463
464
// The global epoch is set to maxUint64 while exiting the server.
464
465
// By using this information polling goroutine terminates the subscription.
465
- globalEpoch := uint64 (0 )
466
+ globalEpoch := make (map [uint64 ]* uint64 )
467
+ e := new (uint64 )
468
+ atomic .StoreUint64 (e , 0 )
469
+ globalEpoch [x .GalaxyNamespace ] = e
466
470
var mainServer web.IServeGraphQL
467
471
var gqlHealthStore * admin.GraphQLHealthStore
468
472
// Do not use := notation here because adminServer is a global variable.
469
- mainServer , adminServer , gqlHealthStore = admin .NewServers (introspection , & globalEpoch , closer )
470
- baseMux .Handle ("/graphql" , mainServer .HTTPHandler ())
471
- baseMux .HandleFunc ("/probe/graphql" , func (w http.ResponseWriter ,
472
- r * http.Request ) {
473
+ mainServer , adminServer , gqlHealthStore = admin .NewServers (introspection ,
474
+ globalEpoch , closer )
475
+ baseMux .HandleFunc ("/graphql" , func (w http.ResponseWriter , r * http.Request ) {
476
+ namespace := x .ExtractNamespaceHTTP (r )
477
+ r .Header .Set ("resolver" , strconv .FormatUint (namespace , 10 ))
478
+ admin .LazyLoadSchema (namespace )
479
+ mainServer .HTTPHandler ().ServeHTTP (w , r )
480
+ })
481
+
482
+ baseMux .HandleFunc ("/probe/graphql" , func (w http.ResponseWriter , r * http.Request ) {
473
483
healthStatus := gqlHealthStore .GetHealth ()
474
484
httpStatusCode := http .StatusOK
475
485
if ! healthStatus .Healthy {
@@ -478,14 +488,25 @@ func setupServer(closer *z.Closer) {
478
488
w .Header ().Set ("Content-Type" , "application/json" )
479
489
x .AddCorsHeaders (w )
480
490
w .WriteHeader (httpStatusCode )
491
+ e = globalEpoch [x .ExtractNamespaceHTTP (r )]
492
+ var counter uint64
493
+ if e != nil {
494
+ counter = atomic .LoadUint64 (e )
495
+ }
481
496
x .Check2 (w .Write ([]byte (fmt .Sprintf (`{"status":"%s","schemaUpdateCounter":%d}` ,
482
- healthStatus .StatusMsg , atomic .LoadUint64 (& globalEpoch )))))
497
+ healthStatus .StatusMsg , counter ))))
498
+ })
499
+ baseMux .HandleFunc ("/admin" , func (w http.ResponseWriter , r * http.Request ) {
500
+ r .Header .Set ("resolver" , "0" )
501
+ // We don't need to load the schema for all the admin operations.
502
+ // Only a few like getUser, queryGroup require this. So, this can be optimized.
503
+ admin .LazyLoadSchema (x .ExtractNamespaceHTTP (r ))
504
+ allowedMethodsHandler (allowedMethods {
505
+ http .MethodGet : true ,
506
+ http .MethodPost : true ,
507
+ http .MethodOptions : true ,
508
+ }, adminAuthHandler (adminServer .HTTPHandler ())).ServeHTTP (w , r )
483
509
})
484
- baseMux .Handle ("/admin" , allowedMethodsHandler (allowedMethods {
485
- http .MethodGet : true ,
486
- http .MethodPost : true ,
487
- http .MethodOptions : true ,
488
- }, adminAuthHandler (adminServer .HTTPHandler ())))
489
510
490
511
baseMux .Handle ("/admin/schema" , adminAuthHandler (http .HandlerFunc (func (
491
512
w http.ResponseWriter ,
@@ -559,7 +580,9 @@ func setupServer(closer *z.Closer) {
559
580
defer admin .ServerCloser .Done ()
560
581
561
582
<- admin .ServerCloser .HasBeenClosed ()
562
- atomic .StoreUint64 (& globalEpoch , math .MaxUint64 )
583
+ // TODO - Verify why do we do this and does it have to be done for all namespaces.
584
+ e = globalEpoch [x .GalaxyNamespace ]
585
+ atomic .StoreUint64 (e , math .MaxUint64 )
563
586
564
587
// Stops grpc/http servers; Already accepted connections are not closed.
565
588
if err := grpcListener .Close (); err != nil {
0 commit comments