Documentation ¶
Overview ¶
Package util ResourcePool provides functionality to manage and reuse resources like connections.
Index ¶
- Constants
- Variables
- func Concat(strings ...string) string
- func GetValueExprResult(n *driver.ValueExpr) (interface{}, error)
- func HostName(ip string) (hostname string, err error)
- func Int2TimeDuration(t int) (time.Duration, error)
- func ItoString(a interface{}) (bool, string)
- func Left(str string, length int, pad string) string
- func ResolveAddr(network string, locAddr string) (string, error)
- func Right(str string, length int, pad string) string
- type BoolIndex
- type Factory
- type IPInfo
- type MurmurHash
- type RequestContext
- type Resource
- type ResourcePool
- func (rp *ResourcePool) Active() int64
- func (rp *ResourcePool) Available() int64
- func (rp *ResourcePool) Capacity() int64
- func (rp *ResourcePool) Close()
- func (rp *ResourcePool) Get(ctx context.Context) (resource Resource, err error)
- func (rp *ResourcePool) IdleClosed() int64
- func (rp *ResourcePool) IdleTimeout() time.Duration
- func (rp *ResourcePool) InUse() int64
- func (rp *ResourcePool) IsClosed() (closed bool)
- func (rp *ResourcePool) MaxCap() int64
- func (rp *ResourcePool) Put(resource Resource)
- func (rp *ResourcePool) ScaleCapacity(capacity int) error
- func (rp *ResourcePool) SetCapacity(capacity int) error
- func (rp *ResourcePool) SetDynamic(value bool)
- func (rp *ResourcePool) SetIdleTimeout(idleTimeout time.Duration)
- func (rp *ResourcePool) StatsJSON() string
- func (rp *ResourcePool) WaitCount() int64
- func (rp *ResourcePool) WaitTime() time.Duration
- type Task
- type TimeWheel
Constants ¶
const ( // StmtType stmt type StmtType = "stmtType" // SQL类型, 值类型为int (对应parser.Preview()得到的值) // FromSlave if read from slave FromSlave = "fromSlave" // 读写分离标识, 值类型为int, false = 0, true = 1 DefaultSlice = "defaultSlice" // 默认分片标识 string 类型 )
Variables ¶
var ( // ErrClosed is returned if ResourcePool is used when it's closed. ErrClosed = errors.New("resource pool is closed") // ErrTimeout is returned if a resource get times out. ErrTimeout = errors.New("resource pool timed out") )
Functions ¶
func GetValueExprResult ¶
GetValueExprResult copy from ValueExpr.Restore() TODO: 分表列是否需要支持等值比较NULL
func Int2TimeDuration ¶
Int2TimeDuration convert int to Time.Duration
func ResolveAddr ¶
ResolveAddr return real ip by net interface
Types ¶
type BoolIndex ¶
type BoolIndex struct {
// contains filtered or unexported fields
}
BoolIndex rolled array switch mark
type IPInfo ¶
type IPInfo struct {
// contains filtered or unexported fields
}
IPInfo ip information
type MurmurHash ¶
type MurmurHash struct {
// contains filtered or unexported fields
}
MurmurHash copy from guava Murmur3_32HashFunction
func NewMurmurHash ¶
func NewMurmurHash(seed int) *MurmurHash
NewMurmurHash constructor of MurmurHash
func (*MurmurHash) HashUnencodedChars ¶
func (m *MurmurHash) HashUnencodedChars(inputStr string) int
HashUnencodedChars check if has unencoded chars
type RequestContext ¶
type RequestContext struct {
// contains filtered or unexported fields
}
RequestContext means request scope context with values thread safe
func NewRequestContext ¶
func NewRequestContext() *RequestContext
NewRequestContext return request scopre context
func (*RequestContext) Get ¶
func (reqCtx *RequestContext) Get(key string) interface{}
Get return context in RequestContext
func (*RequestContext) Set ¶
func (reqCtx *RequestContext) Set(key string, value interface{})
Set set value with specific key
type Resource ¶
type Resource interface {
Close()
}
Resource defines the interface that every resource must provide. Thread synchronization between Close() and IsClosed() is the responsibility of the caller.
type ResourcePool ¶
type ResourcePool struct { Dynamic bool // contains filtered or unexported fields }
ResourcePool allows you to use a pool of resources. ResourcePool允许你使用各种资源池,需要根据提供的factory创建特定的资源,比如连接
func NewResourcePool ¶
func NewResourcePool(factory Factory, capacity, maxCap int, idleTimeout time.Duration) *ResourcePool
NewResourcePool creates a new ResourcePool pool. capacity is the number of possible resources in the pool: there can be up to 'capacity' of these at a given time. maxCap specifies the extent to which the pool can be resized in the future through the SetCapacity function. You cannot resize the pool beyond maxCap. If a resource is unused beyond idleTimeout, it's discarded. An idleTimeout of 0 means that there is no timeout. 创建一个资源池子,capacity是池子中可用资源数量 maxCap代表最大资源数量 超过设定空闲时间的连接会被丢弃 资源池会根据传入的factory进行具体资源的初始化,比如建立与mysql的连接
func (*ResourcePool) Active ¶
func (rp *ResourcePool) Active() int64
Active returns the number of active (i.e. non-nil) resources either in the pool or claimed for use
func (*ResourcePool) Available ¶
func (rp *ResourcePool) Available() int64
Available returns the number of currently unused and available resources.
func (*ResourcePool) Capacity ¶
func (rp *ResourcePool) Capacity() int64
Capacity returns the capacity.
func (*ResourcePool) Close ¶
func (rp *ResourcePool) Close()
Close empties the pool calling Close on all its resources. You can call Close while there are outstanding resources. It waits for all resources to be returned (Put). After a Close, Get is not allowed.
func (*ResourcePool) Get ¶
func (rp *ResourcePool) Get(ctx context.Context) (resource Resource, err error)
Get will return the next available resource. If capacity has not been reached, it will create a new one using the factory. Otherwise, it will wait till the next resource becomes available or a timeout. A timeout of 0 is an indefinite wait. Get会返回下一个可用的资源 如果容量没有达到上线,它会根据factory创建一个新的资源,否则会一直等待直到资源可用或超时
func (*ResourcePool) IdleClosed ¶
func (rp *ResourcePool) IdleClosed() int64
IdleClosed returns the count of resources closed due to idle timeout.
func (*ResourcePool) IdleTimeout ¶
func (rp *ResourcePool) IdleTimeout() time.Duration
IdleTimeout returns the idle timeout.
func (*ResourcePool) InUse ¶
func (rp *ResourcePool) InUse() int64
InUse returns the number of claimed resources from the pool
func (*ResourcePool) IsClosed ¶
func (rp *ResourcePool) IsClosed() (closed bool)
IsClosed returns true if the resource pool is closed.
func (*ResourcePool) MaxCap ¶
func (rp *ResourcePool) MaxCap() int64
MaxCap returns the max capacity.
func (*ResourcePool) Put ¶
func (rp *ResourcePool) Put(resource Resource)
Put will return a resource to the pool. For every successful Get, a corresponding Put is required. If you no longer need a resource, you will need to call Put(nil) instead of returning the closed resource. The will eventually cause a new resource to be created in its place.
func (*ResourcePool) ScaleCapacity ¶ added in v1.2.3
func (rp *ResourcePool) ScaleCapacity(capacity int) error
SetCapacity changes the capacity of the pool. You can use it to shrink or expand, but not beyond the max capacity. If the change requires the pool to be shrunk, SetCapacity waits till the necessary number of resources are returned to the pool. A SetCapacity of 0 is equivalent to closing the ResourcePool.
func (*ResourcePool) SetCapacity ¶
func (rp *ResourcePool) SetCapacity(capacity int) error
func (*ResourcePool) SetDynamic ¶ added in v1.2.3
func (rp *ResourcePool) SetDynamic(value bool)
func (*ResourcePool) SetIdleTimeout ¶
func (rp *ResourcePool) SetIdleTimeout(idleTimeout time.Duration)
SetIdleTimeout sets the idle timeout. It can only be used if there was an idle timeout set when the pool was created.
func (*ResourcePool) StatsJSON ¶
func (rp *ResourcePool) StatsJSON() string
StatsJSON returns the stats in JSON format.
func (*ResourcePool) WaitCount ¶
func (rp *ResourcePool) WaitCount() int64
WaitCount returns the total number of waits.
func (*ResourcePool) WaitTime ¶
func (rp *ResourcePool) WaitTime() time.Duration
WaitTime returns the total wait time.
type Task ¶
type Task struct {
// contains filtered or unexported fields
}
Task means handle unit in time wheel
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package cache implements a LRU cache.
|
Package cache implements a LRU cache. |
mocks
|
|
Package sync2 provides extra functionality along the same lines as sync.
|
Package sync2 provides extra functionality along the same lines as sync. |
Package timer provides various enhanced timer functions.
|
Package timer provides various enhanced timer functions. |