aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/jackc
diff options
context:
space:
mode:
authortsmax2004 <tsmax2004@ydb.tech>2023-11-28 17:06:27 +0300
committertsmax2004 <tsmax2004@ydb.tech>2023-11-28 18:13:26 +0300
commit5e35ed89257fa2a1d06f1100c05ad41bcb7ef441 (patch)
treed7cf145a7a4c094848fa12ec7d6ec480c1ed96cd /vendor/github.com/jackc
parente86f906e854caf259f096dd20f0f09425a178d28 (diff)
downloadydb-5e35ed89257fa2a1d06f1100c05ad41bcb7ef441.tar.gz
Contrib: update vendor/github.com/ClickHouse/ch-go v0.56.1 => v0.58.2
В текущей версии в Аркадии библиотека неверно выводит тип Date32, не хватает этого фикса https://github.com/ClickHouse/clickhouse-go/pull/1069
Diffstat (limited to 'vendor/github.com/jackc')
-rw-r--r--vendor/github.com/jackc/puddle/v2/internal/genstack/ya.make4
-rw-r--r--vendor/github.com/jackc/puddle/v2/pool.go38
2 files changed, 25 insertions, 17 deletions
diff --git a/vendor/github.com/jackc/puddle/v2/internal/genstack/ya.make b/vendor/github.com/jackc/puddle/v2/internal/genstack/ya.make
index 0032e6ec01..42615de07c 100644
--- a/vendor/github.com/jackc/puddle/v2/internal/genstack/ya.make
+++ b/vendor/github.com/jackc/puddle/v2/internal/genstack/ya.make
@@ -11,4 +11,6 @@ GO_TEST_SRCS(gen_stack_test.go)
END()
-RECURSE(gotest)
+RECURSE(
+ gotest
+)
diff --git a/vendor/github.com/jackc/puddle/v2/pool.go b/vendor/github.com/jackc/puddle/v2/pool.go
index f9190d627e..c8edc0fb68 100644
--- a/vendor/github.com/jackc/puddle/v2/pool.go
+++ b/vendor/github.com/jackc/puddle/v2/pool.go
@@ -588,42 +588,48 @@ func (p *Pool[T]) AcquireAllIdle() []*Resource[T] {
return idle
}
-// CreateResource constructs a new resource without acquiring it.
-// It goes straight in the IdlePool. It does not check against maxSize.
-// It can be useful to maintain warm resources under little load.
+// CreateResource constructs a new resource without acquiring it. It goes straight in the IdlePool. If the pool is full
+// it returns an error. It can be useful to maintain warm resources under little load.
func (p *Pool[T]) CreateResource(ctx context.Context) error {
+ if !p.acquireSem.TryAcquire(1) {
+ return ErrNotAvailable
+ }
+
p.mux.Lock()
if p.closed {
+ p.acquireSem.Release(1)
p.mux.Unlock()
return ErrClosedPool
}
- p.destructWG.Add(1)
+
+ if len(p.allResources) >= int(p.maxSize) {
+ p.acquireSem.Release(1)
+ p.mux.Unlock()
+ return ErrNotAvailable
+ }
+
+ res := p.createNewResource()
p.mux.Unlock()
value, err := p.constructor(ctx)
+ p.mux.Lock()
+ defer p.mux.Unlock()
+ defer p.acquireSem.Release(1)
if err != nil {
+ p.allResources.remove(res)
p.destructWG.Done()
return err
}
- res := &Resource[T]{
- pool: p,
- creationTime: time.Now(),
- status: resourceStatusIdle,
- value: value,
- lastUsedNano: nanotime(),
- poolResetCount: p.resetCount,
- }
-
- p.mux.Lock()
- defer p.mux.Unlock()
+ res.value = value
+ res.status = resourceStatusIdle
// If closed while constructing resource then destroy it and return an error
if p.closed {
go p.destructResourceValue(res.value)
return ErrClosedPool
}
- p.allResources.append(res)
+
p.idleResources.Push(res)
return nil