MCPcopy
hub / github.com/dgraph-io/dgraph / setupServer

Function setupServer

dgraph/cmd/alpha/run.go:523–670  ·  view source on GitHub ↗
(closer *z.Closer, enableMcp bool)

Source from the content-addressed store, hash-verified

521}
522
523func setupServer(closer *z.Closer, enableMcp bool) {
524 go worker.RunServer(bindall) // For pb.communication.
525 laddr := "localhost"
526 if bindall {
527 laddr = "0.0.0.0"
528 }
529
530 tlsCfg, err := x.LoadServerTLSConfig(Alpha.Conf)
531 if err != nil {
532 log.Fatalf("Failed to setup TLS: %v\n", err)
533 }
534
535 httpListener, err := setupListener(laddr, httpPort())
536 if err != nil {
537 log.Fatal(err)
538 }
539
540 grpcListener, err := setupListener(laddr, grpcPort())
541 if err != nil {
542 log.Fatal(err)
543 }
544
545 baseMux := http.NewServeMux()
546 http.Handle("/", audit.AuditRequestHttp(baseMux))
547
548 http.HandleFunc("/login", loginHandler)
549 baseMux.HandleFunc("/query", queryHandler)
550 baseMux.HandleFunc("/query/", queryHandler)
551 baseMux.HandleFunc("/mutate", mutationHandler)
552 baseMux.HandleFunc("/mutate/", mutationHandler)
553 baseMux.HandleFunc("/commit", commitHandler)
554 baseMux.HandleFunc("/alter", alterHandler)
555 baseMux.HandleFunc("/health", healthCheck)
556 baseMux.HandleFunc("/state", stateHandler)
557 baseMux.HandleFunc("/debug/jemalloc", x.JemallocHandler)
558 http.DefaultServeMux.Handle("/debug/z", zpages.NewTracezHandler(zpages.NewSpanProcessor()))
559
560 // TODO: Figure out what this is for?
561 http.HandleFunc("/debug/store", storeStatsHandler)
562
563 introspection := x.Config.GraphQL.GetBool("introspection")
564
565 // Global Epoch is a lockless synchronization mechanism for graphql service.
566 // It's is just an atomic counter used by the graphql subscription to update its state.
567 // It's is used to detect the schema changes and server exit.
568 // It is also reported by /probe/graphql endpoint as the schemaUpdateCounter.
569
570 // Implementation for schema change:
571 // The global epoch is incremented when there is a schema change.
572 // Polling goroutine acquires the current epoch count as a local epoch.
573 // The local epoch count is checked against the global epoch,
574 // If there is change then we terminate the subscription.
575
576 // Implementation for server exit:
577 // The global epoch is set to maxUint64 while exiting the server.
578 // By using this information polling goroutine terminates the subscription.
579 globalEpoch := make(map[uint64]*uint64)
580 e := new(uint64)

Callers 1

runFunction · 0.85

Calls 15

HTTPHandlerMethod · 0.95
RunServerFunction · 0.92
LoadServerTLSConfigFunction · 0.92
AuditRequestHttpFunction · 0.92
NewServersFunction · 0.92
ExtractNamespaceHTTPFunction · 0.92
LazyLoadSchemaFunction · 0.92
WriteErrorResponseFunction · 0.92
SanitizedDefaultServeMuxFunction · 0.92
StartListenHttpAndHttpsFunction · 0.92
HealthCheckFunction · 0.92
CheckFunction · 0.92

Tested by

no test coverage detected