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

Method initializeGoCBAgent

rest/server_context.go:1878–1911  ·  view source on GitHub ↗

initializeGoCBAgent Obtains a gocb agent from the current server connection. Requires the agent to be closed after use. Uses retry loop

(ctx context.Context)

Source from the content-addressed store, hash-verified

1876// initializeGoCBAgent Obtains a gocb agent from the current server connection. Requires the agent to be closed after use.
1877// Uses retry loop
1878func (sc *ServerContext) initializeGoCBAgent(ctx context.Context) (*gocbcore.Agent, error) {
1879 err, agent := base.RetryLoop(ctx, "Initialize Cluster Agent", func() (shouldRetry bool, err error, agent *gocbcore.Agent) {
1880 agent, err = base.NewClusterAgent(
1881 ctx,
1882 base.CouchbaseClusterSpec{
1883 Server: sc.Config.Bootstrap.Server,
1884 Username: sc.Config.Bootstrap.Username,
1885 Password: sc.Config.Bootstrap.Password,
1886 X509Certpath: sc.Config.Bootstrap.X509CertPath,
1887 X509Keypath: sc.Config.Bootstrap.X509KeyPath,
1888 CACertpath: sc.Config.Bootstrap.CACertPath,
1889 TLSSkipVerify: base.ValDefault(sc.Config.Bootstrap.ServerTLSSkipVerify, false),
1890 },
1891 base.CouchbaseClusterWaitUntilReadyOptions{
1892 // this timeout is pretty short since we are doing external retries
1893 Timeout: 5 * time.Second,
1894 })
1895 if err != nil {
1896 // since we're starting up - let's be verbose (on console) about these retries happening ... otherwise it looks like nothing is happening ...
1897 base.ConsolefCtx(ctx, base.LevelInfo, base.KeyConfig, "Couldn't initialize cluster agent: %v - will retry...", err)
1898 return true, err, nil
1899 }
1900
1901 return false, nil, agent
1902 }, base.CreateSleeperFunc(27, 1000)) // ~2 mins total - 5 second gocb WaitUntilReady timeout and 1 second interval
1903 if err != nil {
1904 // warn and bubble up error for further handling
1905 base.ConsolefCtx(ctx, base.LevelWarn, base.KeyConfig, "Giving up initializing cluster agent after retry: %v", err)
1906 return nil, err
1907 }
1908
1909 base.InfofCtx(ctx, base.KeyConfig, "Successfully initialized cluster agent")
1910 return agent, nil
1911}
1912
1913// initializeNoX509HttpClient() returns an http client based on the bootstrap connection information, but
1914// without any x509 keypair included in the tls config. This client can be used to perform basic

Calls 6

RetryLoopFunction · 0.92
NewClusterAgentFunction · 0.92
ValDefaultFunction · 0.92
ConsolefCtxFunction · 0.92
CreateSleeperFuncFunction · 0.92
InfofCtxFunction · 0.92