diff --git a/zdb/pool.go b/zdb/pool.go index 596c9a42e832213719e09aaec9a2563de6f005a6..890f4ecb392102996b1c6ab058bc9c889c749c48 100644 --- a/zdb/pool.go +++ b/zdb/pool.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "github.com/jackc/pgx/v5/pgxpool" - "log" "reflect" "runtime" "strconv" @@ -41,29 +40,6 @@ type Pool struct { 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 { return &Pool{ ctx: ctx, diff --git a/zdb/zdb.go b/zdb/zdb.go new file mode 100644 index 0000000000000000000000000000000000000000..a15e6c2de353fc2bab0ed99be1b9093c67dd9718 --- /dev/null +++ b/zdb/zdb.go @@ -0,0 +1,40 @@ +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 +}