MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / NewServerContext

Function NewServerContext

rest/server_context.go:164–212  ·  view source on GitHub ↗
(ctx context.Context, config *StartupConfig, persistentConfig bool)

Source from the content-addressed store, hash-verified

162}
163
164func NewServerContext(ctx context.Context, config *StartupConfig, persistentConfig bool) *ServerContext {
165
166 sc := &ServerContext{
167 Config: config,
168 persistentConfig: persistentConfig,
169 _dbRegistry: map[string]struct{}{},
170 _collectionRegistry: map[string]string{},
171 _dbConfigs: map[string]*RuntimeDatabaseConfig{},
172 _databases: map[string]*db.DatabaseContext{},
173 DatabaseInitManager: &DatabaseInitManager{},
174 HTTPClient: http.DefaultClient,
175 statsContext: &statsContext{heapProfileEnabled: !config.HeapProfileDisableCollection},
176 BootstrapContext: &bootstrapContext{sgVersion: *base.ProductVersion},
177 hasStarted: make(chan struct{}),
178 _httpServers: map[serverType]*serverInfo{},
179 SGCollect: newSGCollect(ctx),
180 }
181 sc.invalidDatabaseConfigTracking = invalidDatabaseConfigs{
182 dbNames: map[string]*invalidConfigInfo{},
183 }
184
185 if base.ServerIsWalrus(sc.Config.Bootstrap.Server) {
186 // Disable Admin API authentication when running as walrus on the default admin interface to support dev
187 // environments.
188 if sc.Config.API.AdminInterface == DefaultAdminInterface {
189 sc.Config.API.AdminInterfaceAuthentication = base.Ptr(false)
190 sc.Config.API.MetricsInterfaceAuthentication = base.Ptr(false)
191 }
192 }
193 if config.Replicator.MaxConcurrentReplications != 0 {
194 sc.ActiveReplicationsCounter.activeReplicatorLimit = config.Replicator.MaxConcurrentReplications
195 }
196
197 if config.HeapProfileCollectionThreshold != nil {
198 sc.statsContext.heapProfileCollectionThreshold = *config.HeapProfileCollectionThreshold
199 } else {
200 memoryTotal := getTotalMemory(ctx)
201 if memoryTotal != 0 {
202 sc.statsContext.heapProfileCollectionThreshold = uint64(float64(memoryTotal) * 0.85)
203 } else {
204 base.WarnfCtx(ctx, "Could not determine system memory, disabling automatic heap profile collection")
205 sc.statsContext.heapProfileEnabled = false
206 }
207 }
208
209 sc.startStatsLogger(ctx)
210
211 return sc
212}
213
214func (sc *ServerContext) WaitForRESTAPIs(ctx context.Context) error {
215 timeout := 30 * time.Second

Calls 6

startStatsLoggerMethod · 0.95
ServerIsWalrusFunction · 0.92
PtrFunction · 0.92
WarnfCtxFunction · 0.92
newSGCollectFunction · 0.85
getTotalMemoryFunction · 0.85