@@ -19,13 +19,11 @@ import (
1919var  buildVersion  string  =  buildversion .GetVersion ("github.com/couchbase/gocbcorex" )
2020
2121type  agentState  struct  {
22- 	bucket              string 
23- 	tlsConfig           * tls.Config 
24- 	authenticator       Authenticator 
25- 	numPoolConnections  uint 
26- 	httpTransport       * http.Transport 
22+ 	bucket         string 
23+ 	tlsConfig      * tls.Config 
24+ 	authenticator  Authenticator 
25+ 	httpTransport  * http.Transport 
2726
28- 	lastClients   map [string ]* KvClientConfig 
2927	latestConfig  * ParsedConfig 
3028}
3129
@@ -37,7 +35,8 @@ type Agent struct {
3735	state  agentState 
3836
3937	cfgWatcher   ConfigWatcher 
40- 	connMgr      KvClientManager 
38+ 	connMgr      KvEndpointClientManager 
39+ 	mconnMgr     MultiKvEndpointClientManager 
4140	collections  CollectionResolver 
4241	retries      RetryManager 
4342	vbRouter     VbucketRouter 
@@ -148,12 +147,11 @@ func CreateAgent(ctx context.Context, opts AgentOptions) (*Agent, error) {
148147		networkType : networkType ,
149148
150149		state : agentState {
151- 			bucket :             opts .BucketName ,
152- 			tlsConfig :          opts .TLSConfig ,
153- 			authenticator :      opts .Authenticator ,
154- 			numPoolConnections : connectionPoolSize ,
155- 			latestConfig :       bootstrapConfig ,
156- 			httpTransport :      httpTransport ,
150+ 			bucket :        opts .BucketName ,
151+ 			tlsConfig :     opts .TLSConfig ,
152+ 			authenticator : opts .Authenticator ,
153+ 			latestConfig :  bootstrapConfig ,
154+ 			httpTransport : httpTransport ,
157155		},
158156	}
159157	if  opts .RetryManager  ==  nil  {
@@ -164,20 +162,29 @@ func CreateAgent(ctx context.Context, opts AgentOptions) (*Agent, error) {
164162
165163	agentComponentConfigs  :=  agent .genAgentComponentConfigsLocked ()
166164
167- 	connMgr , err  :=  NewKvClientManager (& KvClientManagerConfig {
168- 		NumPoolConnections : agent .state .numPoolConnections ,
169- 		Clients :            agentComponentConfigs .KvClientManagerClients ,
170- 	}, & KvClientManagerOptions {
171- 		Logger : agent .logger .Named ("client-manager" ),
165+ 	mconnMgr , err  :=  NewMultiKvEndpointClientManager (& MultiKvEndpointClientManagerOptions {
166+ 		Logger :    agent .logger .Named ("multi-client-manager" ),
167+ 		Endpoints : agentComponentConfigs .KvTargets ,
168+ 		Auth :      agentComponentConfigs .KvAuth ,
169+ 	})
170+ 	if  err  !=  nil  {
171+ 		return  nil , handleAgentCreateErr (err )
172+ 	}
173+ 	agent .mconnMgr  =  mconnMgr 
174+ 
175+ 	connMgr , err  :=  mconnMgr .NewManager (NewManagerOptions {
176+ 		NumPoolConnections : connectionPoolSize ,
177+ 		OnDemandConnect :    false ,
178+ 		SelectedBucket :     agentComponentConfigs .KvSelectedBucket ,
172179	})
173180	if  err  !=  nil  {
174181		return  nil , handleAgentCreateErr (err )
175182	}
176183	agent .connMgr  =  connMgr 
177184
178185	coreCollections , err  :=  NewCollectionResolverMemd (& CollectionResolverMemdOptions {
179- 		Logger :  agent .logger ,
180- 		ConnMgr : agent .connMgr ,
186+ 		Logger :        agent .logger ,
187+ 		ConnProvider : agent .connMgr ,
181188	})
182189	if  err  !=  nil  {
183190		return  nil , handleAgentCreateErr (err )
@@ -213,9 +220,9 @@ func CreateAgent(ctx context.Context, opts AgentOptions) (*Agent, error) {
213220		configWatcher , err  :=  NewConfigWatcherMemd (
214221			& agentComponentConfigs .ConfigWatcherMemdConfig ,
215222			& ConfigWatcherMemdOptions {
216- 				Logger :           logger .Named ("memd-config-watcher" ),
217- 				KvClientManager : connMgr ,
218- 				PollingPeriod :    2500  *  time .Millisecond ,
223+ 				Logger :         logger .Named ("memd-config-watcher" ),
224+ 				ClientProvider : connMgr ,
225+ 				PollingPeriod :  2500  *  time .Millisecond ,
219226			},
220227		)
221228		if  err  !=  nil  {
@@ -258,12 +265,12 @@ func CreateAgent(ctx context.Context, opts AgentOptions) (*Agent, error) {
258265	}
259266
260267	agent .crud  =  & CrudComponent {
261- 		logger :      agent .logger ,
262- 		collections : agent .collections ,
263- 		retries :     consistencyRetryMgr ,
264- 		connManager : agent .connMgr ,
265- 		nmvHandler :  & agentNmvHandler {agent },
266- 		vbs :         agent .vbRouter ,
268+ 		logger :        agent .logger ,
269+ 		collections :   agent .collections ,
270+ 		retries :       consistencyRetryMgr ,
271+ 		connProvider : agent .connMgr ,
272+ 		nmvHandler :    & agentNmvHandler {agent },
273+ 		vbs :           agent .vbRouter ,
267274		compression : & CompressionManagerDefault {
268275			disableCompression :   ! useCompression ,
269276			compressionMinSize :   compressionMinSize ,
@@ -370,8 +377,8 @@ func (agent *Agent) NumVbuckets() int {
370377}
371378
372379func  (agent  * Agent ) Close () error  {
373- 	if  err  :=  agent .connMgr .Close (); err  !=  nil  {
374- 		agent .logger .Debug ("Failed to close conn mgr" , zap .Error (err ))
380+ 	if  err  :=  agent .mconnMgr .Close (); err  !=  nil  {
381+ 		agent .logger .Debug ("Failed to close multi  conn mgr" , zap .Error (err ))
375382	}
376383
377384	agent .cfgWatcherCancel ()
@@ -412,41 +419,23 @@ func (agent *Agent) updateStateLocked() {
412419	// the routing table.  Then go back and remove the old entries from 
413420	// the connection manager list. 
414421
415- 	oldClients  :=  make (map [string ]* KvClientConfig )
416- 	if  agent .state .lastClients  !=  nil  {
417- 		for  clientName , client  :=  range  agent .state .lastClients  {
418- 			oldClients [clientName ] =  client 
419- 		}
420- 	}
421- 	for  clientName , client  :=  range  agentComponentConfigs .KvClientManagerClients  {
422- 		if  oldClients [clientName ] ==  nil  {
423- 			oldClients [clientName ] =  client 
424- 		}
425- 	}
426- 
427- 	err  :=  agent .connMgr .Reconfigure (& KvClientManagerConfig {
428- 		NumPoolConnections : agent .state .numPoolConnections ,
429- 		Clients :            oldClients ,
430- 	})
422+ 	err  :=  agent .mconnMgr .UpdateEndpoints (agentComponentConfigs .KvTargets , true )
431423	if  err  !=  nil  {
432- 		agent .logger .Error ("failed to reconfigure  connection manager (old clients) " , zap .Error (err ))
424+ 		agent .logger .Error ("failed to add-only update kv  connection manager endpoint " , zap .Error (err ))
433425	}
434426
435427	agent .vbRouter .UpdateRoutingInfo (agentComponentConfigs .VbucketRoutingInfo )
436428
437429	if  agent .memdCfgWatcher  !=  nil  {
438- 		err  =  agent .memdCfgWatcher .Reconfigure (& agentComponentConfigs .ConfigWatcherMemdConfig )
430+ 		err  : =  agent .memdCfgWatcher .Reconfigure (& agentComponentConfigs .ConfigWatcherMemdConfig )
439431		if  err  !=  nil  {
440432			agent .logger .Error ("failed to reconfigure memd config watcher component" , zap .Error (err ))
441433		}
442434	}
443435
444- 	err  =  agent .connMgr .Reconfigure (& KvClientManagerConfig {
445- 		NumPoolConnections : agent .state .numPoolConnections ,
446- 		Clients :            agentComponentConfigs .KvClientManagerClients ,
447- 	})
436+ 	err  =  agent .mconnMgr .UpdateEndpoints (agentComponentConfigs .KvTargets , false )
448437	if  err  !=  nil  {
449- 		agent .logger .Error ("failed to reconfigure  connection manager (updated clients) " , zap .Error (err ))
438+ 		agent .logger .Error ("failed to update kv  connection manager endpoint " , zap .Error (err ))
450439	}
451440
452441	err  =  agent .query .Reconfigure (& agentComponentConfigs .QueryComponentConfig )
0 commit comments