Commit 168e879e authored by Vladimir Barsukov's avatar Vladimir Barsukov
Browse files

zdb NewMaster

parent 02d4612b
...@@ -4,7 +4,6 @@ import ( ...@@ -4,7 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/jackc/pgx/v5/pgxpool" "github.com/jackc/pgx/v5/pgxpool"
"log"
"reflect" "reflect"
"runtime" "runtime"
"strconv" "strconv"
...@@ -41,29 +40,6 @@ type Pool struct { ...@@ -41,29 +40,6 @@ type Pool struct {
PingTry int PingTry int
} }
func New(ctx context.Context) *Pool {
return &Pool{
ctx: ctx,
mu: &sync.RWMutex{},
slavesIter: &atomic.Int64{},
slavesAsyncIter: &atomic.Int64{},
Continues: []string{"connect", "EOF", "conflict with recovery", "context deadline exceeded"},
ContinuesTry: []string{"conflict with recovery"},
TryOnError: 1,
TryOnSleep: time.Second,
Balance: BalanceLeastConn,
PingTimout: time.Second * 5,
PingTry: 5,
}
}
func NewDefault() *Pool {
p := New(context.Background())
p.logger = log.Default()
return p
}
func (d *Pool) WithContext(ctx context.Context) *Pool { func (d *Pool) WithContext(ctx context.Context) *Pool {
return &Pool{ return &Pool{
ctx: ctx, ctx: ctx,
......
package zdb
import (
"context"
"log"
"sync"
"sync/atomic"
"time"
)
func New(ctx context.Context) *Pool {
return &Pool{
ctx: ctx,
mu: &sync.RWMutex{},
slavesIter: &atomic.Int64{},
slavesAsyncIter: &atomic.Int64{},
Continues: []string{"connect", "EOF", "conflict with recovery", "context deadline exceeded"},
ContinuesTry: []string{"conflict with recovery"},
TryOnError: 1,
TryOnSleep: time.Second,
Balance: BalanceLeastConn,
PingTimout: time.Second * 5,
PingTry: 5,
}
}
func NewDefault() *Pool {
p := New(context.Background())
p.logger = log.Default()
return p
}
func NewMaster(conn string) *Pool {
s := NewDefault()
_ = s.NewConn(ConnModeMaster, conn)
s.Start()
return s
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment