mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
update vendor
This commit is contained in:
Generated
+6
-6
@@ -1765,9 +1765,10 @@
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:80b6e83e951313a5cde2995b9a158002bb73fd3a819c633f66d52ae0f52fe1cd"
|
||||
digest = "1:04187b7fe2d9788ad901137fd8976272f464bd4080963e7a7f28aa9615d1e47a"
|
||||
name = "yunion.io/x/pkg"
|
||||
packages = [
|
||||
"errors",
|
||||
"gotypes",
|
||||
"prettytable",
|
||||
"trace",
|
||||
@@ -1792,22 +1793,21 @@
|
||||
"util/stringutils",
|
||||
"util/timeutils",
|
||||
"util/trace",
|
||||
"util/ttlpool",
|
||||
"util/version",
|
||||
"util/wait",
|
||||
"util/workqueue",
|
||||
"utils",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "43fa4e20e9663f2012e5c3cf455ad3dd6e10adfa"
|
||||
revision = "3afb7f847aad0b254d5768f961d226b24aa24cea"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:66d19ef38985070b76f8ca9f9fc468e69e923bf331cb9bf4488d7997f2f4a7b0"
|
||||
digest = "1:a1d55c54bf4a9a83c1d955b9038a003cf1edc7c8707d07799608c796b2790034"
|
||||
name = "yunion.io/x/sqlchemy"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "b100553e017505920d398be5bb4bafe7914d6ef0"
|
||||
revision = "4e836c2494cbadad5c5a22f83abbf1d87df6d439"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
@@ -1942,6 +1942,7 @@
|
||||
"yunion.io/x/jsonutils",
|
||||
"yunion.io/x/log",
|
||||
"yunion.io/x/log/hooks",
|
||||
"yunion.io/x/pkg/errors",
|
||||
"yunion.io/x/pkg/gotypes",
|
||||
"yunion.io/x/pkg/prettytable",
|
||||
"yunion.io/x/pkg/trace",
|
||||
@@ -1964,7 +1965,6 @@
|
||||
"yunion.io/x/pkg/util/stringutils",
|
||||
"yunion.io/x/pkg/util/timeutils",
|
||||
"yunion.io/x/pkg/util/trace",
|
||||
"yunion.io/x/pkg/util/ttlpool",
|
||||
"yunion.io/x/pkg/util/version",
|
||||
"yunion.io/x/pkg/util/wait",
|
||||
"yunion.io/x/pkg/util/workqueue",
|
||||
|
||||
Generated
Vendored
+21
-1
@@ -12,4 +12,24 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package ttlpool // import "yunion.io/x/pkg/util/ttlpool"
|
||||
package errors
|
||||
|
||||
import "github.com/pkg/errors"
|
||||
|
||||
type Error string
|
||||
|
||||
func (e Error) Error() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
func Wrap(err error, msg string) error {
|
||||
return errors.Wrap(err, msg)
|
||||
}
|
||||
|
||||
func Wrapf(err error, format string, args ...interface{}) error {
|
||||
return errors.Wrapf(err, format, args...)
|
||||
}
|
||||
|
||||
func Cause(err error) error {
|
||||
return errors.Cause(err)
|
||||
}
|
||||
+14
@@ -1,3 +1,17 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package netutils
|
||||
|
||||
import (
|
||||
|
||||
-190
@@ -1,190 +0,0 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package ttlpool
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/util/cache"
|
||||
)
|
||||
|
||||
type Item interface {
|
||||
Index() (string, error)
|
||||
}
|
||||
|
||||
type item struct {
|
||||
key string
|
||||
}
|
||||
|
||||
func (i *item) Index() (string, error) {
|
||||
return i.key, nil
|
||||
}
|
||||
|
||||
type TTLPool struct {
|
||||
pool cache.Store
|
||||
}
|
||||
|
||||
func NewTTLPool(defaultTTL time.Duration) *TTLPool {
|
||||
p := &TTLPool{}
|
||||
p.pool = cache.NewTTLStore(p.storeKeyFunc, defaultTTL)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *TTLPool) Add(obj interface{}) error {
|
||||
return p.pool.Add(obj)
|
||||
}
|
||||
|
||||
func (p *TTLPool) Delete(obj interface{}) error {
|
||||
return p.pool.Delete(obj)
|
||||
}
|
||||
|
||||
func (p *TTLPool) DeleteByKey(key string) error {
|
||||
return p.pool.Delete(&item{key})
|
||||
}
|
||||
|
||||
func (p *TTLPool) Get(obj interface{}) (interface{}, bool, error) {
|
||||
return p.pool.Get(obj)
|
||||
}
|
||||
|
||||
func (p *TTLPool) GetByKey(key string) (interface{}, bool, error) {
|
||||
return p.pool.GetByKey(key)
|
||||
}
|
||||
|
||||
func (p *TTLPool) Has(obj interface{}) (bool, error) {
|
||||
_, exists, err := p.Get(obj)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return exists, nil
|
||||
}
|
||||
|
||||
func (p *TTLPool) HasByKey(key string) (bool, error) {
|
||||
_, exists, err := p.GetByKey(key)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return exists, nil
|
||||
}
|
||||
|
||||
func (p *TTLPool) List() []interface{} {
|
||||
return p.pool.List()
|
||||
}
|
||||
|
||||
func (p *TTLPool) storeKeyFunc(obj interface{}) (string, error) {
|
||||
return obj.(Item).Index()
|
||||
}
|
||||
|
||||
type CountPool struct {
|
||||
ttlPool *TTLPool
|
||||
countMap *sync.Map
|
||||
}
|
||||
|
||||
func NewCountPool() *CountPool {
|
||||
ttlPool := NewTTLPool(0)
|
||||
return &CountPool{
|
||||
ttlPool: ttlPool,
|
||||
countMap: new(sync.Map),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *CountPool) storeKeyFunc(obj interface{}) (string, error) {
|
||||
return p.ttlPool.storeKeyFunc(obj)
|
||||
}
|
||||
|
||||
func (p *CountPool) Add(obj interface{}, count uint64) error {
|
||||
log.V(10).Debugf("CountPool add obj: %v, count: %d", obj, count)
|
||||
if count <= 0 {
|
||||
return fmt.Errorf("count must be postive number.")
|
||||
}
|
||||
key, err := p.storeKeyFunc(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.countMap.Store(key, count)
|
||||
return p.ttlPool.Add(obj)
|
||||
}
|
||||
|
||||
func (p *CountPool) DeleteByKey(key string) (err error) {
|
||||
count, ok := p.countMap.Load(key)
|
||||
if !ok {
|
||||
err = p.ttlPool.DeleteByKey(key)
|
||||
return
|
||||
}
|
||||
minusCount := count.(uint64) - 1
|
||||
p.countMap.Store(key, minusCount)
|
||||
log.V(10).Debugf("Delete %q, count => %d", key, minusCount)
|
||||
if minusCount <= 0 {
|
||||
p.countMap.Delete(key)
|
||||
return p.ttlPool.DeleteByKey(key)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *CountPool) Delete(obj interface{}) (err error) {
|
||||
key, err := p.storeKeyFunc(obj)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return p.DeleteByKey(key)
|
||||
}
|
||||
|
||||
func (p *CountPool) GetCount(obj interface{}) (count uint64, ok bool, err error) {
|
||||
key, err := p.storeKeyFunc(obj)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
count, ok = p.GetCountByKey(key)
|
||||
return
|
||||
}
|
||||
|
||||
func (p *CountPool) GetCountByKey(key string) (count uint64, ok bool) {
|
||||
countI, ok := p.countMap.Load(key)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
count = countI.(uint64)
|
||||
return
|
||||
}
|
||||
|
||||
func (p *CountPool) GetByKey(key string) (interface{}, bool, error) {
|
||||
count, ok := p.GetCountByKey(key)
|
||||
if !ok {
|
||||
return nil, false, nil
|
||||
}
|
||||
if count <= 0 {
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
return p.ttlPool.GetByKey(key)
|
||||
}
|
||||
|
||||
func (p *CountPool) Get(obj interface{}) (interface{}, bool, error) {
|
||||
key, err := p.storeKeyFunc(obj)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
return p.GetByKey(key)
|
||||
}
|
||||
|
||||
func (p *CountPool) Has(obj interface{}) (bool, error) {
|
||||
return p.ttlPool.Has(obj)
|
||||
}
|
||||
|
||||
func (p *CountPool) HasByKey(key string) (bool, error) {
|
||||
return p.ttlPool.HasByKey(key)
|
||||
}
|
||||
+1
@@ -398,6 +398,7 @@ func (tq *SQuery) Rows() (*sql.Rows, error) {
|
||||
return _db.Query(sqlstr, vars...)
|
||||
}
|
||||
|
||||
// deprecated
|
||||
func (tq *SQuery) Count() int {
|
||||
cnt, _ := tq.CountWithError()
|
||||
return cnt
|
||||
|
||||
Reference in New Issue
Block a user