zdb.go 785 Bytes
Newer Older
Vladimir Barsukov's avatar
Vladimir Barsukov committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
}