Skip to content

Commit 3a1819c

Browse files
committed
ING-1366: Fixed Kv Client OnDemandConnect to build clients.
1 parent 3f26da0 commit 3a1819c

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

kvclientpool.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ func NewKvClientPool(opts *KvClientPoolOptions) (KvClientPool, error) {
7171
return nil, errors.New("a pool of connections must have at least one connection")
7272
}
7373

74+
if opts.OnDemandConnect {
75+
if opts.NumConnections != 1 {
76+
return nil, errors.New("on-demand connect pools can only have one connection")
77+
}
78+
}
79+
7480
logger := loggerOrNop(opts.Logger)
7581
// We namespace the pool to improve debugging,
7682
logger = logger.With(
@@ -187,12 +193,18 @@ func (p *kvClientPool) GetClient(ctx context.Context) (KvClient, error) {
187193
}
188194
}
189195

190-
p.logger.Debug("no client found in fast map")
191-
192196
return p.getClientSlow(ctx)
193197
}
194198

195199
func (p *kvClientPool) getClientSlow(ctx context.Context) (KvClient, error) {
200+
// if there is only 1 manager, we can skip the complex distributing
201+
// logic and just directly call its GetClient method. This is especially
202+
// important in the OnDemandConnect case where we only have 1 manager
203+
// and we need to actually trigger the build of the connection.
204+
if len(p.managers) == 1 {
205+
return p.managers[0].Manager.GetClient(ctx)
206+
}
207+
196208
clientIdxStart := atomic.AddUint64(&p.clientIdx, 1) - 1
197209

198210
p.lock.Lock()

0 commit comments

Comments
 (0)