// NewTxPool creates a new TxPool. It's not operational until it's Open'd. func NewTxPool( name string, txStatsPrefix string, capacity int, timeout time.Duration, idleTimeout time.Duration, enablePublishStats bool, qStats *QueryServiceStats, checker MySQLChecker) *TxPool { txStatsName := "" if enablePublishStats { txStatsName = txStatsPrefix + "Transactions" } axp := &TxPool{ pool: NewConnPool(name, capacity, idleTimeout, enablePublishStats, qStats, checker), activePool: pools.NewNumbered(), lastID: sync2.NewAtomicInt64(time.Now().UnixNano()), timeout: sync2.NewAtomicDuration(timeout), ticks: timer.NewTimer(timeout / 10), txStats: stats.NewTimings(txStatsName), checker: checker, queryServiceStats: qStats, } // Careful: pool also exports name+"xxx" vars, // but we know it doesn't export Timeout. if enablePublishStats { stats.Publish(name+"Timeout", stats.DurationFunc(axp.timeout.Get)) } return axp }
func NewActivePool(queryTimeout, idleTimeout time.Duration) *ActivePool { return &ActivePool{ pool: pools.NewNumbered(), timeout: sync2.AtomicDuration(queryTimeout), connPool: NewConnectionPool(1, idleTimeout), ticks: timer.NewTimer(queryTimeout / 10), } }
func NewActiveTxPool(timeout time.Duration) *ActiveTxPool { return &ActiveTxPool{ pool: pools.NewNumbered(), lastId: sync2.AtomicInt64(time.Now().UnixNano()), timeout: sync2.AtomicDuration(timeout), ticks: timer.NewTimer(timeout / 10), txStats: stats.NewTimings("Transactions"), } }
// resetVTGate resets the internal state of RpcVTGate. func resetVTGate() (sess proto.Session) { resetSandbox() *RpcVTGate = VTGate{ balancerMap: NewBalancerMap(new(sandboxTopo), "aa", "vt"), tabletProtocol: "sandbox", connections: pools.NewNumbered(), retryDelay: 1 * time.Second, retryCount: 10, } RpcVTGate.GetSessionId(&proto.SessionParams{TabletType: "master"}, &sess) return }
func Init(blm *BalancerMap, tabletProtocol string, retryDelay time.Duration, retryCount int) { if RpcVTGate != nil { log.Fatalf("VTGate already initialized") } RpcVTGate = &VTGate{ balancerMap: blm, tabletProtocol: tabletProtocol, connections: pools.NewNumbered(), retryDelay: retryDelay, retryCount: retryCount, } proto.RegisterAuthenticated(RpcVTGate) }
func NewActivePool(name string, queryTimeout time.Duration, connKiller *ConnectionKiller) *ActivePool { ap := &ActivePool{ pool: pools.NewNumbered(), timeout: sync2.AtomicDuration(queryTimeout), ticks: timer.NewTimer(queryTimeout / 10), connKiller: connKiller, } stats.Publish(name+"Size", stats.IntFunc(ap.pool.Size)) stats.Publish( name+"Timeout", stats.DurationFunc(func() time.Duration { return ap.timeout.Get() }), ) return ap }
func NewActiveTxPool(name string, timeout time.Duration) *ActiveTxPool { axp := &ActiveTxPool{ pool: pools.NewNumbered(), lastId: sync2.AtomicInt64(time.Now().UnixNano()), timeout: sync2.AtomicDuration(timeout), ticks: timer.NewTimer(timeout / 10), txStats: stats.NewTimings("Transactions"), } stats.Publish(name+"Size", stats.IntFunc(axp.pool.Size)) stats.Publish( name+"Timeout", stats.DurationFunc(func() time.Duration { return axp.timeout.Get() }), ) return axp }
func NewTxPool(name string, capacity int, timeout, poolTimeout, idleTimeout time.Duration) *TxPool { axp := &TxPool{ pool: dbconnpool.NewConnectionPool(name, capacity, idleTimeout), activePool: pools.NewNumbered(), lastId: sync2.AtomicInt64(time.Now().UnixNano()), timeout: sync2.AtomicDuration(timeout), poolTimeout: sync2.AtomicDuration(poolTimeout), ticks: timer.NewTimer(timeout / 10), txStats: stats.NewTimings("Transactions"), } // Careful: pool also exports name+"xxx" vars, // but we know it doesn't export Timeout. stats.Publish(name+"Timeout", stats.DurationFunc(axp.timeout.Get)) stats.Publish(name+"PoolTimeout", stats.DurationFunc(axp.poolTimeout.Get)) return axp }
func (ap *ActivePool) Close() { ap.ticks.Stop() ap.connPool.Close() ap.pool = pools.NewNumbered() }
func NewReservedPool() *ReservedPool { return &ReservedPool{pool: pools.NewNumbered(), lastId: 1} }
func NewReservedPool(name string) *ReservedPool { rp := &ReservedPool{pool: pools.NewNumbered(), lastId: 1} stats.Publish(name+"Size", stats.IntFunc(rp.pool.Size)) return rp }