本文整理汇总了Golang中github.com/youtube/vitess/go/sync2.AtomicInt32类的典型用法代码示例。如果您正苦于以下问题:Golang AtomicInt32类的具体用法?Golang AtomicInt32怎么用?Golang AtomicInt32使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AtomicInt32类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: WaitForChange
func (f *fileInfo) WaitForChange(running *sync2.AtomicInt32) error {
for {
if running.Get() != 1 {
return io.EOF
}
time.Sleep(100 * time.Millisecond)
fi, err := f.handle.Stat()
if err != nil {
return fmt.Errorf("stat error: %v", err)
}
if fi.Size() != f.pos {
return nil
}
}
}
开发者ID:rjammala,项目名称:vitess,代码行数:15,代码来源:binlog_streamer.go
示例2: qps
// qps is a function used by tests to run a vtgate load check.
// It will get the same srvKeyspaces as fast as possible and display the QPS.
func qps(ctx context.Context, cell string, keyspaces []string) {
var count sync2.AtomicInt32
for _, keyspace := range keyspaces {
for i := 0; i < 10; i++ {
go func() {
rpcClient := connect()
for true {
getSrvKeyspace(ctx, rpcClient, cell, keyspace, false)
count.Add(1)
}
}()
}
}
ticker := time.NewTicker(time.Second)
i := 0
for _ = range ticker.C {
c := count.Get()
count.Set(0)
println(fmt.Sprintf("QPS = %v", c))
i++
if i == 10 {
break
}
}
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:28,代码来源:zkclient2.go
示例3: qps
// qps is a function used by tests to run a zkocc load check.
// It will get zk paths as fast as possible and display the QPS.
func qps(paths []string) {
var count sync2.AtomicInt32
for _, path := range paths {
for i := 0; i < 10; i++ {
go func() {
rpcClient := connect()
for true {
get(rpcClient, path, false)
count.Add(1)
}
}()
}
}
ticker := time.NewTicker(time.Second)
i := 0
for _ = range ticker.C {
c := count.Get()
count.Set(0)
println(fmt.Sprintf("QPS = %v", c))
i++
if i == 10 {
break
}
}
}
开发者ID:chinna1986,项目名称:vitess,代码行数:28,代码来源:zkclient2.go
示例4: commandPruneActionLogs
func commandPruneActionLogs(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error {
keepCount := subFlags.Int("keep-count", 10, "count to keep")
if err := subFlags.Parse(args); err != nil {
return err
}
if subFlags.NArg() == 0 {
return fmt.Errorf("action PruneActionLogs requires <zk action log path> ...")
}
paths, err := resolveWildcards(wr, subFlags.Args())
if err != nil {
return err
}
zkts, ok := wr.TopoServer().(*zktopo.Server)
if !ok {
return fmt.Errorf("PruneActionLogs requires a zktopo.Server")
}
var errCount sync2.AtomicInt32
wg := sync.WaitGroup{}
for _, zkActionLogPath := range paths {
wg.Add(1)
go func(zkActionLogPath string) {
defer wg.Done()
purgedCount, err := zkts.PruneActionLogs(zkActionLogPath, *keepCount)
if err == nil {
wr.Logger().Infof("%v pruned %v", zkActionLogPath, purgedCount)
} else {
wr.Logger().Errorf("%v pruning failed: %v", zkActionLogPath, err)
errCount.Add(1)
}
}(zkActionLogPath)
}
wg.Wait()
if errCount.Get() > 0 {
return fmt.Errorf("some errors occurred, check the log")
}
return nil
}
开发者ID:nangong92t,项目名称:go_src,代码行数:41,代码来源:plugin_zktopo.go
示例5: commandStaleActions
func commandStaleActions(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (string, error) {
maxStaleness := subFlags.Duration("max-staleness", 5*time.Minute, "how long since the last modification before an action considered stale")
purge := subFlags.Bool("purge", false, "purge stale actions")
if err := subFlags.Parse(args); err != nil {
return "", err
}
if subFlags.NArg() == 0 {
return "", fmt.Errorf("action StaleActions requires <zk action path>")
}
zkts, ok := wr.TopoServer().(*zktopo.Server)
if !ok {
return "", fmt.Errorf("StaleActions requires a zktopo.Server")
}
zkPaths, err := resolveWildcards(wr, subFlags.Args())
if err != nil {
return "", err
}
var errCount sync2.AtomicInt32
wg := sync.WaitGroup{}
for _, apath := range zkPaths {
wg.Add(1)
go func(zkActionPath string) {
defer wg.Done()
staleActions, err := staleActions(zkts, zkActionPath, *maxStaleness)
if err != nil {
errCount.Add(1)
wr.Logger().Errorf("can't check stale actions: %v %v", zkActionPath, err)
return
}
for _, action := range staleActions {
wr.Logger().Printf("%v\n", fmtAction(action))
}
if *purge && len(staleActions) > 0 {
err := zkts.PurgeActions(zkActionPath, actionnode.ActionNodeCanBePurged)
if err != nil {
errCount.Add(1)
wr.Logger().Errorf("can't purge stale actions: %v %v", zkActionPath, err)
return
}
}
}(apath)
}
wg.Wait()
if errCount.Get() > 0 {
return "", fmt.Errorf("some errors occurred, check the log")
}
return "", nil
}
开发者ID:chinna1986,项目名称:vitess,代码行数:48,代码来源:plugin_zktopo.go
注:本文中的github.com/youtube/vitess/go/sync2.AtomicInt32类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论